sylphx 0.3.8

The Sylphx SDK: one API, one key, every Sylphx service. Generated from the Sylphx schema registry.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
// @generated by sylphx-gen. Do not edit.
//! `sylphx.ai.v1`.

#![allow(clippy::all)]

/// An AI Model is one admitted entry of the Sylphx AI catalog: a model id a
/// caller may name on the inference surface, with its sell prices, limits, and
/// data policy. Only admitted models list (AI-CATALOG-ADMISSION); no
/// capability, contract, connector, or upstream price appears on an entry
/// (AI-CATALOG-NO-LEAK). The id is the canonical model id with `/` and `.`
/// written as `-`, for example `anthropic-claude-opus-5`; `model` carries the
/// canonical id itself.
///
/// The catalog is platform-wide and written only by `sylphx-platform`;
/// customers read it.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct AiModel {
    /// `ai_models/{ai_model}`.
    ///
    /// Field behavior: `identifier`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub name: String,
    /// `aim_<cell><ulid>`; never reused.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub uid: String,
    /// Resource metadata.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub meta: Option<crate::common::ResourceMeta>,
    /// The canonical model id, `brand/model`, for example
    /// `anthropic/claude-opus-5`.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub model: String,
    /// The brand, for example `anthropic`.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub brand: String,
    /// Bare spellings that resolve to this model when unique, for example
    /// `claude-opus-5`.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub aliases: Vec<String>,
    /// What the model produces.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub modality: Option<ModelModality>,
    /// Accepted input modalities, for example text and image.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "Vec::is_empty",
        alias = "inputModalities"
    )]
    pub input_modalities: Vec<InputModality>,
    /// Inference encodings the model answers on.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "Vec::is_empty", alias = "apiSurfaces")]
    pub api_surfaces: Vec<ApiSurface>,
    /// Context window in tokens.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        with = "crate::runtime::int64",
        alias = "contextWindowTokens"
    )]
    pub context_window_tokens: i64,
    /// Most output tokens per response.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        with = "crate::runtime::int64",
        alias = "maxOutputTokens"
    )]
    pub max_output_tokens: i64,
    /// The upstream release date.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "releaseTime"
    )]
    pub release_time: String,
    /// Whether the model is a preview.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub preview: bool,
    /// Sell prices per meter and class; the only prices on an entry.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub prices: Vec<ModelPrice>,
    /// The price identity usage events carry, for example `spv3-...`.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "priceIdentity"
    )]
    pub price_identity: String,
    /// How request and response data are retained and used.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "dataPolicy")]
    pub data_policy: Option<DataPolicy>,
    /// How long a prompt-cache prefix stays warm on this model, and the longest
    /// retention a request may ask for; unset when no serving lane declares it.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub caching: Option<ModelCaching>,
}

/// How a model's request and response data are handled.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct DataPolicy {
    /// Whether Sylphx or the upstream retains prompts beyond the request.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "retainsPrompts"
    )]
    pub retains_prompts: bool,
    /// Whether the upstream may train on prompts.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "trainsOnPrompts"
    )]
    pub trains_on_prompts: bool,
    /// Stored responses expire after this long (7 days).
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "responseRetention"
    )]
    pub response_retention: String,
}

/// The request of GetAiModel.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct GetAiModelRequest {
    /// The name of the AI model to get.
    ///
    /// Field behavior: `required`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub name: String,
}

/// The request of ListAiModels.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ListAiModelsRequest {
    /// At most this many; default 50, clamped to 1000.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "pageSize"
    )]
    pub page_size: i32,
    /// `next_page_token` of the previous page.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "pageToken"
    )]
    pub page_token: String,
    /// AIP-160 filter over labels and filterable fields.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub filter: String,
    /// AIP-132 ordering over filterable fields.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "orderBy"
    )]
    pub order_by: String,
}

/// The response of ListAiModels.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ListAiModelsResponse {
    /// The page.
    #[serde(default, skip_serializing_if = "Vec::is_empty", alias = "aiModels")]
    pub ai_models: Vec<AiModel>,
    /// The token of the next page; empty on the last page.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "nextPageToken"
    )]
    pub next_page_token: String,
}

