agent-sdk-providers 0.12.0

LLM provider trait, streaming primitives, and first-party provider implementations for the Agent SDK
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
//! Static feature metadata for `OpenAI` models.
//!
//! This registry complements [`crate::model_capabilities`] with API-shape
//! information used to validate requests and choose an inference surface.

/// `OpenAI` API surface on which a model can be used.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelApiSurface {
    ChatCompletions,
    Responses,
    Batch,
}

/// Input modality accepted by a model.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelInputModality {
    Text,
    Image,
}

/// Exact `OpenAI` `reasoning.effort` value.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelReasoningEffort {
    None,
    Minimal,
    Low,
    Medium,
    High,
    XHigh,
    Max,
}

/// Exact `OpenAI` `reasoning.mode` value.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelReasoningMode {
    Standard,
    Pro,
}

/// Exact `OpenAI` `reasoning.context` value.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelReasoningContext {
    Auto,
    CurrentTurn,
    AllTurns,
}

/// Exact `OpenAI` `reasoning.summary` value.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelReasoningSummary {
    Auto,
    Concise,
    Detailed,
}

/// Mechanism available for continuing opaque reasoning state.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelReasoningStateReplay {
    PreviousResponseId,
    ManualOutputItems,
    EncryptedContent,
}

/// Exact GPT-5.6 `prompt_cache_options.mode` value.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelPromptCacheMode {
    Implicit,
    Explicit,
}

/// Exact GPT-5.6 `prompt_cache_options.ttl` value.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelPromptCacheTtl {
    ThirtyMinutes,
}

/// Tool-selection policy accepted by `OpenAI` function calling.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ModelToolChoice {
    None,
    Auto,
    Required,
    ForcedFunction,
    AllowedTools,
}

/// Values supported by a feature and the request surfaces that accept them.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ModelFeatureSet<T: 'static> {
    pub values: &'static [T],
    pub api_surfaces: &'static [ModelApiSurface],
}

/// Reasoning controls supported by a model.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ModelReasoningFeatures {
    pub efforts: ModelFeatureSet<ModelReasoningEffort>,
    pub modes: ModelFeatureSet<ModelReasoningMode>,
    pub contexts: ModelFeatureSet<ModelReasoningContext>,
    pub summaries: ModelFeatureSet<ModelReasoningSummary>,
    pub state_replay: ModelFeatureSet<ModelReasoningStateReplay>,
}

/// Prompt-cache controls supported by a model.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ModelPromptCacheFeatures {
    pub automatic: &'static [ModelApiSurface],
    pub prompt_cache_key: &'static [ModelApiSurface],
    pub modes: ModelFeatureSet<ModelPromptCacheMode>,
    pub ttls: ModelFeatureSet<ModelPromptCacheTtl>,
    pub explicit_breakpoints: &'static [ModelApiSurface],
    pub max_write_breakpoints: Option<u8>,
}

/// Function-tool controls supported by a model.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ModelToolFeatures {
    pub choices: ModelFeatureSet<ModelToolChoice>,
    pub parallel_function_calls: &'static [ModelApiSurface],
}

/// API feature profile for one exact `OpenAI` model ID or alias.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ModelFeatures {
    /// Exact request model ID.
    pub model_id: &'static str,
    /// Canonical model selected by this alias, when applicable.
    pub alias_of: Option<&'static str>,
    /// Total input-plus-output context capacity.
    pub context_window: u32,
    /// Maximum input tokens accepted in one request.
    pub max_input_tokens: u32,
    /// Maximum output-token budget accepted in one request.
    pub max_output_tokens: u32,
    pub api_surfaces: &'static [ModelApiSurface],
    pub input_modalities: &'static [ModelInputModality],
    pub reasoning: ModelReasoningFeatures,
    pub prompt_cache: ModelPromptCacheFeatures,
    pub tools: ModelToolFeatures,
    pub source_urls: &'static [&'static str],
}

const CHAT_AND_RESPONSES: &[ModelApiSurface] =
    &[ModelApiSurface::ChatCompletions, ModelApiSurface::Responses];
