Skip to main content

alien_core/
ai_catalog.rs

1//! Curated, per-cloud model catalog for the AI gateway.
2//!
3//! Single source of truth for which public model ids each cloud exposes, the
4//! upstream id the gateway forwards, and the wire protocol of the model's native
5//! endpoint. Backs `getAvailableModels()` and the gateway's `/v1/models`, and the
6//! Azure controller deploys the Azure entries as named deployments at provision
7//! time (see `azure_deployments`).
8//!
9//! A model is includable only if its cloud serves it over a protocol the client
10//! SDK already speaks (OpenAI Chat Completions or Anthropic Messages), so the
11//! gateway forwards the request body untranslated.
12
13use crate::Platform;
14use serde::{Deserialize, Serialize};
15
16/// A public API accepted from an application client.
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
18#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
19#[serde(rename_all = "kebab-case")]
20pub enum ClientApi {
21    OpenAiChatCompletions,
22    OpenAiResponses,
23    AnthropicMessages,
24}
25
26impl ClientApi {
27    /// Public request protocols accepted for every text-generation model. The
28    /// gateway translates to the model's provider-native protocol when needed.
29    pub const ALL: [Self; 3] = [
30        Self::OpenAiChatCompletions,
31        Self::OpenAiResponses,
32        Self::AnthropicMessages,
33    ];
34}
35
36/// The provider API used for the upstream request. This is deliberately
37/// separate from [`ClientApi`]: an adapter may expose one client API over a
38/// different provider API, but only after that exact combination is qualified.
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
40#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
41#[serde(rename_all = "lowercase")]
42pub enum ProviderApi {
43    /// OpenAI Chat Completions (`/v1/chat/completions`).
44    OpenAi,
45    /// Anthropic Messages (`/v1/messages`).
46    Anthropic,
47    /// OpenAI Responses on bedrock-mantle. The only API the GPT-5 family serves;
48    /// the exact path is per-model, see `RESPONSES_UPSTREAM`.
49    OpenAiResponses,
50}
51
52/// The one-time action, if any, a customer must take in the cloud provider before
53/// the gateway can invoke a model. Static per (provider, cloud), surfaced in docs
54/// and the example README. Distinct from the read-only availability observation
55/// reported by the resource heartbeat for a particular deployment.
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub enum Activation {
58    /// Enabled by default; nothing for the customer to do (quota still applies).
59    OutOfBox,
60    /// Needs a one-time customer action first; the string says what.
61    RequiresOneTimeStep(&'static str),
62}
63
64/// One curated model: the public id an app requests, the cloud that serves it,
65/// the upstream id the gateway forwards (for Azure this is the deployment name),
66/// and the protocol of its native endpoint.
67#[derive(Debug, Clone)]
68pub struct CatalogModel {
69    pub public_id: &'static str,
70    pub cloud: Platform,
71    pub upstream_id: &'static str,
72    /// Provider-native protocols. These choose the lowest-overhead upstream;
73    /// applications may use any [`ClientApi`] through the gateway adapter.
74    pub client_apis: &'static [ClientApi],
75    pub provider_api: ProviderApi,
76}
77
78/// One model served directly by Anthropic. This is separate from `CatalogModel`:
79/// direct Anthropic is a provider connection, not a deployable cloud platform.
80#[derive(Debug, Clone, Copy)]
81pub struct DirectAnthropicModel {
82    pub public_id: &'static str,
83    pub upstream_id: &'static str,
84}
85
86/// One OpenAI model qualified through the Gateway's direct-provider route.
87///
88/// OpenAI's account model listing also contains embeddings, image, audio,
89/// moderation, realtime, and other APIs. Keep this list explicit so
90/// `GET /v1/models` never claims that an observed provider model is callable
91/// through Chat Completions or Responses when it is not.
92#[derive(Debug, Clone, Copy)]
93pub struct DirectOpenAiModel {
94    pub public_id: &'static str,
95    pub client_apis: &'static [ClientApi],
96}
97
98/// The one Databricks resource and protocol used for a direct model.
99///
100/// A caller may use any public gateway protocol. This route describes only the
101/// provider-facing request after protocol translation, so the incoming API can
102/// never accidentally select a retired Databricks path.
103#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104pub enum DirectDatabricksUpstream {
105    ServingEndpointChat { endpoint: &'static str },
106    ModelServiceChat { service: &'static str },
107    ModelServiceMessages { service: &'static str },
108}
109
110impl DirectDatabricksUpstream {
111    pub const fn model_id(self) -> &'static str {
112        match self {
113            Self::ServingEndpointChat { endpoint } => endpoint,
114            Self::ModelServiceChat { service } | Self::ModelServiceMessages { service } => service,
115        }
116    }
117
118    pub const fn client_api(self) -> ClientApi {
119        match self {
120            Self::ServingEndpointChat { .. } | Self::ModelServiceChat { .. } => {
121                ClientApi::OpenAiChatCompletions
122            }
123            Self::ModelServiceMessages { .. } => ClientApi::AnthropicMessages,
124        }
125    }
126}
127
128/// One Databricks-hosted text model with an explicitly qualified upstream route.
129#[derive(Debug, Clone, Copy)]
130pub struct DirectDatabricksModel {
131    pub public_id: &'static str,
132    pub upstream: DirectDatabricksUpstream,
133}
134
135impl DirectAnthropicModel {
136    pub fn display_name(&self) -> &'static str {
137        resolve(self.public_id)
138            .map(CatalogModel::display_name)
139            .unwrap_or(self.public_id)
140    }
141}
142
143impl CatalogModel {
144    /// The model's publisher, for grouping in a picker. Derived from the public id,
145    /// so the same public id reports the same provider on every cloud.
146    pub fn provider(&self) -> &'static str {
147        let id = self.public_id;
148        if id.starts_with("claude") {
149            "anthropic"
150        } else if id.starts_with("gpt") || id == "model-router" {
151            "openai"
152        } else if id.starts_with("gemini") || id.starts_with("gemma") {
153            "google"
154        } else if id.starts_with("qwen") {
155            "qwen"
156        } else if id.starts_with("deepseek") {
157            "deepseek"
158        } else if id.starts_with("mistral")
159            || id.starts_with("devstral")
160            || id.starts_with("magistral")
161            || id.starts_with("ministral")
162        {
163            "mistral"
164        } else if id.starts_with("minimax") {
165            "minimax"
166        } else if id.starts_with("kimi") {
167            "moonshotai"
168        } else if id.starts_with("nemotron") {
169            "nvidia"
170        } else if id.starts_with("glm") {
171            "zai"
172        } else if id.starts_with("palmyra") {
173            "writer"
174        } else {
175            "unknown"
176        }
177    }
178
179    /// A human label for a model picker. Curated per id rather than derived so the
180    /// acronyms (GPT, OSS, GLM, VL) and versions read correctly.
181    pub fn display_name(&self) -> &'static str {
182        match self.public_id {
183            "gpt-5.6-sol" => "GPT-5.6 Sol",
184            "gpt-5.6-terra" => "GPT-5.6 Terra",
185            "gpt-5.6-luna" => "GPT-5.6 Luna",
186            "gpt-5.5" => "GPT-5.5",
187            "gpt-5.4" => "GPT-5.4",
188            "gpt-oss-20b" => "GPT-OSS 20B",
189            "gpt-oss-120b" => "GPT-OSS 120B",
190            "gpt-oss-safeguard-20b" => "GPT-OSS Safeguard 20B",
191            "gpt-oss-safeguard-120b" => "GPT-OSS Safeguard 120B",
192            "deepseek-v3.2" => "DeepSeek V3.2",
193            "qwen3-32b" => "Qwen3 32B",
194            "qwen3-coder-30b" => "Qwen3 Coder 30B",
195            "qwen3-next-80b" => "Qwen3 Next 80B",
196            "qwen3-vl-235b" => "Qwen3 VL 235B",
197            "mistral-large-3" => "Mistral Large 3",
198            "devstral-2" => "Devstral 2",
199            "magistral-small" => "Magistral Small",
200            "ministral-3-14b" => "Ministral 3 14B",
201            "ministral-3-8b" => "Ministral 3 8B",
202            "ministral-3-3b" => "Ministral 3 3B",
203            "minimax-m2" => "MiniMax M2",
204            "minimax-m2.1" => "MiniMax M2.1",
205            "minimax-m2.5" => "MiniMax M2.5",
206            "kimi-k2.5" => "Kimi K2.5",
207            "nemotron-nano-9b" => "Nemotron Nano 9B",
208            "nemotron-nano-12b" => "Nemotron Nano 12B",
209            "nemotron-nano-3-30b" => "Nemotron Nano 3 30B",
210            "nemotron-super-3-120b" => "Nemotron Super 3 120B",
211            "gemma-3-4b" => "Gemma 3 4B",
212            "gemma-3-12b" => "Gemma 3 12B",
213            "gemma-3-27b" => "Gemma 3 27B",
214            "glm-4.7" => "GLM 4.7",
215            "glm-4.7-flash" => "GLM 4.7 Flash",
216            "glm-5" => "GLM 5",
217            "palmyra-vision-7b" => "Palmyra Vision 7B",
218            "claude-opus-5" => "Claude Opus 5",
219            "claude-sonnet-5" => "Claude Sonnet 5",
220            "claude-opus-4.8" => "Claude Opus 4.8",
221            "claude-opus-4.7" => "Claude Opus 4.7",
222            "claude-opus-4.6" => "Claude Opus 4.6",
223            "claude-opus-4.5" => "Claude Opus 4.5",
224            "claude-sonnet-4.6" => "Claude Sonnet 4.6",
225            "claude-sonnet-4.5" => "Claude Sonnet 4.5",
226            "claude-haiku-4.5" => "Claude Haiku 4.5",
227            "claude-fable-5" => "Claude Fable 5",
228            "gemini-2.5-pro" => "Gemini 2.5 Pro",
229            "gemini-2.5-flash" => "Gemini 2.5 Flash",
230            "gemini-2.5-flash-lite" => "Gemini 2.5 Flash Lite",
231            "gemini-3.5-flash" => "Gemini 3.5 Flash",
232            "gemini-3.1-flash-lite" => "Gemini 3.1 Flash Lite",
233            "gpt-4.1" => "GPT-4.1",
234            "gpt-4o-mini" => "GPT-4o mini",
235            "model-router" => "Model Router",
236            other => other,
237        }
238    }
239
240    /// The one-time enablement step for this model on its cloud, if any. Only Claude
241    /// needs one today, and the step differs per cloud.
242    pub fn activation(&self) -> Activation {
243        if !self.public_id.starts_with("claude") {
244            return Activation::OutOfBox;
245        }
246        match self.cloud {
247            Platform::Aws => Activation::RequiresOneTimeStep(
248                "Submit the one-time Anthropic use-case form in the Bedrock console.",
249            ),
250            Platform::Gcp => Activation::RequiresOneTimeStep(
251                "Enable Claude in Vertex AI Model Garden and accept Anthropic's terms of service, one-time, in the Google Cloud console.",
252            ),
253            Platform::Azure => Activation::RequiresOneTimeStep(
254                "Accept the Marketplace terms and create the Claude deployment in the Microsoft Foundry portal (one-time).",
255            ),
256            _ => Activation::OutOfBox,
257        }
258    }
259}
260
261/// The cross-region inference-profile geo prefix for a Bedrock region. Claude on
262/// Bedrock is invocable only through a geo profile (e.g. `us.anthropic.…`).
263///
264/// us / us-gov regions keep their own geo. Every other commercial region routes via
265/// the region-agnostic `global` profile: current-generation Claude models publish a
266/// `global.` inference profile invocable from any commercial region (verified against
267/// live Bedrock), and do NOT publish `eu.`/`apac.` profiles, so a per-continent
268/// prefix would build a non-existent id. (An older model that publishes only a `us.`
269/// profile, e.g. opus-4.1, stays us-region-only either way.)
270pub fn bedrock_geo(region: &str) -> &'static str {
271    if region.starts_with("us-gov-") {
272        "us-gov"
273    } else if region.starts_with("us-") {
274        "us"
275    } else {
276        "global"
277    }
278}
279
280/// The Bedrock model id an app invokes `upstream_id` with from `region`: the geo
281/// inference profile (e.g. `us.anthropic.claude-haiku-4-5-20251001-v1:0`). The gateway
282/// builds its Claude requests with it, and availability is checked against the same id.
283pub fn bedrock_inference_profile_id(region: &str, upstream_id: &str) -> String {
284    format!("{}.{}", bedrock_geo(region), upstream_id)
285}
286
287static CATALOG: &[CatalogModel] = &[
288    // AWS Bedrock over `/openai/v1` chat completions. The plain Bedrock model id,
289    // not the `us.*` cross-region inference profile — that endpoint rejects it.
290    // Invoke/Converse-only models (older Llama/Mistral-v0/Nova) can't be served here.
291    // The GPT-5 family is Responses-only: chat completions, converse and invoke are
292    // all unavailable, so `upstream_id` here is the mantle id.
293    CatalogModel {
294        public_id: "gpt-5.6-sol",
295        cloud: Platform::Aws,
296        upstream_id: "openai.gpt-5.6-sol",
297        client_apis: &[ClientApi::OpenAiResponses],
298        provider_api: ProviderApi::OpenAiResponses,
299    },
300    CatalogModel {
301        public_id: "gpt-5.6-terra",
302        cloud: Platform::Aws,
303        upstream_id: "openai.gpt-5.6-terra",
304        client_apis: &[ClientApi::OpenAiResponses],
305        provider_api: ProviderApi::OpenAiResponses,
306    },
307    CatalogModel {
308        public_id: "gpt-5.6-luna",
309        cloud: Platform::Aws,
310        upstream_id: "openai.gpt-5.6-luna",
311        client_apis: &[ClientApi::OpenAiResponses],
312        provider_api: ProviderApi::OpenAiResponses,
313    },
314    CatalogModel {
315        public_id: "gpt-5.5",
316        cloud: Platform::Aws,
317        upstream_id: "openai.gpt-5.5",
318        client_apis: &[ClientApi::OpenAiResponses],
319        provider_api: ProviderApi::OpenAiResponses,
320    },
321    CatalogModel {
322        public_id: "gpt-5.4",
323        cloud: Platform::Aws,
324        upstream_id: "openai.gpt-5.4",
325        client_apis: &[ClientApi::OpenAiResponses],
326        provider_api: ProviderApi::OpenAiResponses,
327    },
328    CatalogModel {
329        public_id: "gpt-oss-20b",
330        cloud: Platform::Aws,
331        upstream_id: "openai.gpt-oss-20b-1:0",
332        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
333        provider_api: ProviderApi::OpenAi,
334    },
335    CatalogModel {
336        public_id: "gpt-oss-120b",
337        cloud: Platform::Aws,
338        upstream_id: "openai.gpt-oss-120b-1:0",
339        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
340        provider_api: ProviderApi::OpenAi,
341    },
342    CatalogModel {
343        public_id: "gpt-oss-safeguard-20b",
344        cloud: Platform::Aws,
345        upstream_id: "openai.gpt-oss-safeguard-20b",
346        client_apis: &[ClientApi::OpenAiChatCompletions],
347        provider_api: ProviderApi::OpenAi,
348    },
349    CatalogModel {
350        public_id: "gpt-oss-safeguard-120b",
351        cloud: Platform::Aws,
352        upstream_id: "openai.gpt-oss-safeguard-120b",
353        client_apis: &[ClientApi::OpenAiChatCompletions],
354        provider_api: ProviderApi::OpenAi,
355    },
356    CatalogModel {
357        public_id: "deepseek-v3.2",
358        cloud: Platform::Aws,
359        upstream_id: "deepseek.v3.2",
360        client_apis: &[ClientApi::OpenAiChatCompletions],
361        provider_api: ProviderApi::OpenAi,
362    },
363    CatalogModel {
364        public_id: "qwen3-32b",
365        cloud: Platform::Aws,
366        upstream_id: "qwen.qwen3-32b-v1:0",
367        client_apis: &[ClientApi::OpenAiChatCompletions],
368        provider_api: ProviderApi::OpenAi,
369    },
370    CatalogModel {
371        public_id: "qwen3-coder-30b",
372        cloud: Platform::Aws,
373        upstream_id: "qwen.qwen3-coder-30b-a3b-v1:0",
374        client_apis: &[ClientApi::OpenAiChatCompletions],
375        provider_api: ProviderApi::OpenAi,
376    },
377    CatalogModel {
378        public_id: "qwen3-next-80b",
379        cloud: Platform::Aws,
380        upstream_id: "qwen.qwen3-next-80b-a3b",
381        client_apis: &[ClientApi::OpenAiChatCompletions],
382        provider_api: ProviderApi::OpenAi,
383    },
384    CatalogModel {
385        public_id: "qwen3-vl-235b",
386        cloud: Platform::Aws,
387        upstream_id: "qwen.qwen3-vl-235b-a22b",
388        client_apis: &[ClientApi::OpenAiChatCompletions],
389        provider_api: ProviderApi::OpenAi,
390    },
391    CatalogModel {
392        public_id: "mistral-large-3",
393        cloud: Platform::Aws,
394        upstream_id: "mistral.mistral-large-3-675b-instruct",
395        client_apis: &[ClientApi::OpenAiChatCompletions],
396        provider_api: ProviderApi::OpenAi,
397    },
398    CatalogModel {
399        public_id: "devstral-2",
400        cloud: Platform::Aws,
401        upstream_id: "mistral.devstral-2-123b",
402        client_apis: &[ClientApi::OpenAiChatCompletions],
403        provider_api: ProviderApi::OpenAi,
404    },
405    CatalogModel {
406        public_id: "magistral-small",
407        cloud: Platform::Aws,
408        upstream_id: "mistral.magistral-small-2509",
409        client_apis: &[ClientApi::OpenAiChatCompletions],
410        provider_api: ProviderApi::OpenAi,
411    },
412    CatalogModel {
413        public_id: "ministral-3-14b",
414        cloud: Platform::Aws,
415        upstream_id: "mistral.ministral-3-14b-instruct",
416        client_apis: &[ClientApi::OpenAiChatCompletions],
417        provider_api: ProviderApi::OpenAi,
418    },
419    CatalogModel {
420        public_id: "ministral-3-8b",
421        cloud: Platform::Aws,
422        upstream_id: "mistral.ministral-3-8b-instruct",
423        client_apis: &[ClientApi::OpenAiChatCompletions],
424        provider_api: ProviderApi::OpenAi,
425    },
426    CatalogModel {
427        public_id: "ministral-3-3b",
428        cloud: Platform::Aws,
429        upstream_id: "mistral.ministral-3-3b-instruct",
430        client_apis: &[ClientApi::OpenAiChatCompletions],
431        provider_api: ProviderApi::OpenAi,
432    },
433    CatalogModel {
434        public_id: "minimax-m2",
435        cloud: Platform::Aws,
436        upstream_id: "minimax.minimax-m2",
437        client_apis: &[ClientApi::OpenAiChatCompletions],
438        provider_api: ProviderApi::OpenAi,
439    },
440    CatalogModel {
441        public_id: "minimax-m2.1",
442        cloud: Platform::Aws,
443        upstream_id: "minimax.minimax-m2.1",
444        client_apis: &[ClientApi::OpenAiChatCompletions],
445        provider_api: ProviderApi::OpenAi,
446    },
447    CatalogModel {
448        public_id: "minimax-m2.5",
449        cloud: Platform::Aws,
450        upstream_id: "minimax.minimax-m2.5",
451        client_apis: &[ClientApi::OpenAiChatCompletions],
452        provider_api: ProviderApi::OpenAi,
453    },
454    CatalogModel {
455        public_id: "kimi-k2.5",
456        cloud: Platform::Aws,
457        upstream_id: "moonshotai.kimi-k2.5",
458        client_apis: &[ClientApi::OpenAiChatCompletions],
459        provider_api: ProviderApi::OpenAi,
460    },
461    CatalogModel {
462        public_id: "nemotron-nano-9b",
463        cloud: Platform::Aws,
464        upstream_id: "nvidia.nemotron-nano-9b-v2",
465        client_apis: &[ClientApi::OpenAiChatCompletions],
466        provider_api: ProviderApi::OpenAi,
467    },
468    CatalogModel {
469        public_id: "nemotron-nano-12b",
470        cloud: Platform::Aws,
471        upstream_id: "nvidia.nemotron-nano-12b-v2",
472        client_apis: &[ClientApi::OpenAiChatCompletions],
473        provider_api: ProviderApi::OpenAi,
474    },
475    CatalogModel {
476        public_id: "nemotron-nano-3-30b",
477        cloud: Platform::Aws,
478        upstream_id: "nvidia.nemotron-nano-3-30b",
479        client_apis: &[ClientApi::OpenAiChatCompletions],
480        provider_api: ProviderApi::OpenAi,
481    },
482    CatalogModel {
483        public_id: "nemotron-super-3-120b",
484        cloud: Platform::Aws,
485        upstream_id: "nvidia.nemotron-super-3-120b",
486        client_apis: &[ClientApi::OpenAiChatCompletions],
487        provider_api: ProviderApi::OpenAi,
488    },
489    CatalogModel {
490        public_id: "gemma-3-4b",
491        cloud: Platform::Aws,
492        upstream_id: "google.gemma-3-4b-it",
493        client_apis: &[ClientApi::OpenAiChatCompletions],
494        provider_api: ProviderApi::OpenAi,
495    },
496    CatalogModel {
497        public_id: "gemma-3-12b",
498        cloud: Platform::Aws,
499        upstream_id: "google.gemma-3-12b-it",
500        client_apis: &[ClientApi::OpenAiChatCompletions],
501        provider_api: ProviderApi::OpenAi,
502    },
503    CatalogModel {
504        public_id: "gemma-3-27b",
505        cloud: Platform::Aws,
506        upstream_id: "google.gemma-3-27b-it",
507        client_apis: &[ClientApi::OpenAiChatCompletions],
508        provider_api: ProviderApi::OpenAi,
509    },
510    CatalogModel {
511        public_id: "glm-4.7",
512        cloud: Platform::Aws,
513        upstream_id: "zai.glm-4.7",
514        client_apis: &[ClientApi::OpenAiChatCompletions],
515        provider_api: ProviderApi::OpenAi,
516    },
517    CatalogModel {
518        public_id: "glm-4.7-flash",
519        cloud: Platform::Aws,
520        upstream_id: "zai.glm-4.7-flash",
521        client_apis: &[ClientApi::OpenAiChatCompletions],
522        provider_api: ProviderApi::OpenAi,
523    },
524    CatalogModel {
525        public_id: "glm-5",
526        cloud: Platform::Aws,
527        upstream_id: "zai.glm-5",
528        client_apis: &[ClientApi::OpenAiChatCompletions],
529        provider_api: ProviderApi::OpenAi,
530    },
531    CatalogModel {
532        public_id: "palmyra-vision-7b",
533        cloud: Platform::Aws,
534        upstream_id: "writer.palmyra-vision-7b",
535        client_apis: &[ClientApi::OpenAiChatCompletions],
536        provider_api: ProviderApi::OpenAi,
537    },
538    // AWS Bedrock, Claude over classic InvokeModel (the Anthropic Messages body is
539    // the InvokeModel body; the model travels in the URL). `upstream_id` is the plain
540    // Bedrock model id; the gateway prepends the region's cross-region inference-profile
541    // geo prefix (`us.`/`eu.`/`apac.`) at request time, since Claude is invocable only
542    // through a profile. Dated ids (`…-<date>-v1:0`) are required where AWS has no short
543    // alias. These need Claude model access granted on the deployment's account.
544    CatalogModel {
545        public_id: "claude-opus-5",
546        cloud: Platform::Aws,
547        upstream_id: "anthropic.claude-opus-5",
548        client_apis: &[ClientApi::AnthropicMessages],
549        provider_api: ProviderApi::Anthropic,
550    },
551    CatalogModel {
552        public_id: "claude-sonnet-5",
553        cloud: Platform::Aws,
554        upstream_id: "anthropic.claude-sonnet-5",
555        client_apis: &[ClientApi::AnthropicMessages],
556        provider_api: ProviderApi::Anthropic,
557    },
558    CatalogModel {
559        public_id: "claude-opus-4.8",
560        cloud: Platform::Aws,
561        upstream_id: "anthropic.claude-opus-4-8",
562        client_apis: &[ClientApi::AnthropicMessages],
563        provider_api: ProviderApi::Anthropic,
564    },
565    CatalogModel {
566        public_id: "claude-opus-4.7",
567        cloud: Platform::Aws,
568        upstream_id: "anthropic.claude-opus-4-7",
569        client_apis: &[ClientApi::AnthropicMessages],
570        provider_api: ProviderApi::Anthropic,
571    },
572    CatalogModel {
573        public_id: "claude-opus-4.6",
574        cloud: Platform::Aws,
575        upstream_id: "anthropic.claude-opus-4-6-v1",
576        client_apis: &[ClientApi::AnthropicMessages],
577        provider_api: ProviderApi::Anthropic,
578    },
579    CatalogModel {
580        public_id: "claude-opus-4.5",
581        cloud: Platform::Aws,
582        upstream_id: "anthropic.claude-opus-4-5-20251101-v1:0",
583        client_apis: &[ClientApi::AnthropicMessages],
584        provider_api: ProviderApi::Anthropic,
585    },
586    CatalogModel {
587        public_id: "claude-sonnet-4.6",
588        cloud: Platform::Aws,
589        upstream_id: "anthropic.claude-sonnet-4-6",
590        client_apis: &[ClientApi::AnthropicMessages],
591        provider_api: ProviderApi::Anthropic,
592    },
593    CatalogModel {
594        public_id: "claude-sonnet-4.5",
595        cloud: Platform::Aws,
596        upstream_id: "anthropic.claude-sonnet-4-5-20250929-v1:0",
597        client_apis: &[ClientApi::AnthropicMessages],
598        provider_api: ProviderApi::Anthropic,
599    },
600    CatalogModel {
601        public_id: "claude-haiku-4.5",
602        cloud: Platform::Aws,
603        upstream_id: "anthropic.claude-haiku-4-5-20251001-v1:0",
604        client_apis: &[ClientApi::AnthropicMessages],
605        provider_api: ProviderApi::Anthropic,
606    },
607    CatalogModel {
608        public_id: "claude-fable-5",
609        cloud: Platform::Aws,
610        upstream_id: "anthropic.claude-fable-5",
611        client_apis: &[ClientApi::AnthropicMessages],
612        provider_api: ProviderApi::Anthropic,
613    },
614    // GCP Vertex, Gemini. The OpenAI-compatible Vertex endpoint expects the `google/` prefix.
615    // The 2.5 family serves in-region; the 3.x models serve on the `global` location.
616    CatalogModel {
617        public_id: "gemini-2.5-pro",
618        cloud: Platform::Gcp,
619        upstream_id: "google/gemini-2.5-pro",
620        client_apis: &[ClientApi::OpenAiChatCompletions],
621        provider_api: ProviderApi::OpenAi,
622    },
623    CatalogModel {
624        public_id: "gemini-2.5-flash",
625        cloud: Platform::Gcp,
626        upstream_id: "google/gemini-2.5-flash",
627        client_apis: &[ClientApi::OpenAiChatCompletions],
628        provider_api: ProviderApi::OpenAi,
629    },
630    CatalogModel {
631        public_id: "gemini-2.5-flash-lite",
632        cloud: Platform::Gcp,
633        upstream_id: "google/gemini-2.5-flash-lite",
634        client_apis: &[ClientApi::OpenAiChatCompletions],
635        provider_api: ProviderApi::OpenAi,
636    },
637    CatalogModel {
638        public_id: "gemini-3.5-flash",
639        cloud: Platform::Gcp,
640        upstream_id: "google/gemini-3.5-flash",
641        client_apis: &[ClientApi::OpenAiChatCompletions],
642        provider_api: ProviderApi::OpenAi,
643    },
644    CatalogModel {
645        public_id: "gemini-3.1-flash-lite",
646        cloud: Platform::Gcp,
647        upstream_id: "google/gemini-3.1-flash-lite",
648        client_apis: &[ClientApi::OpenAiChatCompletions],
649        provider_api: ProviderApi::OpenAi,
650    },
651    // GCP Vertex, Claude. The upstream id is the Vertex Model Garden id that travels
652    // in the `:rawPredict` URL path (`publishers/anthropic/models/<id>`); models past
653    // Sonnet 4.5 carry no date suffix, older ones keep an `@<date>` version. Needs
654    // Claude model access granted on the deployment's project.
655    CatalogModel {
656        public_id: "claude-opus-5",
657        cloud: Platform::Gcp,
658        upstream_id: "claude-opus-5",
659        client_apis: &[ClientApi::AnthropicMessages],
660        provider_api: ProviderApi::Anthropic,
661    },
662    CatalogModel {
663        public_id: "claude-sonnet-5",
664        cloud: Platform::Gcp,
665        upstream_id: "claude-sonnet-5",
666        client_apis: &[ClientApi::AnthropicMessages],
667        provider_api: ProviderApi::Anthropic,
668    },
669    CatalogModel {
670        public_id: "claude-opus-4.8",
671        cloud: Platform::Gcp,
672        upstream_id: "claude-opus-4-8",
673        client_apis: &[ClientApi::AnthropicMessages],
674        provider_api: ProviderApi::Anthropic,
675    },
676    CatalogModel {
677        public_id: "claude-opus-4.7",
678        cloud: Platform::Gcp,
679        upstream_id: "claude-opus-4-7",
680        client_apis: &[ClientApi::AnthropicMessages],
681        provider_api: ProviderApi::Anthropic,
682    },
683    CatalogModel {
684        public_id: "claude-opus-4.6",
685        cloud: Platform::Gcp,
686        upstream_id: "claude-opus-4-6",
687        client_apis: &[ClientApi::AnthropicMessages],
688        provider_api: ProviderApi::Anthropic,
689    },
690    CatalogModel {
691        public_id: "claude-opus-4.5",
692        cloud: Platform::Gcp,
693        upstream_id: "claude-opus-4-5@20251101",
694        client_apis: &[ClientApi::AnthropicMessages],
695        provider_api: ProviderApi::Anthropic,
696    },
697    CatalogModel {
698        public_id: "claude-sonnet-4.6",
699        cloud: Platform::Gcp,
700        upstream_id: "claude-sonnet-4-6",
701        client_apis: &[ClientApi::AnthropicMessages],
702        provider_api: ProviderApi::Anthropic,
703    },
704    CatalogModel {
705        public_id: "claude-sonnet-4.5",
706        cloud: Platform::Gcp,
707        upstream_id: "claude-sonnet-4-5@20250929",
708        client_apis: &[ClientApi::AnthropicMessages],
709        provider_api: ProviderApi::Anthropic,
710    },
711    CatalogModel {
712        public_id: "claude-haiku-4.5",
713        cloud: Platform::Gcp,
714        upstream_id: "claude-haiku-4-5@20251001",
715        client_apis: &[ClientApi::AnthropicMessages],
716        provider_api: ProviderApi::Anthropic,
717    },
718    CatalogModel {
719        public_id: "claude-fable-5",
720        cloud: Platform::Gcp,
721        upstream_id: "claude-fable-5",
722        client_apis: &[ClientApi::AnthropicMessages],
723        provider_api: ProviderApi::Anthropic,
724    },
725    // Azure, OpenAI-protocol. The upstream id is the deployment name the controller
726    // creates (see AZURE_DEPLOYMENTS); the app requests it by the same id. Azure serves
727    // only what is deployed, so this list must stay in sync with AZURE_DEPLOYMENTS.
728    CatalogModel {
729        public_id: "gpt-4.1",
730        cloud: Platform::Azure,
731        upstream_id: "gpt-4.1",
732        client_apis: &[ClientApi::OpenAiChatCompletions],
733        provider_api: ProviderApi::OpenAi,
734    },
735    CatalogModel {
736        public_id: "gpt-4o-mini",
737        cloud: Platform::Azure,
738        upstream_id: "gpt-4o-mini",
739        client_apis: &[ClientApi::OpenAiChatCompletions],
740        provider_api: ProviderApi::OpenAi,
741    },
742    CatalogModel {
743        public_id: "model-router",
744        cloud: Platform::Azure,
745        upstream_id: "model-router",
746        client_apis: &[ClientApi::OpenAiChatCompletions],
747        provider_api: ProviderApi::OpenAi,
748    },
749    // Azure, GPT-5 family. Foundry serves these on Responses (also Chat Completions,
750    // but the gateway only advertises the Responses path, which carries `web_search`).
751    CatalogModel {
752        public_id: "gpt-5.5",
753        cloud: Platform::Azure,
754        upstream_id: "gpt-5.5",
755        client_apis: &[ClientApi::OpenAiResponses],
756        provider_api: ProviderApi::OpenAiResponses,
757    },
758    CatalogModel {
759        public_id: "gpt-5.6-sol",
760        cloud: Platform::Azure,
761        upstream_id: "gpt-5.6-sol",
762        client_apis: &[ClientApi::OpenAiResponses],
763        provider_api: ProviderApi::OpenAiResponses,
764    },
765    // Azure, Claude over the Foundry Anthropic endpoint. The upstream id is the
766    // Foundry deployment name (defaults to the model id). Unlike the OpenAI list,
767    // these are not in AZURE_DEPLOYMENTS: a first Claude deployment requires
768    // accepting Azure Marketplace terms, a portal step the controller cannot
769    // perform, so Claude deployments are created in the Foundry portal. These stay
770    // in the catalog as the deployment-name mapping. The resource heartbeat lists
771    // actual deployments, so the gateway omits Claude until that deployment exists.
772    CatalogModel {
773        public_id: "claude-opus-5",
774        cloud: Platform::Azure,
775        upstream_id: "claude-opus-5",
776        client_apis: &[ClientApi::AnthropicMessages],
777        provider_api: ProviderApi::Anthropic,
778    },
779    CatalogModel {
780        public_id: "claude-sonnet-5",
781        cloud: Platform::Azure,
782        upstream_id: "claude-sonnet-5",
783        client_apis: &[ClientApi::AnthropicMessages],
784        provider_api: ProviderApi::Anthropic,
785    },
786    CatalogModel {
787        public_id: "claude-opus-4.8",
788        cloud: Platform::Azure,
789        upstream_id: "claude-opus-4-8",
790        client_apis: &[ClientApi::AnthropicMessages],
791        provider_api: ProviderApi::Anthropic,
792    },
793    CatalogModel {
794        public_id: "claude-opus-4.7",
795        cloud: Platform::Azure,
796        upstream_id: "claude-opus-4-7",
797        client_apis: &[ClientApi::AnthropicMessages],
798        provider_api: ProviderApi::Anthropic,
799    },
800    CatalogModel {
801        public_id: "claude-opus-4.6",
802        cloud: Platform::Azure,
803        upstream_id: "claude-opus-4-6",
804        client_apis: &[ClientApi::AnthropicMessages],
805        provider_api: ProviderApi::Anthropic,
806    },
807    CatalogModel {
808        public_id: "claude-opus-4.5",
809        cloud: Platform::Azure,
810        upstream_id: "claude-opus-4-5",
811        client_apis: &[ClientApi::AnthropicMessages],
812        provider_api: ProviderApi::Anthropic,
813    },
814    CatalogModel {
815        public_id: "claude-sonnet-4.6",
816        cloud: Platform::Azure,
817        upstream_id: "claude-sonnet-4-6",
818        client_apis: &[ClientApi::AnthropicMessages],
819        provider_api: ProviderApi::Anthropic,
820    },
821    CatalogModel {
822        public_id: "claude-sonnet-4.5",
823        cloud: Platform::Azure,
824        upstream_id: "claude-sonnet-4-5",
825        client_apis: &[ClientApi::AnthropicMessages],
826        provider_api: ProviderApi::Anthropic,
827    },
828    CatalogModel {
829        public_id: "claude-haiku-4.5",
830        cloud: Platform::Azure,
831        upstream_id: "claude-haiku-4-5",
832        client_apis: &[ClientApi::AnthropicMessages],
833        provider_api: ProviderApi::Anthropic,
834    },
835    CatalogModel {
836        public_id: "claude-fable-5",
837        cloud: Platform::Azure,
838        upstream_id: "claude-fable-5",
839        client_apis: &[ClientApi::AnthropicMessages],
840        provider_api: ProviderApi::Anthropic,
841    },
842];
843
844/// Changes whenever public model ids or their supported client APIs change.
845/// Heartbeat consumers use this to distinguish an old observation from a
846/// current catalog without duplicating the catalog in durable state.
847pub const AI_CATALOG_REVISION: &str = "2026-08-20.1";
848
849/// Azure deployments to create at provision time: (deployment name, model name,
850/// model version). The deployment name is the catalog `upstream_id`. The version
851/// is validated against the target region's model catalog at deploy time.
852///
853/// Each entry is (deployment name, model name, model version, capacity in
854/// thousands of tokens per minute). Every deployment asks for 50, enough for chat
855/// and document indexing; one unit allows about one request a minute. The Azure
856/// controller lowers a deployment to the subscription's free quota when that is lower.
857static AZURE_DEPLOYMENTS: &[(&str, &str, &str, i32)] = &[
858    ("gpt-4.1", "gpt-4.1", "2025-04-14", 50),
859    ("model-router", "model-router", "2025-11-18", 50),
860    ("gpt-5.5", "gpt-5.5", "2026-04-24", 50),
861    ("gpt-5.6-sol", "gpt-5.6-sol", "2026-07-09", 50),
862    ("text-embedding-3-large", "text-embedding-3-large", "1", 50),
863];
864
865/// One embeddings model. Embeddings are not text generation, so they stay out of
866/// [`CatalogModel`] and its client-API lists: the gateway serves them only on
867/// `POST /<name>/v1/embeddings`, and the model listing does not include them.
868#[derive(Debug, Clone, Copy)]
869pub struct EmbeddingModel {
870    pub public_id: &'static str,
871    pub cloud: Platform,
872    /// For Azure, the deployment name the controller creates (see `AZURE_DEPLOYMENTS`).
873    pub upstream_id: &'static str,
874}
875
876static EMBEDDING_MODELS: &[EmbeddingModel] = &[
877    EmbeddingModel {
878        public_id: "text-embedding-3-large",
879        cloud: Platform::Azure,
880        upstream_id: "text-embedding-3-large",
881    },
882    // Vertex's publisher model, 3072 dimensions by default like `text-embedding-3-large`, and a
883    // client's `dimensions` narrows it. Served through `:predict`, one input per upstream call.
884    EmbeddingModel {
885        public_id: "gemini-embedding-001",
886        cloud: Platform::Gcp,
887        upstream_id: "gemini-embedding-001",
888    },
889];
890
891/// The embeddings model a client-sent id names on `cloud`, or `None`.
892pub fn resolve_embedding_for(model_id: &str, cloud: Platform) -> Option<&'static EmbeddingModel> {
893    EMBEDDING_MODELS
894        .iter()
895        .find(|m| m.cloud == cloud && m.public_id == model_id)
896}
897
898/// Direct Anthropic aliases qualified for the native Messages API. Keep this
899/// explicit: the three cloud providers use different upstream IDs and cannot be
900/// used as an accidental source of direct-provider routing data.
901static DIRECT_ANTHROPIC_MODELS: &[DirectAnthropicModel] = &[
902    DirectAnthropicModel {
903        public_id: "claude-opus-5",
904        upstream_id: "claude-opus-5",
905    },
906    DirectAnthropicModel {
907        public_id: "claude-sonnet-5",
908        upstream_id: "claude-sonnet-5",
909    },
910    DirectAnthropicModel {
911        public_id: "claude-opus-4.8",
912        upstream_id: "claude-opus-4-8",
913    },
914    DirectAnthropicModel {
915        public_id: "claude-opus-4.7",
916        upstream_id: "claude-opus-4-7",
917    },
918    DirectAnthropicModel {
919        public_id: "claude-opus-4.6",
920        upstream_id: "claude-opus-4-6",
921    },
922    DirectAnthropicModel {
923        public_id: "claude-opus-4.5",
924        upstream_id: "claude-opus-4-5",
925    },
926    DirectAnthropicModel {
927        public_id: "claude-sonnet-4.6",
928        upstream_id: "claude-sonnet-4-6",
929    },
930    DirectAnthropicModel {
931        public_id: "claude-sonnet-4.5",
932        upstream_id: "claude-sonnet-4-5-20250929",
933    },
934    DirectAnthropicModel {
935        public_id: "claude-haiku-4.5",
936        upstream_id: "claude-haiku-4-5-20251001",
937    },
938    DirectAnthropicModel {
939        public_id: "claude-fable-5",
940        upstream_id: "claude-fable-5",
941    },
942];
943
944/// Direct OpenAI models qualified end to end through the Gateway.
945///
946/// Add a model only after exercising every client API listed for it against a
947/// real provider account. Provider discovery is then used as the account-level
948/// availability filter; discovery alone is not sufficient to expose a model.
949///
950/// Every entry below was exercised live (2026-08-09) against both
951/// `/v1/chat/completions` and `/v1/responses`. Note the GPT-5 family answers
952/// both APIs here, unlike on bedrock-mantle where it is Responses-only.
953static DIRECT_OPENAI_MODELS: &[DirectOpenAiModel] = &[
954    DirectOpenAiModel {
955        public_id: "gpt-5.6-sol",
956        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
957    },
958    DirectOpenAiModel {
959        public_id: "gpt-5.6-terra",
960        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
961    },
962    DirectOpenAiModel {
963        public_id: "gpt-5.6-luna",
964        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
965    },
966    DirectOpenAiModel {
967        public_id: "gpt-5.5",
968        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
969    },
970    DirectOpenAiModel {
971        public_id: "gpt-5.4",
972        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
973    },
974    DirectOpenAiModel {
975        public_id: "gpt-4.1",
976        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
977    },
978    DirectOpenAiModel {
979        public_id: "gpt-4.1-mini",
980        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
981    },
982    DirectOpenAiModel {
983        public_id: "gpt-4o-mini",
984        client_apis: &[ClientApi::OpenAiChatCompletions, ClientApi::OpenAiResponses],
985    },
986];
987
988/// Generally available Databricks-hosted text-generation models that have an
989/// exact Alien public-model ID, reviewed against Databricks' supported-models
990/// catalog on 2026-08-10. Preview, deprecated, embedding, and image-generation
991/// models are intentionally excluded. Credential verification is separate from
992/// model access: Databricks can accept OAuth while a service is disabled by quota.
993/// Source: <https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/supported-models>
994static DIRECT_DATABRICKS_MODELS: &[DirectDatabricksModel] = &[
995    DirectDatabricksModel {
996        public_id: "gpt-5.6-sol",
997        upstream: DirectDatabricksUpstream::ServingEndpointChat {
998            endpoint: "databricks-gpt-5-6-sol",
999        },
1000    },
1001    DirectDatabricksModel {
1002        public_id: "gpt-5.6-terra",
1003        upstream: DirectDatabricksUpstream::ServingEndpointChat {
1004            endpoint: "databricks-gpt-5-6-terra",
1005        },
1006    },
1007    DirectDatabricksModel {
1008        public_id: "gpt-5.6-luna",
1009        upstream: DirectDatabricksUpstream::ServingEndpointChat {
1010            endpoint: "databricks-gpt-5-6-luna",
1011        },
1012    },
1013    DirectDatabricksModel {
1014        public_id: "gpt-5.5",
1015        upstream: DirectDatabricksUpstream::ServingEndpointChat {
1016            endpoint: "databricks-gpt-5-5",
1017        },
1018    },
1019    DirectDatabricksModel {
1020        public_id: "gpt-5.4",
1021        upstream: DirectDatabricksUpstream::ServingEndpointChat {
1022            endpoint: "databricks-gpt-5-4",
1023        },
1024    },
1025    DirectDatabricksModel {
1026        public_id: "claude-haiku-4.5",
1027        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1028            service: "system.ai.claude-haiku-4-5",
1029        },
1030    },
1031    DirectDatabricksModel {
1032        public_id: "claude-opus-5",
1033        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1034            service: "system.ai.claude-opus-5",
1035        },
1036    },
1037    DirectDatabricksModel {
1038        public_id: "claude-sonnet-5",
1039        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1040            service: "system.ai.claude-sonnet-5",
1041        },
1042    },
1043    DirectDatabricksModel {
1044        public_id: "claude-sonnet-4.6",
1045        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1046            service: "system.ai.claude-sonnet-4-6",
1047        },
1048    },
1049    DirectDatabricksModel {
1050        public_id: "claude-sonnet-4.5",
1051        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1052            service: "system.ai.claude-sonnet-4-5",
1053        },
1054    },
1055    DirectDatabricksModel {
1056        public_id: "claude-fable-5",
1057        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1058            service: "system.ai.claude-fable-5",
1059        },
1060    },
1061    DirectDatabricksModel {
1062        public_id: "claude-opus-4.8",
1063        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1064            service: "system.ai.claude-opus-4-8",
1065        },
1066    },
1067    DirectDatabricksModel {
1068        public_id: "claude-opus-4.7",
1069        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1070            service: "system.ai.claude-opus-4-7",
1071        },
1072    },
1073    DirectDatabricksModel {
1074        public_id: "claude-opus-4.6",
1075        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1076            service: "system.ai.claude-opus-4-6",
1077        },
1078    },
1079    DirectDatabricksModel {
1080        public_id: "claude-opus-4.5",
1081        upstream: DirectDatabricksUpstream::ModelServiceMessages {
1082            service: "system.ai.claude-opus-4-5",
1083        },
1084    },
1085    DirectDatabricksModel {
1086        public_id: "gemini-3.5-flash",
1087        upstream: DirectDatabricksUpstream::ModelServiceChat {
1088            service: "system.ai.gemini-3-5-flash",
1089        },
1090    },
1091    DirectDatabricksModel {
1092        public_id: "gemini-3.1-flash-lite",
1093        upstream: DirectDatabricksUpstream::ModelServiceChat {
1094            service: "system.ai.gemini-3-1-flash-lite",
1095        },
1096    },
1097    DirectDatabricksModel {
1098        public_id: "gpt-oss-120b",
1099        upstream: DirectDatabricksUpstream::ServingEndpointChat {
1100            endpoint: "databricks-gpt-oss-120b",
1101        },
1102    },
1103    DirectDatabricksModel {
1104        public_id: "gpt-oss-20b",
1105        upstream: DirectDatabricksUpstream::ServingEndpointChat {
1106            endpoint: "databricks-gpt-oss-20b",
1107        },
1108    },
1109    DirectDatabricksModel {
1110        public_id: "gemma-3-12b",
1111        upstream: DirectDatabricksUpstream::ModelServiceChat {
1112            service: "system.ai.gemma-3-12b",
1113        },
1114    },
1115];
1116
1117/// Where a model sits on the bedrock-mantle Responses API.
1118#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1119pub struct ResponsesTarget {
1120    /// The id mantle expects, which drops the InvokeModel version suffix.
1121    pub upstream_id: &'static str,
1122    /// Path under the mantle host. The GPT-5 family serves on `/openai/v1/responses`,
1123    /// the open-weight models on `/v1/responses`.
1124    pub path: &'static str,
1125}
1126
1127/// AWS models servable over the bedrock-mantle OpenAI Responses API. Only a subset
1128/// of the chat catalog supports Responses at all — Claude is Messages-only and e.g.
1129/// Qwen rejects it. Kept explicit rather than derived: both the id scheme and the
1130/// path differ per model family, not by a rule.
1131static RESPONSES_UPSTREAM: &[(&str, ResponsesTarget)] = &[
1132    (
1133        "gpt-oss-20b",
1134        ResponsesTarget {
1135            upstream_id: "openai.gpt-oss-20b",
1136            path: "/v1/responses",
1137        },
1138    ),
1139    (
1140        "gpt-oss-120b",
1141        ResponsesTarget {
1142            upstream_id: "openai.gpt-oss-120b",
1143            path: "/v1/responses",
1144        },
1145    ),
1146    (
1147        "gpt-5.6-sol",
1148        ResponsesTarget {
1149            upstream_id: "openai.gpt-5.6-sol",
1150            path: "/openai/v1/responses",
1151        },
1152    ),
1153    (
1154        "gpt-5.6-terra",
1155        ResponsesTarget {
1156            upstream_id: "openai.gpt-5.6-terra",
1157            path: "/openai/v1/responses",
1158        },
1159    ),
1160    (
1161        "gpt-5.6-luna",
1162        ResponsesTarget {
1163            upstream_id: "openai.gpt-5.6-luna",
1164            path: "/openai/v1/responses",
1165        },
1166    ),
1167    (
1168        "gpt-5.5",
1169        ResponsesTarget {
1170            upstream_id: "openai.gpt-5.5",
1171            path: "/openai/v1/responses",
1172        },
1173    ),
1174    (
1175        "gpt-5.4",
1176        ResponsesTarget {
1177            upstream_id: "openai.gpt-5.4",
1178            path: "/openai/v1/responses",
1179        },
1180    ),
1181];
1182
1183/// The bedrock-mantle Responses target for a public model id, or `None` when the
1184/// model is not servable over the Responses API.
1185pub fn responses_target(public_id: &str) -> Option<ResponsesTarget> {
1186    RESPONSES_UPSTREAM
1187        .iter()
1188        .find(|(public, _)| *public == public_id)
1189        .map(|(_, target)| *target)
1190}
1191
1192pub fn models_for(cloud: Platform) -> Vec<&'static CatalogModel> {
1193    CATALOG.iter().filter(|m| m.cloud == cloud).collect()
1194}
1195
1196pub fn direct_anthropic_models() -> Vec<&'static DirectAnthropicModel> {
1197    DIRECT_ANTHROPIC_MODELS.iter().collect()
1198}
1199
1200pub fn resolve_direct_anthropic(public_id: &str) -> Option<&'static DirectAnthropicModel> {
1201    DIRECT_ANTHROPIC_MODELS
1202        .iter()
1203        .find(|model| model.public_id == public_id)
1204}
1205
1206pub fn direct_openai_models() -> Vec<&'static DirectOpenAiModel> {
1207    DIRECT_OPENAI_MODELS.iter().collect()
1208}
1209
1210pub fn resolve_direct_openai(public_id: &str) -> Option<&'static DirectOpenAiModel> {
1211    DIRECT_OPENAI_MODELS
1212        .iter()
1213        .find(|model| model.public_id == public_id)
1214}
1215
1216pub fn direct_databricks_models() -> Vec<&'static DirectDatabricksModel> {
1217    DIRECT_DATABRICKS_MODELS.iter().collect()
1218}
1219
1220pub fn resolve_direct_databricks(public_id: &str) -> Option<&'static DirectDatabricksModel> {
1221    DIRECT_DATABRICKS_MODELS
1222        .iter()
1223        .find(|model| model.public_id == public_id)
1224}
1225
1226/// The catalog model for a public id, or `None` if it is not exposed.
1227///
1228/// First match: for an id serving on more than one cloud this is the AWS entry;
1229/// cloud-scoped callers use `lookup_for` via `resolve_for`.
1230pub fn lookup(public_id: &str) -> Option<&'static CatalogModel> {
1231    CATALOG.iter().find(|m| m.public_id == public_id)
1232}
1233
1234fn lookup_for(public_id: &str, cloud: Platform) -> Option<&'static CatalogModel> {
1235    CATALOG
1236        .iter()
1237        .find(|m| m.public_id == public_id && m.cloud == cloud)
1238}
1239
1240/// The catalog model for a client-sent model id on a specific cloud. A public id
1241/// can appear once per cloud (Claude serves on more than one), so resolution must
1242/// scope to the binding's cloud rather than filter a first-match lookup — the
1243/// first match is another cloud's entry whenever ids overlap.
1244pub fn resolve_for(model_id: &str, cloud: Platform) -> Option<&'static CatalogModel> {
1245    lookup_for(model_id, cloud).or_else(|| lookup_for(&canonical_public_id(model_id), cloud))
1246}
1247
1248/// The catalog model for a client-sent model id, accepting the Anthropic-native
1249/// spellings agent CLIs actually send alongside the catalog's public ids.
1250///
1251/// Claude Code's `/model` emits ids like `claude-sonnet-4-5-20250929` or
1252/// `claude-haiku-4-5`, Bedrock-aware clients may carry the full upstream id
1253/// (`us.anthropic.claude-haiku-4-5-20251001-v1:0`), and Vertex clients the
1254/// `@date` form (`claude-sonnet-4-5@20250929`). Exact public ids win; otherwise
1255/// the id is canonicalized — vendor/geo prefix, InvokeModel `-vN[:M]` suffix,
1256/// and either release-date suffix drop off, and a dashed minor version becomes
1257/// the catalog's dotted form (`claude-haiku-4-5` → `claude-haiku-4.5`).
1258///
1259/// A public id can appear once per cloud, and this returns the first catalog
1260/// entry — for a multi-cloud id that is the AWS one. Callers routing by a
1261/// binding must use `resolve_for` with the binding's cloud.
1262pub fn resolve(model_id: &str) -> Option<&'static CatalogModel> {
1263    lookup(model_id).or_else(|| lookup(&canonical_public_id(model_id)))
1264}
1265
1266fn canonical_public_id(model_id: &str) -> String {
1267    let mut id = model_id;
1268    if let Some(pos) = id.rfind("anthropic.") {
1269        id = &id[pos + "anthropic.".len()..];
1270    }
1271    // Vertex spells the release date as an `@` suffix rather than a dash.
1272    id = id.split_once('@').map_or(id, |(base, _)| base);
1273    id = strip_invoke_version(id);
1274    id = strip_release_date(id);
1275    dot_minor_version(id)
1276}
1277
1278/// Strip an InvokeModel version suffix: `-v1:0` or `-v1`.
1279fn strip_invoke_version(id: &str) -> &str {
1280    let base = id.split_once(':').map_or(id, |(base, _)| base);
1281    match base.rsplit_once("-v") {
1282        Some((stem, digits))
1283            if !digits.is_empty() && digits.bytes().all(|b| b.is_ascii_digit()) =>
1284        {
1285            stem
1286        }
1287        _ => base,
1288    }
1289}
1290
1291/// Strip a release-date suffix: `-20251001`.
1292fn strip_release_date(id: &str) -> &str {
1293    match id.rsplit_once('-') {
1294        Some((stem, date))
1295            if date.len() == 8
1296                && date.starts_with("20")
1297                && date.bytes().all(|b| b.is_ascii_digit()) =>
1298        {
1299            stem
1300        }
1301        _ => id,
1302    }
1303}
1304
1305/// Rewrite a trailing dashed minor version to the catalog's dotted form:
1306/// `claude-haiku-4-5` → `claude-haiku-4.5`. Whole versions (`claude-sonnet-5`)
1307/// are already in catalog form and pass through.
1308fn dot_minor_version(id: &str) -> String {
1309    let Some((stem, minor)) = id.rsplit_once('-') else {
1310        return id.to_string();
1311    };
1312    let Some((prefix, major)) = stem.rsplit_once('-') else {
1313        return id.to_string();
1314    };
1315    let both_numeric = !major.is_empty()
1316        && !minor.is_empty()
1317        && major.bytes().all(|b| b.is_ascii_digit())
1318        && minor.bytes().all(|b| b.is_ascii_digit());
1319    if both_numeric {
1320        format!("{prefix}-{major}.{minor}")
1321    } else {
1322        id.to_string()
1323    }
1324}
1325
1326/// The Azure predefined model deployments, as (deployment name, model name, version).
1327pub fn azure_deployments() -> Vec<(&'static str, &'static str, &'static str, i32)> {
1328    AZURE_DEPLOYMENTS.to_vec()
1329}
1330
1331#[cfg(test)]
1332mod tests {
1333    #[test]
1334    fn bedrock_geo_routes_non_us_regions_via_global() {
1335        assert_eq!(bedrock_geo("us-east-2"), "us");
1336        assert_eq!(bedrock_geo("us-west-2"), "us");
1337        assert_eq!(bedrock_geo("us-gov-west-1"), "us-gov");
1338        assert_eq!(bedrock_geo("eu-west-1"), "global");
1339        assert_eq!(bedrock_geo("ap-southeast-2"), "global");
1340        assert_eq!(bedrock_geo("ca-central-1"), "global");
1341        assert_eq!(bedrock_geo("sa-east-1"), "global");
1342        assert_eq!(bedrock_geo("mx-central-1"), "global");
1343    }
1344
1345    #[test]
1346    fn inference_profile_id_prefixes_the_regions_geo() {
1347        assert_eq!(
1348            bedrock_inference_profile_id("us-west-2", "anthropic.claude-sonnet-5"),
1349            "us.anthropic.claude-sonnet-5"
1350        );
1351        assert_eq!(
1352            bedrock_inference_profile_id("eu-west-1", "anthropic.claude-sonnet-5"),
1353            "global.anthropic.claude-sonnet-5"
1354        );
1355    }
1356
1357    /// A public id may serve on more than one cloud (Claude does), but must appear at
1358    /// most once per cloud — a duplicate within a cloud would make `resolve_for`
1359    /// silently pick whichever entry comes first.
1360    #[test]
1361    fn public_ids_are_unique_per_cloud() {
1362        let mut seen = std::collections::HashSet::new();
1363        for model in super::CATALOG {
1364            assert!(
1365                seen.insert((model.cloud, model.public_id)),
1366                "public id '{}' appears more than once under {:?}",
1367                model.public_id,
1368                model.cloud
1369            );
1370        }
1371    }
1372
1373    #[test]
1374    fn direct_anthropic_aliases_are_unique_and_round_trip() {
1375        let mut public_ids = std::collections::HashSet::new();
1376        let mut upstream_ids = std::collections::HashSet::new();
1377        for model in DIRECT_ANTHROPIC_MODELS {
1378            assert!(public_ids.insert(model.public_id));
1379            assert!(upstream_ids.insert(model.upstream_id));
1380            assert_eq!(
1381                resolve_direct_anthropic(model.public_id)
1382                    .expect("direct model must resolve")
1383                    .upstream_id,
1384                model.upstream_id
1385            );
1386            assert_ne!(model.display_name(), model.public_id);
1387        }
1388        assert!(resolve_direct_anthropic("claude-not-real").is_none());
1389    }
1390
1391    #[test]
1392    fn direct_openai_models_are_unique_and_have_qualified_apis() {
1393        let mut public_ids = std::collections::HashSet::new();
1394        for model in DIRECT_OPENAI_MODELS {
1395            assert!(public_ids.insert(model.public_id));
1396            assert!(!model.client_apis.is_empty());
1397            assert_eq!(
1398                resolve_direct_openai(model.public_id)
1399                    .expect("direct model must resolve")
1400                    .client_apis,
1401                model.client_apis
1402            );
1403        }
1404        assert!(resolve_direct_openai("text-embedding-3-small").is_none());
1405        assert!(resolve_direct_openai("gpt-image-1").is_none());
1406    }
1407
1408    #[test]
1409    fn direct_databricks_models_are_unique_and_resolve_to_provider_ids() {
1410        let mut public_ids = std::collections::HashSet::new();
1411        for model in DIRECT_DATABRICKS_MODELS {
1412            assert!(public_ids.insert(model.public_id));
1413            let upstream_id = model.upstream.model_id();
1414            assert!(
1415                upstream_id.starts_with("databricks-") || upstream_id.starts_with("system.ai.")
1416            );
1417            assert_eq!(
1418                resolve_direct_databricks(model.public_id)
1419                    .expect("direct Databricks model must resolve")
1420                    .upstream,
1421                model.upstream
1422            );
1423        }
1424        assert!(resolve_direct_databricks("bge-large-en").is_none());
1425        assert!(resolve_direct_databricks("databricks-genie").is_none());
1426        assert_eq!(
1427            resolve_direct_databricks("claude-opus-5")
1428                .expect("Claude Opus 5 must resolve")
1429                .upstream
1430                .model_id(),
1431            "system.ai.claude-opus-5"
1432        );
1433        assert_eq!(
1434            resolve_direct_databricks("gpt-oss-120b")
1435                .expect("GPT-OSS 120B must resolve")
1436                .upstream,
1437            DirectDatabricksUpstream::ServingEndpointChat {
1438                endpoint: "databricks-gpt-oss-120b"
1439            }
1440        );
1441    }
1442
1443    use super::*;
1444
1445    #[test]
1446    fn resolve_accepts_anthropic_native_spellings() {
1447        // Claude Code /model forms: dashed minor version, with and without date.
1448        assert_eq!(
1449            resolve("claude-haiku-4-5").unwrap().public_id,
1450            "claude-haiku-4.5"
1451        );
1452        assert_eq!(
1453            resolve("claude-sonnet-4-5-20250929").unwrap().public_id,
1454            "claude-sonnet-4.5"
1455        );
1456        // Full Bedrock upstream ids, with geo/vendor prefix and version suffix.
1457        assert_eq!(
1458            resolve("us.anthropic.claude-haiku-4-5-20251001-v1:0")
1459                .unwrap()
1460                .public_id,
1461            "claude-haiku-4.5"
1462        );
1463        assert_eq!(
1464            resolve("anthropic.claude-opus-4-6-v1").unwrap().public_id,
1465            "claude-opus-4.6"
1466        );
1467        // Whole versions are already catalog form.
1468        assert_eq!(
1469            resolve("claude-sonnet-5").unwrap().public_id,
1470            "claude-sonnet-5"
1471        );
1472        // Exact public ids still win untouched.
1473        assert_eq!(
1474            resolve("claude-opus-4.8").unwrap().public_id,
1475            "claude-opus-4.8"
1476        );
1477        assert_eq!(resolve("gpt-oss-20b").unwrap().public_id, "gpt-oss-20b");
1478        // Unknowns stay unknown — no fuzzy matching.
1479        assert!(resolve("claude-nonexistent-9-9").is_none());
1480        assert!(resolve("gpt-5").is_none());
1481    }
1482
1483    #[test]
1484    fn aws_has_openai_and_anthropic_with_plain_ids() {
1485        let aws = models_for(Platform::Aws);
1486        assert!(!aws.is_empty());
1487        assert!(aws
1488            .iter()
1489            .any(|m| m.public_id == "gpt-oss-20b" && m.provider_api == ProviderApi::OpenAi));
1490        assert!(
1491            aws.iter().any(|m| m.provider_api == ProviderApi::Anthropic),
1492            "Claude must be included via the Anthropic protocol"
1493        );
1494        // The OpenAI endpoint rejects `us.*` cross-region profile ids.
1495        assert!(aws.iter().all(|m| !m.upstream_id.starts_with("us.")));
1496    }
1497
1498    #[test]
1499    fn resolve_for_scopes_to_cloud() {
1500        // The same public id serves on more than one cloud with different upstream
1501        // ids, so resolution must scope to the binding's cloud.
1502        let aws = resolve_for("claude-opus-4.8", Platform::Aws).expect("aws claude");
1503        assert_eq!(aws.upstream_id, "anthropic.claude-opus-4-8");
1504        let gcp = resolve_for("claude-opus-4.8", Platform::Gcp).expect("gcp claude");
1505        assert_eq!(gcp.upstream_id, "claude-opus-4-8");
1506        assert_eq!(gcp.provider_api, ProviderApi::Anthropic);
1507        // Canonicalization applies per cloud: Claude Code's dashed release-date
1508        // spelling resolves to the Vertex `@date` id.
1509        let dated = resolve_for("claude-haiku-4-5-20251001", Platform::Gcp).expect("dated id");
1510        assert_eq!(dated.upstream_id, "claude-haiku-4-5@20251001");
1511        // A Vertex-native `@date` spelling resolves too — it is the very id the
1512        // GCP catalog stores upstream.
1513        let vertex = resolve_for("claude-sonnet-4-5@20250929", Platform::Gcp).expect("vertex id");
1514        assert_eq!(vertex.upstream_id, "claude-sonnet-4-5@20250929");
1515        // A model serving on one cloud does not resolve on another.
1516        assert!(resolve_for("gemini-2.5-pro", Platform::Aws).is_none());
1517        assert!(resolve_for("gpt-4.1", Platform::Gcp).is_none());
1518    }
1519
1520    #[test]
1521    fn lookup_round_trips() {
1522        let m = lookup("gpt-oss-20b").expect("known model");
1523        assert_eq!(m.cloud, Platform::Aws);
1524        assert_eq!(m.provider_api, ProviderApi::OpenAi);
1525        assert_eq!(m.upstream_id, "openai.gpt-oss-20b-1:0");
1526
1527        let c = lookup("claude-opus-4.8").expect("claude known");
1528        assert_eq!(c.provider_api, ProviderApi::Anthropic);
1529
1530        assert!(lookup("nonexistent-model").is_none());
1531    }
1532
1533    #[test]
1534    fn azure_deployments_map_to_catalog() {
1535        assert!(!azure_deployments().is_empty());
1536        for (deployment, ..) in azure_deployments() {
1537            assert!(
1538                models_for(Platform::Azure)
1539                    .iter()
1540                    .any(|m| m.upstream_id == deployment)
1541                    || resolve_embedding_for(deployment, Platform::Azure).is_some(),
1542                "azure deployment {deployment} must map to a catalog model"
1543            );
1544        }
1545    }
1546
1547    #[test]
1548    fn embeddings_resolve_only_on_the_cloud_that_serves_them() {
1549        let m = resolve_embedding_for("text-embedding-3-large", Platform::Azure).unwrap();
1550        assert_eq!(m.upstream_id, "text-embedding-3-large");
1551        assert!(resolve_embedding_for("text-embedding-3-large", Platform::Aws).is_none());
1552        assert!(resolve_embedding_for("text-embedding-3-large", Platform::Gcp).is_none());
1553        let g = resolve_embedding_for("gemini-embedding-001", Platform::Gcp).unwrap();
1554        assert_eq!(g.upstream_id, "gemini-embedding-001");
1555        assert!(resolve_embedding_for("gemini-embedding-001", Platform::Azure).is_none());
1556        assert!(lookup("gemini-embedding-001").is_none());
1557        // Embeddings never appear in the text-generation catalog.
1558        assert!(lookup("text-embedding-3-large").is_none());
1559    }
1560
1561    #[test]
1562    fn api_kinds_have_stable_wire_names() {
1563        assert_eq!(
1564            serde_json::to_string(&ProviderApi::OpenAi).unwrap(),
1565            "\"openai\""
1566        );
1567        assert_eq!(
1568            serde_json::to_string(&ProviderApi::Anthropic).unwrap(),
1569            "\"anthropic\""
1570        );
1571        assert_eq!(
1572            serde_json::to_string(&ProviderApi::OpenAiResponses).unwrap(),
1573            "\"openairesponses\""
1574        );
1575        assert_eq!(
1576            serde_json::to_string(&ClientApi::OpenAiChatCompletions).unwrap(),
1577            "\"open-ai-chat-completions\""
1578        );
1579        assert_eq!(
1580            serde_json::to_string(&ClientApi::OpenAiResponses).unwrap(),
1581            "\"open-ai-responses\""
1582        );
1583        assert_eq!(
1584            serde_json::to_string(&ClientApi::AnthropicMessages).unwrap(),
1585            "\"anthropic-messages\""
1586        );
1587    }
1588
1589    #[test]
1590    fn client_apis_are_explicit_and_non_empty() {
1591        for model in CATALOG {
1592            assert!(
1593                !model.client_apis.is_empty(),
1594                "'{}' has no supported client API",
1595                model.public_id
1596            );
1597        }
1598
1599        let gpt_oss = resolve_for("gpt-oss-20b", Platform::Aws).unwrap();
1600        assert!(gpt_oss
1601            .client_apis
1602            .contains(&ClientApi::OpenAiChatCompletions));
1603        assert!(gpt_oss.client_apis.contains(&ClientApi::OpenAiResponses));
1604    }
1605
1606    #[test]
1607    fn every_model_has_provider_display_name_and_activation() {
1608        for m in CATALOG {
1609            assert_ne!(
1610                m.provider(),
1611                "unknown",
1612                "no provider mapping for '{}'",
1613                m.public_id
1614            );
1615            assert_ne!(
1616                m.display_name(),
1617                m.public_id,
1618                "no curated display_name for '{}'",
1619                m.public_id
1620            );
1621            // Only Claude needs a one-time step; everything else is out of the box.
1622            let is_claude = m.public_id.starts_with("claude");
1623            match m.activation() {
1624                Activation::OutOfBox => {
1625                    assert!(
1626                        !is_claude,
1627                        "'{}' (Claude) must require a one-time step",
1628                        m.public_id
1629                    )
1630                }
1631                Activation::RequiresOneTimeStep(summary) => {
1632                    assert!(is_claude, "'{}' must be out of the box", m.public_id);
1633                    assert!(
1634                        !summary.is_empty(),
1635                        "'{}' step summary is empty",
1636                        m.public_id
1637                    );
1638                }
1639            }
1640        }
1641    }
1642
1643    /// The gateway forwards, it does not translate, so a client picks its wire format
1644    /// from the model id alone. Break this and an OpenAI body reaches the Anthropic
1645    /// upstream, or the reverse, for a bare 400 no caller can act on.
1646    #[test]
1647    fn only_claude_ids_speak_the_anthropic_protocol() {
1648        for m in CATALOG {
1649            assert_eq!(
1650                m.provider_api == ProviderApi::Anthropic,
1651                m.public_id.starts_with("claude"),
1652                "'{}' is {:?} but its id says otherwise",
1653                m.public_id,
1654                m.provider_api
1655            );
1656        }
1657    }
1658}