/// A model's prompt-cache retention, from its serving lanes' declarations.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ModelCaching {
    /// How long a cached prefix stays warm after its last use with the default
    /// retention, for example 300 seconds.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub ttl: String,
    /// The longest retention a request may ask for with
    /// `prompt_cache_retention: "24h"`, for example one hour on a lane whose
    /// longest native breakpoint is one hour; zero when no longer retention
    /// exists. A prefix written at this retention bills at the `cache_write_1h`
    /// price.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "extendedTtl"
    )]
    pub extended_ttl: String,
}

/// One sell price of a model.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ModelPrice {
    /// The meter, for example `ai.tokens`.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub meter: String,
    /// The meter dimension class, for example `input`, `cached_input`, `output`,
    /// `reasoning`, `cache_write` (writing a prompt-cache prefix at the default
    /// retention), or `cache_write_1h` (writing it at the extended retention).
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "priceClass"
    )]
    pub price_class: String,
    /// The unit the price is per, for example `1M tokens` or `image`.
    ///
    /// Field behavior: `output_only`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub unit: String,
    /// ISO 4217 currency.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "currencyCode"
    )]
    pub currency_code: String,
    /// The price as a decimal string, for example `1.2`; never a float.
    ///
    /// Field behavior: `output_only`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "unitPrice"
    )]
    pub unit_price: String,
}

/// An inference encoding of the compatibility surface (ai-inference-surface.md
/// §5).
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ApiSurface {
    /// `/v1/responses`.
    Responses,
    /// `/v1/messages`.
    Messages,
    /// `/v1/chat/completions`.
    ChatCompletions,
    /// `/v1/embeddings`.
    Embeddings,
    /// `/v1/images/generations`.
    Images,
    /// `/v1/audio/speech`.
    Speech,
    /// `/v1/audio/transcriptions` and `/v1/audio/translations`.
    Transcription,
    /// A value this SDK version does not know.
    Unknown(String),
}

impl ApiSurface {
    /// The wire string.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Responses => "responses",
            Self::Messages => "messages",
            Self::ChatCompletions => "chat_completions",
            Self::Embeddings => "embeddings",
            Self::Images => "images",
            Self::Speech => "speech",
            Self::Transcription => "transcription",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Parses a wire string; unknown values are kept.
    pub fn from_wire(s: &str) -> Self {
        match s {
            "responses" => Self::Responses,
            "messages" => Self::Messages,
            "chat_completions" => Self::ChatCompletions,
            "embeddings" => Self::Embeddings,
            "images" => Self::Images,
            "speech" => Self::Speech,
            "transcription" => Self::Transcription,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl serde::Serialize for ApiSurface {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> serde::Deserialize<'de> for ApiSurface {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        let s = <String as serde::Deserialize>::deserialize(d)?;
        Ok(Self::from_wire(&s))
    }
}

impl crate::runtime::QueryValue for ApiSurface {
    fn query_value(&self) -> Option<String> {
        Some(self.as_str().to_string())
    }
}

/// An input a model accepts.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum InputModality {
    /// Text.
    Text,
    /// Images.
    Image,
    /// Audio.
    Audio,
    /// Files.
    File,
    /// Video.
    Video,
    /// A value this SDK version does not know.
    Unknown(String),
}

impl InputModality {
    /// The wire string.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Text => "text",
            Self::Image => "image",
            Self::Audio => "audio",
            Self::File => "file",
            Self::Video => "video",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Parses a wire string; unknown values are kept.
    pub fn from_wire(s: &str) -> Self {
        match s {
            "text" => Self::Text,
            "image" => Self::Image,
            "audio" => Self::Audio,
            "file" => Self::File,
            "video" => Self::Video,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl serde::Serialize for InputModality {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> serde::Deserialize<'de> for InputModality {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        let s = <String as serde::Deserialize>::deserialize(d)?;
        Ok(Self::from_wire(&s))
    }
}

impl crate::runtime::QueryValue for InputModality {
    fn query_value(&self) -> Option<String> {
        Some(self.as_str().to_string())
    }
}

/// What a model produces.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ModelModality {
    /// Text or structured output (Responses, Messages, Chat Completions).
    Chat,
    /// Embeddings.
    Embedding,
    /// Images.
    Image,
    /// Speech audio.
    Speech,
    /// Text from audio.
    Transcription,
    /// Video.
    Video,
    /// Decision answers through structured output.
    Decision,
    /// A value this SDK version does not know.
    Unknown(String),
}

impl ModelModality {
    /// The wire string.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Chat => "chat",
            Self::Embedding => "embedding",
            Self::Image => "image",
            Self::Speech => "speech",
            Self::Transcription => "transcription",
            Self::Video => "video",
            Self::Decision => "decision",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Parses a wire string; unknown values are kept.
    pub fn from_wire(s: &str) -> Self {
        match s {
            "chat" => Self::Chat,
            "embedding" => Self::Embedding,
            "image" => Self::Image,
            "speech" => Self::Speech,
            "transcription" => Self::Transcription,
            "video" => Self::Video,
            "decision" => Self::Decision,
            other => Self::Unknown(other.to_string()),
        }
    }
}

impl serde::Serialize for ModelModality {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> serde::Deserialize<'de> for ModelModality {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        let s = <String as serde::Deserialize>::deserialize(d)?;
        Ok(Self::from_wire(&s))
    }
}

impl crate::runtime::QueryValue for ModelModality {
    fn query_value(&self) -> Option<String> {
        Some(self.as_str().to_string())
    }
}

impl<T: crate::runtime::Transport> crate::runtime::Client<T> {
    /// Sylphx AI (`preview`).
    pub fn ai(&self) -> AiApi<'_, T> {
        AiApi { client: self }
    }
}