const RESPONSES: &[ModelApiSurface] = &[ModelApiSurface::Responses];
const ALL_SURFACES: &[ModelApiSurface] = &[
    ModelApiSurface::ChatCompletions,
    ModelApiSurface::Responses,
    ModelApiSurface::Batch,
];
const TEXT_AND_IMAGE: &[ModelInputModality] =
    &[ModelInputModality::Text, ModelInputModality::Image];

const GPT56_EFFORTS: &[ModelReasoningEffort] = &[
    ModelReasoningEffort::None,
    ModelReasoningEffort::Low,
    ModelReasoningEffort::Medium,
    ModelReasoningEffort::High,
    ModelReasoningEffort::XHigh,
    ModelReasoningEffort::Max,
];
const GPT53_CODEX_EFFORTS: &[ModelReasoningEffort] = &[
    ModelReasoningEffort::Low,
    ModelReasoningEffort::Medium,
    ModelReasoningEffort::High,
    ModelReasoningEffort::XHigh,
];
const GPT52_PRO_EFFORTS: &[ModelReasoningEffort] = &[
    ModelReasoningEffort::Medium,
    ModelReasoningEffort::High,
    ModelReasoningEffort::XHigh,
];
const GPT56_MODES: &[ModelReasoningMode] = &[ModelReasoningMode::Standard, ModelReasoningMode::Pro];
const GPT56_CONTEXTS: &[ModelReasoningContext] = &[
    ModelReasoningContext::Auto,
    ModelReasoningContext::CurrentTurn,
    ModelReasoningContext::AllTurns,
];
const AUTO_SUMMARY: &[ModelReasoningSummary] = &[ModelReasoningSummary::Auto];
const REASONING_STATE_REPLAY: &[ModelReasoningStateReplay] = &[
    ModelReasoningStateReplay::PreviousResponseId,
    ModelReasoningStateReplay::ManualOutputItems,
    ModelReasoningStateReplay::EncryptedContent,
];
const CACHE_MODES: &[ModelPromptCacheMode] = &[
    ModelPromptCacheMode::Implicit,
    ModelPromptCacheMode::Explicit,
];
const CACHE_TTLS: &[ModelPromptCacheTtl] = &[ModelPromptCacheTtl::ThirtyMinutes];
const TOOL_CHOICES: &[ModelToolChoice] = &[
    ModelToolChoice::None,
    ModelToolChoice::Auto,
    ModelToolChoice::Required,
    ModelToolChoice::ForcedFunction,
    ModelToolChoice::AllowedTools,
];

const GPT56_REASONING: ModelReasoningFeatures = ModelReasoningFeatures {
    efforts: ModelFeatureSet {
        values: GPT56_EFFORTS,
        api_surfaces: CHAT_AND_RESPONSES,
    },
    modes: ModelFeatureSet {
        values: GPT56_MODES,
        api_surfaces: RESPONSES,
    },
    contexts: ModelFeatureSet {
        values: GPT56_CONTEXTS,
        api_surfaces: RESPONSES,
    },
    summaries: ModelFeatureSet {
        values: AUTO_SUMMARY,
        api_surfaces: RESPONSES,
    },
    state_replay: ModelFeatureSet {
        values: REASONING_STATE_REPLAY,
        api_surfaces: RESPONSES,
    },
};

const GPT53_CODEX_REASONING: ModelReasoningFeatures = ModelReasoningFeatures {
    efforts: ModelFeatureSet {
        values: GPT53_CODEX_EFFORTS,
        api_surfaces: RESPONSES,
    },
    modes: ModelFeatureSet {
        values: &[],
        api_surfaces: &[],
    },
    contexts: ModelFeatureSet {
        values: &[],
        api_surfaces: &[],
    },
    summaries: ModelFeatureSet {
        values: &[],
        api_surfaces: &[],
    },
    state_replay: ModelFeatureSet {
        values: REASONING_STATE_REPLAY,
        api_surfaces: RESPONSES,
    },
};

