llmshim 0.2.1

Blazing fast LLM API translation layer in pure Rust
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
//! Static model registry — shared between the CLI and proxy.
//!
//! Beyond routing identity (`id`/`provider`/`name`/`label`), each entry can
//! carry **spec metadata**: context window, output ceiling, and per-capability
//! support. This lets consumers read a model's facts from one place instead of
//! hand-maintaining a parallel table that drifts every time a model is added.
//!
//! Honesty rule: unverified facts stay [`Support::Unknown`] / `None`. We never
//! guess a number to fill a cell. Specs are a point-in-time snapshot, pinned by
//! the crate version exactly like the model list itself.
//!
//! Spec source (as of 2026-07-16): populated from official provider docs
//! (platform.claude.com, developers.openai.com, ai.google.dev, docs.x.ai).
//! `reasoning` support is additionally cross-checked against the live-verified
//! clamp logic in `src/providers/*.rs`. Provider-specific caveats:
//! - **Gemini**: publishes input and output limits separately (no combined
//!   total), so `context_window_tokens` is the documented input limit and
//!   `max_output_tokens` is the separate output limit.
//! - **Anthropic**: the 1M-token window is the documented default for the
//!   listed models; Haiku 4.5 is 200k. Output is the synchronous Messages API
//!   ceiling (higher via the Batch API beta).
//! - **xAI**: does not publish a per-model max output ceiling (`None`), and
//!   does not state streaming / parallel-tool-call support per model
//!   (`Unknown`, not upgraded from the general API behavior).
//! - `parallel_tool_calls` is `Unknown` for most models — providers rarely
//!   document it per model, and we don't infer it.

/// Whether a model supports a capability. Tri-state so "we haven't verified
/// this yet" is a first-class, honest value rather than a silent `false`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Support {
    /// The model supports this capability.
    Supported,
    /// The model does not support this capability.
    Unsupported,
    /// Not yet verified. Consumers decide how to treat it (probe, assume, ask).
    #[default]
    Unknown,
}

/// Per-capability support flags for a model. Every field defaults to
/// [`Support::Unknown`].
///
/// Note: reasoning is intentionally a single [`Support`] ("does this model
/// accept a reasoning control at all"). The detailed per-tier mapping is not
/// duplicated here — it lives in the provider transforms and is pinned by the
/// `unit_*` tests. See `docs/src/guides/reasoning.md`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ModelCapabilities {
    /// Function/tool calling.
    pub tools: Support,
    /// Server-sent streaming responses.
    pub streaming: Support,
    /// Image input.
    pub images: Support,
    /// Provider-side prompt caching.
    pub prompt_cache: Support,
    /// Structured output / JSON-schema-constrained responses.
    pub structured_output: Support,
    /// More than one tool call in a single assistant turn.
    pub parallel_tool_calls: Support,
    /// Accepts a reasoning-effort control (see note above).
    pub reasoning: Support,
}

impl ModelCapabilities {
    /// All-unknown baseline — the honest default before verification. Usable in
    /// `const` context, unlike [`Default::default`].
    pub const fn unknown() -> Self {
        Self {
            tools: Support::Unknown,
            streaming: Support::Unknown,
            images: Support::Unknown,
            prompt_cache: Support::Unknown,
            structured_output: Support::Unknown,
            parallel_tool_calls: Support::Unknown,
            reasoning: Support::Unknown,
        }
    }

    /// Set tool support (const builder).
    pub const fn with_tools(mut self, s: Support) -> Self {
        self.tools = s;
        self
    }
    /// Set streaming support (const builder).
    pub const fn with_streaming(mut self, s: Support) -> Self {
        self.streaming = s;
        self
    }
    /// Set image-input support (const builder).
    pub const fn with_images(mut self, s: Support) -> Self {
        self.images = s;
        self
    }
    /// Set prompt-cache support (const builder).
    pub const fn with_prompt_cache(mut self, s: Support) -> Self {
        self.prompt_cache = s;
        self
    }
    /// Set structured-output support (const builder).
    pub const fn with_structured_output(mut self, s: Support) -> Self {
        self.structured_output = s;
        self
    }
    /// Set parallel-tool-call support (const builder).
    pub const fn with_parallel_tool_calls(mut self, s: Support) -> Self {
        self.parallel_tool_calls = s;
        self
    }
    /// Set reasoning-control support (const builder).
    pub const fn with_reasoning(mut self, s: Support) -> Self {
        self.reasoning = s;
        self
    }
}

impl Default for ModelCapabilities {
    fn default() -> Self {
        Self::unknown()
    }
}

