Open History to see the last commit
1/**
2 * Bedrock API compatibility config. First matching `match` substring wins.
3 * Transcribed from:
4 * https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html
5 * mantlePath is transcribed from each model card's Programmatic Access URL
6 * (default /v1). Put more specific matches first.
7 *
8 * `models` lists ids the AWS ListFoundationModels call does not return so
9 * `scripts/fetch-bedrock-models.ts` can still emit them.
10 */
11export type BedrockMantlePath = '/v1' | '/openai/v1'
12
13export interface BedrockSeedModel {
14 id: string
15 input: ReadonlyArray<string>
16}
17
18export interface BedrockCompatibilityRule {
19 match: string
20 converse: boolean
21 chat: boolean
22 responses: boolean
23 mantlePath?: BedrockMantlePath
24 models?: ReadonlyArray<BedrockSeedModel>
25}
26
27export interface BedrockCompatibility {
28 converse: boolean
29 chat: boolean
30 responses: boolean
31 mantlePath: BedrockMantlePath
32}
33
34export const BEDROCK_API_COMPATIBILITY: ReadonlyArray<BedrockCompatibilityRule> =
35 [
36 { match: 'openai.gpt-oss', converse: true, chat: true, responses: true },
37 {
38 match: 'anthropic.claude',
39 converse: true,
40 chat: false,
41 responses: false,
42 },
43 { match: 'amazon.nova', converse: true, chat: false, responses: false },
44 { match: 'meta.llama', converse: true, chat: false, responses: false },
45 { match: 'ai21.jamba', converse: true, chat: false, responses: false },
46 { match: 'cohere.command', converse: true, chat: false, responses: false },
47 { match: 'deepseek.r1', converse: true, chat: false, responses: false },
48 { match: 'deepseek', converse: true, chat: true, responses: false },
49 {
50 match: 'mistral.pixtral',
51 converse: true,
52 chat: false,
53 responses: false,
54 },
55 { match: 'mistral', converse: true, chat: true, responses: false },
56 { match: 'qwen', converse: true, chat: true, responses: false },
57 {
58 match: 'google.gemma-4-',
59 converse: false,
60 chat: true,
61 responses: true,
62 mantlePath: '/openai/v1',
63 models: [
64 { id: 'google.gemma-4-31b', input: ['text', 'image'] },
65 { id: 'google.gemma-4-26b-a4b', input: ['text', 'image'] },
66 { id: 'google.gemma-4-e2b', input: ['text', 'image'] },
67 ],
68 },
69 {
70 match: 'google.gemma',
71 converse: true,
72 chat: true,
73 responses: false,
74 mantlePath: '/v1',
75 },
76 ]
77
78const DEFAULT_COMPAT: BedrockCompatibility = {
79 converse: true,
80 chat: false,
81 responses: false,
82 mantlePath: '/v1',
83}
84
85export function lookupBedrockCompatibility(id: string): BedrockCompatibility {
86 for (const rule of BEDROCK_API_COMPATIBILITY) {
87 if (id.includes(rule.match)) {
88 return {
89 converse: rule.converse,
90 chat: rule.chat,
91 responses: rule.responses,
92 mantlePath: rule.mantlePath ?? '/v1',
93 }
94 }
95 }
96 return DEFAULT_COMPAT
97}
98
99/** Mantle OpenAI path from the compatibility config. Unknown ids stay on `/v1`. */
100export function mantlePathForModel(
101 model: string | undefined,
102): BedrockMantlePath {
103 if (typeof model !== 'string') return '/v1'
104 return lookupBedrockCompatibility(model).mantlePath
105}