const GPT52_PRO_REASONING: ModelReasoningFeatures = ModelReasoningFeatures {
    efforts: ModelFeatureSet {
        values: GPT52_PRO_EFFORTS,
        api_surfaces: RESPONSES,
    },
    modes: ModelFeatureSet {
        values: &[],
        api_surfaces: &[],
    },
    contexts: ModelFeatureSet {
        values: &[],
        api_surfaces: &[],
    },
    summaries: ModelFeatureSet {
        values: &[],
        api_surfaces: &[],
    },
    state_replay: ModelFeatureSet {
        values: REASONING_STATE_REPLAY,
        api_surfaces: RESPONSES,
    },
};

const GPT56_CACHE: ModelPromptCacheFeatures = ModelPromptCacheFeatures {
    automatic: CHAT_AND_RESPONSES,
    prompt_cache_key: CHAT_AND_RESPONSES,
    modes: ModelFeatureSet {
        values: CACHE_MODES,
        api_surfaces: CHAT_AND_RESPONSES,
    },
    ttls: ModelFeatureSet {
        values: CACHE_TTLS,
        api_surfaces: CHAT_AND_RESPONSES,
    },
    explicit_breakpoints: CHAT_AND_RESPONSES,
    max_write_breakpoints: Some(4),
};

const LEGACY_AUTOMATIC_CACHE: ModelPromptCacheFeatures = ModelPromptCacheFeatures {
    automatic: RESPONSES,
    prompt_cache_key: RESPONSES,
    modes: ModelFeatureSet {
        values: &[],
        api_surfaces: &[],
    },
    ttls: ModelFeatureSet {
        values: &[],
        api_surfaces: &[],
    },
    explicit_breakpoints: &[],
    max_write_breakpoints: None,
};

const FUNCTION_TOOLS: ModelToolFeatures = ModelToolFeatures {
    choices: ModelFeatureSet {
        values: TOOL_CHOICES,
        api_surfaces: CHAT_AND_RESPONSES,
    },
    parallel_function_calls: CHAT_AND_RESPONSES,
};

const RESPONSES_FUNCTION_TOOLS: ModelToolFeatures = ModelToolFeatures {
    choices: ModelFeatureSet {
        values: TOOL_CHOICES,
        api_surfaces: RESPONSES,
    },
    parallel_function_calls: RESPONSES,
};

const REASONING_URL: &str = "https://developers.openai.com/api/docs/guides/reasoning";
const CACHE_URL: &str = "https://developers.openai.com/api/docs/guides/prompt-caching";
const FUNCTION_CALLING_URL: &str = "https://developers.openai.com/api/docs/guides/function-calling";
const GPT56_GUIDE_URL: &str = "https://developers.openai.com/api/docs/guides/latest-model";
const GPT56_SOL_URL: &str = "https://developers.openai.com/api/docs/models/gpt-5.6-sol";
const GPT56_TERRA_URL: &str = "https://developers.openai.com/api/docs/models/gpt-5.6-terra";
const GPT56_LUNA_URL: &str = "https://developers.openai.com/api/docs/models/gpt-5.6-luna";
const GPT53_CODEX_URL: &str = "https://developers.openai.com/api/docs/models/gpt-5.3-codex";
const GPT52_PRO_URL: &str = "https://developers.openai.com/api/docs/models/gpt-5.2-pro";

const GPT56_SOURCES: &[&str] = &[
    GPT56_SOL_URL,
    GPT56_GUIDE_URL,
    REASONING_URL,
    CACHE_URL,
    FUNCTION_CALLING_URL,
];
const GPT56_SOL_SOURCES: &[&str] = GPT56_SOURCES;
const GPT56_TERRA_SOURCES: &[&str] = &[
    GPT56_TERRA_URL,
    GPT56_GUIDE_URL,
    REASONING_URL,
    CACHE_URL,
    FUNCTION_CALLING_URL,
];
const GPT56_LUNA_SOURCES: &[&str] = &[
    GPT56_LUNA_URL,
    GPT56_GUIDE_URL,
    REASONING_URL,
    CACHE_URL,
    FUNCTION_CALLING_URL,
];
const GPT53_CODEX_SOURCES: &[&str] = &[
    GPT53_CODEX_URL,
    REASONING_URL,
    CACHE_URL,
    FUNCTION_CALLING_URL,
];
const GPT52_PRO_SOURCES: &[&str] = &[
    GPT52_PRO_URL,
    REASONING_URL,
    CACHE_URL,
    FUNCTION_CALLING_URL,
];