/// A registered model: routing identity plus optional spec metadata.
///
/// `#[non_exhaustive]`: construct via the crate's [`MODELS`] table and read the
/// fields you need. New spec fields will be added over time without a breaking
/// change.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct ModelInfo {
    /// Full routing id, e.g. `"openai/gpt-5.6-sol"`.
    pub id: &'static str,
    /// Provider key, e.g. `"openai"`.
    pub provider: &'static str,
    /// Bare model name sent upstream, e.g. `"gpt-5.6-sol"`.
    pub name: &'static str,
    /// Human-facing label, e.g. `"GPT-5.6 Sol"`.
    pub label: &'static str,

    /// Total context window in tokens (input for Gemini — see module docs), if
    /// published.
    pub context_window_tokens: Option<u32>,
    /// Maximum output tokens the model will emit in one response, if published.
    pub max_output_tokens: Option<u32>,
    /// Per-capability support flags ([`Support::Unknown`] where unverified).
    pub capabilities: ModelCapabilities,
}

/// Everything supported, including parallel tool calls.
const CAPS_FULL: ModelCapabilities = ModelCapabilities {
    tools: Support::Supported,
    streaming: Support::Supported,
    images: Support::Supported,
    prompt_cache: Support::Supported,
    structured_output: Support::Supported,
    parallel_tool_calls: Support::Supported,
    reasoning: Support::Supported,
};
/// tools/streaming/images/prompt_cache/structured_output + reasoning supported;
/// parallel tool calls not documented per model (Unknown). (OpenAI & Gemini.)
const CAPS_STD: ModelCapabilities = ModelCapabilities {
    parallel_tool_calls: Support::Unknown,
    ..CAPS_FULL
};
/// xAI documented models: tools/images/prompt_cache/structured_output +
/// reasoning supported; streaming and parallel tool calls not stated (Unknown).
const CAPS_XAI: ModelCapabilities = ModelCapabilities {
    tools: Support::Supported,
    streaming: Support::Unknown,
    images: Support::Supported,
    prompt_cache: Support::Supported,
    structured_output: Support::Supported,
    parallel_tool_calls: Support::Unknown,
    reasoning: Support::Supported,
};
pub const MODELS: &[ModelInfo] = &[
    ModelInfo {
        id: "openai/gpt-5.6-sol",
        provider: "openai",
        name: "gpt-5.6-sol",
        label: "GPT-5.6 Sol",
        context_window_tokens: Some(1_050_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "openai/gpt-5.6-terra",
        provider: "openai",
        name: "gpt-5.6-terra",
        label: "GPT-5.6 Terra",
        context_window_tokens: Some(1_050_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "openai/gpt-5.6-luna",
        provider: "openai",
        name: "gpt-5.6-luna",
        label: "GPT-5.6 Luna",
        context_window_tokens: Some(1_050_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "openai/gpt-5.5",
        provider: "openai",
        name: "gpt-5.5",
        label: "GPT-5.5",
        context_window_tokens: Some(1_050_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "openai/gpt-5.5-pro",
        provider: "openai",
        name: "gpt-5.5-pro",
        label: "GPT-5.5 Pro",
        context_window_tokens: Some(1_050_000),
        max_output_tokens: Some(128_000),
        // pro: streaming explicitly not supported; no cached-input pricing.
        capabilities: CAPS_STD
            .with_streaming(Support::Unsupported)
            .with_prompt_cache(Support::Unknown),
    },
    ModelInfo {
        id: "openai/gpt-5.4",
        provider: "openai",
        name: "gpt-5.4",
        label: "GPT-5.4",
        context_window_tokens: Some(1_050_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "openai/gpt-5.4-pro",
        provider: "openai",
        name: "gpt-5.4-pro",
        label: "GPT-5.4 Pro",
        context_window_tokens: Some(1_050_000),
        max_output_tokens: Some(128_000),
        // pro: structured outputs explicitly not supported; no cached-input row.
        capabilities: CAPS_STD
            .with_structured_output(Support::Unsupported)
            .with_prompt_cache(Support::Unknown),
    },
    ModelInfo {
        id: "openai/gpt-5.4-mini",
        provider: "openai",
        name: "gpt-5.4-mini",
        label: "GPT-5.4 Mini",
        context_window_tokens: Some(400_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "openai/gpt-5.4-nano",
        provider: "openai",
        name: "gpt-5.4-nano",
        label: "GPT-5.4 Nano",
        context_window_tokens: Some(400_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "anthropic/claude-opus-4-8",
        provider: "anthropic",
        name: "claude-opus-4-8",
        label: "Claude Opus 4.8",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_FULL,
    },
    ModelInfo {
        id: "anthropic/claude-sonnet-5",
        provider: "anthropic",
        name: "claude-sonnet-5",
        label: "Claude Sonnet 5",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_FULL,
    },
    ModelInfo {
        id: "anthropic/claude-opus-4-7",
        provider: "anthropic",
        name: "claude-opus-4-7",
        label: "Claude Opus 4.7",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_FULL,
    },
    ModelInfo {
        id: "anthropic/claude-opus-4-6",
        provider: "anthropic",
        name: "claude-opus-4-6",
        label: "Claude Opus 4.6",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_FULL,
    },
    ModelInfo {
        id: "anthropic/claude-sonnet-4-6",
        provider: "anthropic",
        name: "claude-sonnet-4-6",
        label: "Claude Sonnet 4.6",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: Some(128_000),
        capabilities: CAPS_FULL,
    },
    ModelInfo {
        id: "anthropic/claude-haiku-4-5-20251001",
        provider: "anthropic",
        name: "claude-haiku-4-5-20251001",
        label: "Claude Haiku 4.5",
        context_window_tokens: Some(200_000),
        max_output_tokens: Some(64_000),
        capabilities: CAPS_FULL,
    },
    ModelInfo {
        id: "gemini/gemini-3.5-flash",
        provider: "gemini",
        name: "gemini-3.5-flash",
        label: "Gemini 3.5 Flash",
        context_window_tokens: Some(1_048_576),
        max_output_tokens: Some(65_536),
        capabilities: CAPS_FULL,
    },
    ModelInfo {
        id: "gemini/gemini-3.1-pro-preview",
        provider: "gemini",
        name: "gemini-3.1-pro-preview",
        label: "Gemini 3.1 Pro",
        context_window_tokens: Some(1_048_576),
        max_output_tokens: Some(65_536),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "gemini/gemini-3-flash-preview",
        provider: "gemini",
        name: "gemini-3-flash-preview",
        label: "Gemini 3 Flash",
        context_window_tokens: Some(1_048_576),
        max_output_tokens: Some(65_536),
        capabilities: CAPS_STD,
    },
    ModelInfo {
        id: "xai/grok-4.5",
        provider: "xai",
        name: "grok-4.5",
        label: "Grok 4.5",
        context_window_tokens: Some(500_000),
        max_output_tokens: None,
        capabilities: CAPS_XAI,
    },
    ModelInfo {
        id: "xai/grok-4.3",
        provider: "xai",
        name: "grok-4.3",
        label: "Grok 4.3",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: None,
        capabilities: CAPS_XAI,
    },
    // grok-4.20-* models are name-locked: reasoning on/off is encoded in the
    // model name and the API 400s on any reasoning parameter (see
    // `src/providers/xai.rs::is_reasoning_name_locked`).
    ModelInfo {
        id: "xai/grok-4.20-multi-agent-beta-0309",
        provider: "xai",
        name: "grok-4.20-multi-agent-beta-0309",
        label: "Grok 4.20 Multi-Agent",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: None,
        capabilities: CAPS_XAI.with_reasoning(Support::Unsupported),
    },
    ModelInfo {
        id: "xai/grok-4.20-beta-0309-reasoning",
        provider: "xai",
        name: "grok-4.20-beta-0309-reasoning",
        label: "Grok 4.20 Reasoning",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: None,
        capabilities: CAPS_XAI.with_reasoning(Support::Unsupported),
    },
    ModelInfo {
        id: "xai/grok-4.20-beta-0309-non-reasoning",
        provider: "xai",
        name: "grok-4.20-beta-0309-non-reasoning",
        label: "Grok 4.20",
        context_window_tokens: Some(1_000_000),
        max_output_tokens: None,
        capabilities: CAPS_XAI.with_reasoning(Support::Unsupported),
    },
];

/// Get models filtered to only providers that are registered (have API keys).
pub fn available_models(registered_providers: &[&str]) -> Vec<&'static ModelInfo> {
    MODELS
        .iter()
        .filter(|m| registered_providers.contains(&m.provider))
        .collect()
}

/// Look up a single model's full spec by full id (`"openai/gpt-5.6-sol"`) or by
/// bare name (`"gpt-5.6-sol"`). Returns `None` for unregistered models.
pub fn spec(id: &str) -> Option<&'static ModelInfo> {
    MODELS.iter().find(|m| m.id == id || m.name == id)
}