/// AiService is the Resource side of Sylphx AI: the model catalog.
///
/// Inference is not here. The OpenAI- and Anthropic-compatible routes
/// (`/v1/responses`, `/v1/chat/completions`, `/v1/messages`, `/v1/embeddings`,
/// `/v1/images/*`, `/v1/audio/*`, `/v1/models`, `/v1/files`) keep their
/// industry wire and stay outside the Resource grammar (ai-inference-surface.md
/// §4, resource-api-and-clients.md §4.6); their contract is imported OpenAPI,
/// not proto. Usage is not here either: AI keeps no usage or spend table
/// (AI-USAGE-SPEND); its meters are read from Kernel Billing.
///
/// Namespace of Sylphx AI on the client.
pub struct AiApi<'a, T> {
    client: &'a crate::runtime::Client<T>,
}

impl<'a, T: crate::runtime::Transport> AiApi<'a, T> {
    /// The `ai_models` collection.
    pub fn ai_models(&self) -> AiModelsCollection<'a, T> {
        AiModelsCollection {
            client: self.client,
        }
    }
}

/// `ai_models` of Sylphx AI: Resource type `ai.sylphx.com/AiModel`.
pub struct AiModelsCollection<'a, T> {
    client: &'a crate::runtime::Client<T>,
}

impl<'a, T: crate::runtime::Transport> AiModelsCollection<'a, T> {
    /// Gets an AI model.
    ///
    /// `GET /v1/{name=ai_models/*}` · permission `ai:read` · effect `read`
    ///
    /// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`.
    pub async fn get(&self, request: GetAiModelRequest) -> Result<AiModel, crate::runtime::Error> {
        let path = format!(
            "/v1/{}",
            crate::runtime::path_param(&request.name, "ai_models/*", "name")?
        );
        let query = crate::runtime::Query::default();
        let http = crate::runtime::HttpRequest {
            method: "GET",
            path,
            query: query.0,
            body: None,
            mutation: false,
            origin: None,
            effect_ids: false,
        };
        self.client.call(http).await
    }

    /// Lists the admitted catalog; filter by `brand`, `modality`, or `model`.
    ///
    /// `GET /v1/ai_models` · permission `ai:read` · effect `read`
    ///
    /// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `INVALID_FIELD`, `PAGE_TOKEN_MISMATCH`.
    pub async fn list(
        &self,
        request: ListAiModelsRequest,
    ) -> Result<ListAiModelsResponse, crate::runtime::Error> {
        let path = "/v1/ai_models".to_string();
        let mut query = crate::runtime::Query::default();
        query.push("page_size", &request.page_size);
        query.push("page_token", &request.page_token);
        query.push("filter", &request.filter);
        query.push("order_by", &request.order_by);
        let http = crate::runtime::HttpRequest {
            method: "GET",
            path,
            query: query.0,
            body: None,
            mutation: false,
            origin: None,
            effect_ids: false,
        };
        self.client.call(http).await
    }

    /// Every page of [`Self::list`], collected.
    pub async fn list_all(
        &self,
        mut request: ListAiModelsRequest,
    ) -> Result<Vec<AiModel>, crate::runtime::Error> {
        let mut items = Vec::new();
        loop {
            let page = self.list(request.clone()).await?;
            items.extend(page.ai_models);
            if page.next_page_token.is_empty() {
                return Ok(items);
            }
            request.page_token = page.next_page_token;
        }
    }
}