const MODEL_FEATURES: &[ModelFeatures] = &[
    ModelFeatures {
        model_id: "gpt-5.6",
        alias_of: Some("gpt-5.6-sol"),
        context_window: 1_050_000,
        max_input_tokens: 922_000,
        max_output_tokens: 128_000,
        api_surfaces: ALL_SURFACES,
        input_modalities: TEXT_AND_IMAGE,
        reasoning: GPT56_REASONING,
        prompt_cache: GPT56_CACHE,
        tools: FUNCTION_TOOLS,
        source_urls: GPT56_SOURCES,
    },
    ModelFeatures {
        model_id: "gpt-5.6-sol",
        alias_of: None,
        context_window: 1_050_000,
        max_input_tokens: 922_000,
        max_output_tokens: 128_000,
        api_surfaces: ALL_SURFACES,
        input_modalities: TEXT_AND_IMAGE,
        reasoning: GPT56_REASONING,
        prompt_cache: GPT56_CACHE,
        tools: FUNCTION_TOOLS,
        source_urls: GPT56_SOL_SOURCES,
    },
    ModelFeatures {
        model_id: "gpt-5.6-terra",
        alias_of: None,
        context_window: 1_050_000,
        max_input_tokens: 922_000,
        max_output_tokens: 128_000,
        api_surfaces: ALL_SURFACES,
        input_modalities: TEXT_AND_IMAGE,
        reasoning: GPT56_REASONING,
        prompt_cache: GPT56_CACHE,
        tools: FUNCTION_TOOLS,
        source_urls: GPT56_TERRA_SOURCES,
    },
    ModelFeatures {
        model_id: "gpt-5.6-luna",
        alias_of: None,
        context_window: 1_050_000,
        max_input_tokens: 922_000,
        max_output_tokens: 128_000,
        api_surfaces: ALL_SURFACES,
        input_modalities: TEXT_AND_IMAGE,
        reasoning: GPT56_REASONING,
        prompt_cache: GPT56_CACHE,
        tools: FUNCTION_TOOLS,
        source_urls: GPT56_LUNA_SOURCES,
    },
    ModelFeatures {
        model_id: "gpt-5.3-codex",
        alias_of: None,
        context_window: 400_000,
        max_input_tokens: 272_000,
        max_output_tokens: 128_000,
        api_surfaces: RESPONSES,
        input_modalities: TEXT_AND_IMAGE,
        reasoning: GPT53_CODEX_REASONING,
        prompt_cache: LEGACY_AUTOMATIC_CACHE,
        tools: RESPONSES_FUNCTION_TOOLS,
        source_urls: GPT53_CODEX_SOURCES,
    },
    ModelFeatures {
        model_id: "gpt-5.2-pro",
        alias_of: None,
        context_window: 400_000,
        max_input_tokens: 272_000,
        max_output_tokens: 128_000,
        api_surfaces: RESPONSES,
        input_modalities: TEXT_AND_IMAGE,
        reasoning: GPT52_PRO_REASONING,
        prompt_cache: LEGACY_AUTOMATIC_CACHE,
        tools: RESPONSES_FUNCTION_TOOLS,
        source_urls: GPT52_PRO_SOURCES,
    },
];

/// Return the static feature profile for an exact model ID or alias.
#[must_use]
pub fn get_model_features(model_id: &str) -> Option<&'static ModelFeatures> {
    MODEL_FEATURES
        .iter()
        .find(|features| features.model_id == model_id)
}

/// Return all model feature profiles bundled with this SDK release.
#[must_use]
pub const fn supported_model_features() -> &'static [ModelFeatures] {
    MODEL_FEATURES
}

#[cfg(test)]
mod tests {
    use super::*;
    use anyhow::Context;

