1use crate::model::RuntimeBedrockModel;
8use crate::provider::ProviderError;
9use serde::Serialize;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
13#[serde(rename_all = "snake_case")]
14pub enum BedrockConversationApi {
15 Converse,
16 ChatCompletions,
19}
20
21#[derive(Debug, Clone, Copy, Serialize)]
23pub struct BedrockModelDescriptor {
24 pub model_id: &'static str,
25 pub display_name: &'static str,
26 pub context_window_label: &'static str,
27 pub max_output_label: Option<&'static str>,
28 pub conversation_api: BedrockConversationApi,
29 pub requires_inference_profile: bool,
30 pub model_card: &'static str,
31}
32
33impl BedrockModelDescriptor {
34 pub fn with_token_limits(
39 &self,
40 context_tokens: usize,
41 output_tokens: usize,
42 ) -> Result<RuntimeBedrockModel, ProviderError> {
43 RuntimeBedrockModel::new(
44 self.display_name,
45 self.model_id,
46 context_tokens,
47 output_tokens,
48 )
49 }
50}
51
52macro_rules! descriptor {
53 ($id:literal, $name:literal, $context:literal, $output:expr, $api:ident, $profile:literal, $card:literal) => {
54 BedrockModelDescriptor {
55 model_id: $id,
56 display_name: $name,
57 context_window_label: $context,
58 max_output_label: $output,
59 conversation_api: BedrockConversationApi::$api,
60 requires_inference_profile: $profile,
61 model_card: concat!(
62 "https://docs.aws.amazon.com/bedrock/latest/userguide/",
63 $card,
64 ".html"
65 ),
66 }
67 };
68}
69
70pub const BEDROCK_MODEL_CATALOG: &[BedrockModelDescriptor] = &[
74 descriptor!(
75 "anthropic.claude-opus-5-5",
76 "Claude Opus 5.5",
77 "1M",
78 Some("128K"),
79 Converse,
80 true,
81 "model-card-anthropic-claude-opus-5-5"
82 ),
83 descriptor!(
84 "anthropic.claude-opus-5",
85 "Claude Opus 5.0",
86 "1M",
87 Some("128K"),
88 Converse,
89 true,
90 "model-card-anthropic-claude-opus-5"
91 ),
92 descriptor!(
93 "anthropic.claude-sonnet-5",
94 "Claude Sonnet 5",
95 "1M",
96 Some("128K"),
97 Converse,
98 true,
99 "model-card-anthropic-claude-sonnet-5"
100 ),
101 descriptor!(
102 "anthropic.claude-opus-4-8",
103 "Claude Opus 4.8",
104 "1M",
105 Some("128K"),
106 Converse,
107 true,
108 "model-card-anthropic-claude-opus-4-8"
109 ),
110 descriptor!(
111 "anthropic.claude-opus-4-7",
112 "Claude Opus 4.7",
113 "1M",
114 Some("128K"),
115 Converse,
116 true,
117 "model-card-anthropic-claude-opus-4-7"
118 ),
119 descriptor!(
120 "anthropic.claude-sonnet-4-6",
121 "Claude Sonnet 4.6",
122 "1M",
123 Some("64K"),
124 Converse,
125 true,
126 "model-card-anthropic-claude-sonnet-4-6"
127 ),
128 descriptor!(
129 "anthropic.claude-opus-4-5-20251101-v1:0",
130 "Claude Opus 4.5",
131 "200K",
132 Some("64K"),
133 Converse,
134 true,
135 "model-card-anthropic-claude-opus-4-5"
136 ),
137 descriptor!(
138 "anthropic.claude-sonnet-4-5-20250929-v1:0",
139 "Claude Sonnet 4.5",
140 "200K",
141 Some("64K"),
142 Converse,
143 true,
144 "model-card-anthropic-claude-sonnet-4-5"
145 ),
146 descriptor!(
147 "anthropic.claude-sonnet-4-20250514-v1:0",
148 "Claude Sonnet 4",
149 "200K",
150 Some("64K"),
151 Converse,
152 true,
153 "model-card-anthropic-claude-sonnet-4"
154 ),
155 descriptor!(
156 "anthropic.claude-haiku-4-5-20251001-v1:0",
157 "Claude Haiku 4.5",
158 "200K",
159 Some("64K"),
160 Converse,
161 true,
162 "model-card-anthropic-claude-haiku-4-5"
163 ),
164 descriptor!(
166 "anthropic.claude-fable-5",
167 "Claude Fable 5",
168 "1M",
169 Some("128K"),
170 Converse,
171 true,
172 "model-card-anthropic-claude-fable-5"
173 ),
174 descriptor!(
175 "anthropic.claude-fable-5-1",
176 "Claude Fable 5.1",
177 "1M",
178 Some("128K"),
179 Converse,
180 true,
181 "model-card-anthropic-claude-fable-5-1"
182 ),
183 descriptor!(
184 "openai.gpt-6-astra",
185 "GPT-6 Astra",
186 "1,050,000",
187 Some("128,000"),
188 Converse,
189 true,
190 "model-card-openai-gpt-6-astra"
191 ),
192 descriptor!(
193 "openai.gpt-5.6-sol",
194 "GPT-5.6 Sol",
195 "1M",
196 None,
197 Converse,
198 true,
199 "model-card-openai-gpt-56-sol"
200 ),
201 descriptor!(
202 "openai.gpt-5.6-terra",
203 "GPT-5.6 Terra",
204 "1M",
205 None,
206 Converse,
207 true,
208 "model-card-openai-gpt-56-terra"
209 ),
210 descriptor!(
211 "openai.gpt-5.6-luna",
212 "GPT-5.6 Luna",
213 "1M",
214 None,
215 Converse,
216 true,
217 "model-card-openai-gpt-56-luna"
218 ),
219 descriptor!(
220 "minimax.minimax-m2.5",
221 "MiniMax M2.5",
222 "196K",
223 Some("8K"),
224 Converse,
225 false,
226 "model-card-minimax-minimax-m2-5"
227 ),
228 descriptor!(
229 "minimax.minimax-m2.1",
230 "MiniMax M2.1",
231 "196K",
232 Some("8K"),
233 Converse,
234 false,
235 "model-card-minimax-minimax-m2-1"
236 ),
237 descriptor!(
238 "zai.glm-5",
239 "GLM 5",
240 "200K",
241 Some("128K"),
242 Converse,
243 false,
244 "model-card-zai-glm-5"
245 ),
246 descriptor!(
247 "deepseek.v3.2",
248 "DeepSeek V3.2",
249 "164K",
250 Some("8K"),
251 Converse,
252 false,
253 "model-card-deepseek-deepseek-v3-2"
254 ),
255 descriptor!(
256 "qwen.qwen3-coder-next",
257 "Qwen3 Coder Next",
258 "256K",
259 Some("16K"),
260 Converse,
261 false,
262 "model-card-qwen-qwen3-coder-next"
263 ),
264 descriptor!(
265 "xai.grok-4.6",
266 "Grok 4.6",
267 "500K",
268 None,
269 Converse,
270 true,
271 "model-card-xai-grok-4-6"
272 ),
273 descriptor!(
274 "moonshotai.kimi-k3",
275 "Kimi K3",
276 "1M",
277 None,
278 ChatCompletions,
279 true,
280 "model-card-moonshot-ai-kimi-k3"
281 ),
282];
283
284pub fn bedrock_model_descriptor(model_id: &str) -> Option<&'static BedrockModelDescriptor> {
287 let base = ["us.", "eu.", "apac.", "au.", "in.", "jp.", "global."]
288 .iter()
289 .find_map(|prefix| model_id.strip_prefix(prefix))
290 .unwrap_or(model_id);
291 BEDROCK_MODEL_CATALOG
292 .iter()
293 .find(|model| model.model_id == base)
294}
295
296#[cfg(test)]
297mod tests {
298 use super::*;
299 use crate::model::{BedrockModel, InferenceProfile, Model};
300 use std::collections::HashSet;
301
302 #[test]
303 fn catalog_ids_are_unique_and_constructible_without_implicit_routing() {
304 assert_eq!(BEDROCK_MODEL_CATALOG.len(), 23);
305 let mut seen = HashSet::new();
306 for descriptor in BEDROCK_MODEL_CATALOG {
307 assert!(seen.insert(descriptor.model_id));
308 let configured = descriptor.with_token_limits(128_000, 4096).unwrap();
309 assert_eq!(configured.bedrock_id(), descriptor.model_id);
310 assert_eq!(configured.name(), descriptor.display_name);
311 assert_eq!(
312 configured.default_inference_profile(),
313 InferenceProfile::None
314 );
315 assert!(descriptor
316 .model_card
317 .starts_with("https://docs.aws.amazon.com/bedrock/"));
318 }
319 }
320
321 #[test]
322 fn unknown_limits_and_unmapped_aliases_stay_unknown() {
323 assert!(bedrock_model_descriptor("openai.gpt-5.6-sol")
324 .unwrap()
325 .max_output_label
326 .is_none());
327 for alias in [
328 "auto",
329 "agi-nova-beta-1m",
330 "kirin-inference-glm",
331 "unknown.model",
332 ] {
333 assert!(bedrock_model_descriptor(alias).is_none());
334 }
335 }
336
337 #[test]
338 fn profile_lookup_does_not_substitute_models_or_infer_arns() {
339 assert_eq!(
340 bedrock_model_descriptor("us.anthropic.claude-opus-5")
341 .unwrap()
342 .display_name,
343 "Claude Opus 5.0"
344 );
345 assert!(bedrock_model_descriptor(
346 "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/example"
347 )
348 .is_none());
349 assert_eq!(
350 bedrock_model_descriptor("moonshotai.kimi-k3")
351 .unwrap()
352 .conversation_api,
353 BedrockConversationApi::ChatCompletions
354 );
355 }
356}