    #[test]
    fn registry_contains_every_official_row() -> anyhow::Result<()> {
        for model_id in [
            "gpt-5.6",
            "gpt-5.6-sol",
            "gpt-5.6-terra",
            "gpt-5.6-luna",
            "gpt-5.3-codex",
            "gpt-5.2-pro",
        ] {
            get_model_features(model_id)
                .with_context(|| format!("missing model feature row for {model_id}"))?;
        }
        assert!(get_model_features("unknown-model").is_none());
        Ok(())
    }

    #[test]
    fn gpt56_alias_preserves_exact_surface_and_reasoning_features() -> anyhow::Result<()> {
        let features = get_model_features("gpt-5.6").context("missing gpt-5.6 features")?;

        assert_eq!(features.alias_of, Some("gpt-5.6-sol"));
        assert_eq!(features.context_window, 1_050_000);
        assert_eq!(features.max_input_tokens, 922_000);
        assert_eq!(features.max_output_tokens, 128_000);
        assert_eq!(features.api_surfaces, ALL_SURFACES);
        assert_eq!(features.input_modalities, TEXT_AND_IMAGE);
        assert_eq!(features.reasoning.efforts.values, GPT56_EFFORTS);
        assert_eq!(features.reasoning.modes.values, GPT56_MODES);
        assert_eq!(features.reasoning.contexts.values, GPT56_CONTEXTS);
        assert_eq!(features.reasoning.summaries.values, AUTO_SUMMARY);
        assert_eq!(
            features.reasoning.state_replay.values,
            REASONING_STATE_REPLAY
        );
        Ok(())
    }

    #[test]
    fn gpt56_exposes_explicit_cache_and_parallel_tool_controls() -> anyhow::Result<()> {
        let features =
            get_model_features("gpt-5.6-terra").context("missing gpt-5.6-terra features")?;

        assert_eq!(features.prompt_cache.modes.values, CACHE_MODES);
        assert_eq!(features.prompt_cache.ttls.values, CACHE_TTLS);
        assert_eq!(features.prompt_cache.max_write_breakpoints, Some(4));
        assert_eq!(features.tools.choices.values, TOOL_CHOICES);
        assert_eq!(features.tools.parallel_function_calls, CHAT_AND_RESPONSES);
        Ok(())
    }

    #[test]
    fn gpt53_codex_keeps_legacy_boundaries() -> anyhow::Result<()> {
        let features =
            get_model_features("gpt-5.3-codex").context("missing gpt-5.3-codex features")?;

        assert_eq!(features.reasoning.efforts.values, GPT53_CODEX_EFFORTS);
        assert_eq!(features.api_surfaces, RESPONSES);
        assert_eq!(features.context_window, 400_000);
        assert_eq!(features.max_input_tokens, 272_000);
        assert_eq!(features.max_output_tokens, 128_000);
        assert_eq!(features.reasoning.efforts.api_surfaces, RESPONSES);
        assert!(features.reasoning.modes.values.is_empty());
        assert!(features.reasoning.contexts.values.is_empty());
        assert!(features.reasoning.summaries.values.is_empty());
        assert!(features.prompt_cache.modes.values.is_empty());
        assert!(features.prompt_cache.explicit_breakpoints.is_empty());
        assert_eq!(
            features.reasoning.state_replay.values,
            REASONING_STATE_REPLAY
        );
        Ok(())
    }

    #[test]
    fn gpt52_pro_is_responses_only_with_verified_efforts() -> anyhow::Result<()> {
        let features = get_model_features("gpt-5.2-pro").context("missing gpt-5.2-pro features")?;

        assert_eq!(features.api_surfaces, RESPONSES);
        assert_eq!(features.reasoning.efforts.values, GPT52_PRO_EFFORTS);
        assert_eq!(features.reasoning.efforts.api_surfaces, RESPONSES);
        assert_eq!(features.context_window, 400_000);
        assert_eq!(features.max_output_tokens, 128_000);
        Ok(())
    }

    #[test]
    fn model_ids_are_unique() {
        for (index, features) in supported_model_features().iter().enumerate() {
            assert!(
                supported_model_features()[index + 1..]
                    .iter()
                    .all(|candidate| candidate.model_id != features.model_id)
            );
        }
    }
}