Open History to see the last commit
1import nativeSdk from '../fixtures/bedrock-converse-native-sdk.json'
2import nativeThinkingGuides from '../fixtures/bedrock-native-thinking-guides.json'
3
4import { afterEach, describe, expect, it } from 'vitest'
5
6import { price } from '@modelschemas/rate-card'
7import type { RateCard } from '@modelschemas/rate-card'
8
9import {
10 BEDROCK_CARDS_URL,
11 bedrockCardPrice,
12 bedrockReasoning,
13 parseBedrockCard,
14 parseBedrockProfileRows,
15} from '../bedrock-cards.ts'
16import {
17 BEDROCK_METERED_URL,
18 BEDROCK_PRICE_LIST_URL,
19 BEDROCK_PRICING_PAGE_URL,
20} from '../bedrock-pricing.ts'
21import { BEDROCK_SDK_MODEL_URL } from '../bedrock-sdk-spec.ts'
22import { sha256Text } from '../types.ts'
23import { provider } from './amazon-bedrock.ts'
24
25function isRecord(value: unknown): value is Record<string, unknown> {
26 return typeof value === 'object' && value !== null && !Array.isArray(value)
27}
28
29function responseContent(
30 operation: Record<string, unknown> | undefined,
31): unknown {
32 const responses = operation?.responses
33 if (!isRecord(responses)) return undefined
34 const ok = responses['200']
35 if (!isRecord(ok)) return undefined
36 return ok.content
37}
38
39const DOCS = 'https://docs.aws.amazon.com/bedrock/latest/userguide/'
40const YES = ``
41const NO = ``
42
43// AWS ends every table line with `| ` — the trailing space is deliberate.
44const INDEX = `# Models at a glance
45| Logo | Provider | Supported models |
46| --- | --- | --- |
47| x | [Anthropic](model-cards-anthropic.md) | [Claude Sonnet 4.5](model-card-anthropic-claude-sonnet-4-5.md) |
48| x | [OpenAI](model-cards-openai.md) | [GPT-6 Sol](model-card-openai-gpt-6-sol.md), [GPT-5.4](model-card-openai-gpt-54.md) |
49`
50
51/** Older layout: two-column modalities, an API table per endpoint. */
52const SONNET = `# Claude Sonnet 4.5
53
54## Model Details
55+ **Model launch date:** Sep 30, 2025
56+ **Model lifecycle:** Legacy
57+ **Context window:** 200K tokens
58+ **Max output tokens:** 64K
59+ **Reasoning:** Supported
60
61| **Input Modalities** | **Output Modalities** |
62| --- | --- |
63| ${YES} Image | ${NO} Image |
64| ${NO} Speech | ${NO} Speech |
65| ${YES} Text | ${YES} Text |
66
67**APIs supported on bedrock-runtime endpoint**
68
69| **Messages** | **Responses** | **Chat Completions** | **Converse** | **Invoke** |
70| --- | --- | --- | --- | --- |
71| ${NO} | ${NO} | ${NO} | ${YES} | ${YES} |
72
73## Pricing
74For pricing, see the [Amazon Bedrock Pricing](https://aws.amazon.com/bedrock/pricing/) page.
75
76## Programmatic Access
77
78| **Endpoint** | **Model ID** | **In-Region endpoint URL** | **Geo inference ID** | **Global inference ID** |
79| --- | --- | --- | --- | --- |
80| bedrock-runtime | anthropic.claude-sonnet-4-5-20250929-v1:0 | N/A | us.anthropic.claude-sonnet-4-5-20250929-v1:0<br />eu.anthropic.claude-sonnet-4-5-20250929-v1:0 | global.anthropic.claude-sonnet-4-5-20250929-v1:0 |
81
82## Regional Availability
83`
84
85const PRICE_HEAD = `| **Inference option** | **Input** | **Input — cache write** | **Input — cache read** | **Output** |
86| --- | --- | --- | --- | --- | `
87
88/** Priced, and the global profile bills less than the in-Region id. */
89const GPT6 = `# GPT-6 Sol
90
91## Model details
92+ **Model launch date:** September 22, 2026
93+ **Model lifecycle:** Active
94+ **Context window:** 1,050,000 tokens
95+ **Max output tokens:** 128,000
96
97| **Input modalities** | **Output modalities** |
98| --- | --- |
99| ${YES} Text | ${YES} Text |
100
101Set \`prompt_cache_options.ttl\` to \`30m\`, the only supported TTL and the default.
102
103## Pricing
104
105All prices are in USD per 1 million tokens for the Standard tier.
106
107### Commercial Regions — short context (272K input tokens or fewer)
108
109${PRICE_HEAD}
110| Mantle in-Region | $2.20 | $2.75 | $0.22 | $11.00 |
111| Global CRIS | $2.00 | $2.50 | $0.20 | $10.00 |
112
113### Commercial Regions — long context (more than 272K input tokens)
114
115${PRICE_HEAD}
116| Mantle in-Region | $4.40 | $5.50 | $0.44 | $16.50 |
117| Global CRIS | $4.00 | $5.00 | $0.40 | $15.00 |
118
119## Call the model
120
121| **Endpoint** | **Model ID** | **In-Region endpoint URL** | **Geo inference ID** | **Global inference ID** |
122| --- | --- | --- | --- | --- |
123| bedrock-runtime | openai.gpt-6-sol | Not supported | us.openai.gpt-6-sol | global.openai.gpt-6-sol |
124| bedrock-mantle | openai.gpt-6-sol | https://bedrock-mantle.{region}.api.aws/openai/v1 | Not supported | Not supported |
125
126## Service tiers
127`
128
129/** Prices only a cross-Region profile: the base id gets no card. */
130const GPT54 = `# GPT-5.4
131
132## Model details
133+ **Model lifecycle:** Active
134
135| **Input Modalities** | **Output Modalities** | **[APIs supported](apis.html)** | **[Endpoints supported](endpoints.html)** |
136| --- | --- | --- | --- |
137| ${YES} Text | ${YES} Text | ${YES} Converse | ${YES} bedrock-runtime |
138
139## Pricing
140
141| **Inference option** | **Input** | **Output** |
142| --- | --- | --- |
143| Global CRIS | $2.00 | $6.00 |
144
145*All prices are per 1 million tokens.*
146
147## Programmatic Access
148
149| **Endpoint** | **Model ID** | **In-Region endpoint URL** | **Geo inference ID** | **Global inference ID** |
150| --- | --- | --- | --- | --- |
151| bedrock-runtime | openai.gpt-5.4 | N/A | Not supported | global.openai.gpt-5.4 |
152
153## Service Tiers
154`
155
156const SDK_MODEL = {
157 operations: {
158 Converse: {
159 http: { method: 'POST', requestUri: '/model/{modelId}/converse' },
160 input: { shape: 'ConverseRequest' },
161 output: { shape: 'ConverseResponse' },
162 documentation: '<p>Sends messages to the model.</p>',
163 },
164 ConverseStream: {
165 http: { method: 'POST', requestUri: '/model/{modelId}/converse-stream' },
166 input: { shape: 'ConverseStreamRequest' },
167 output: { shape: 'ConverseStreamResponse' },
168 documentation: '<p>Streams messages from the model.</p>',
169 },
170 InvokeModel: {
171 http: { method: 'POST', requestUri: '/model/{modelId}/invoke' },
172 input: { shape: 'InvokeModelRequest' },
173 output: { shape: 'InvokeModelResponse' },
174 },
175 InvokeModelWithResponseStream: {
176 http: {
177 method: 'POST',
178 requestUri: '/model/{modelId}/invoke-with-response-stream',
179 },
180 input: { shape: 'InvokeModelRequest' },
181 output: { shape: 'InvokeModelWithResponseStreamResponse' },
182 },
183 },
184 shapes: {
185 ConverseRequest: {
186 type: 'structure',
187 required: ['modelId', 'messages'],
188 members: {
189 modelId: { shape: 'ModelId', location: 'uri' },
190 messages: { shape: 'Messages', documentation: '<p>The messages.</p>' },
191 },
192 },
193 ConverseResponse: {
194 type: 'structure',
195 members: { stopReason: { shape: 'StopReason' } },
196 },
197 ModelId: { type: 'string', pattern: '(?<bad' },
198 Messages: { type: 'list', member: { shape: 'ContentBlock' }, min: 1 },
199 ContentBlock: {
200 type: 'structure',
201 union: true,
202 members: { text: { shape: 'Text' }, json: { shape: 'Document' } },
203 },
204 Text: { type: 'string', max: 10 },
205 Document: { type: 'structure', members: {}, document: true },
206 StopReason: { type: 'string', enum: ['end_turn', 'max_tokens'] },
207 Throttled: { type: 'structure', members: {}, exception: true },
208 ConverseStreamRequest: {
209 type: 'structure',
210 required: ['modelId', 'messages'],
211 members: {
212 modelId: { shape: 'ModelId', location: 'uri' },
213 messages: { shape: 'Messages', documentation: '<p>The messages.</p>' },
214 },
215 },
216 ConverseStreamResponse: {
217 type: 'structure',
218 members: { stream: { shape: 'ConverseStreamOutput' } },
219 payload: 'stream',
220 },
221 ConverseStreamOutput: {
222 type: 'structure',
223 members: {
224 messageStart: { shape: 'MessageStartEvent' },
225 throttled: { shape: 'Throttled' },
226 },
227 eventstream: true,
228 },
229 MessageStartEvent: {
230 type: 'structure',
231 members: { role: { shape: 'StopReason' } },
232 },
233 InvokeModelRequest: {
234 type: 'structure',
235 required: ['modelId', 'body'],
236 members: {
237 modelId: { shape: 'ModelId', location: 'uri' },
238 body: { shape: 'Body', documentation: '<p>The prompt.</p>' },
239 contentType: {
240 shape: 'MimeType',
241 location: 'header',
242 locationName: 'Content-Type',
243 },
244 },
245 payload: 'body',
246 },
247 InvokeModelResponse: {
248 type: 'structure',
249 required: ['body'],
250 members: { body: { shape: 'Body' } },
251 payload: 'body',
252 },
253 InvokeModelWithResponseStreamResponse: {
254 type: 'structure',
255 required: ['body'],
256 members: { body: { shape: 'ResponseStream' } },
257 payload: 'body',
258 },
259 Body: { type: 'blob' },
260 MimeType: { type: 'string' },
261 ResponseStream: {
262 type: 'structure',
263 members: { chunk: { shape: 'PayloadPart' } },
264 eventstream: true,
265 },
266 PayloadPart: {
267 type: 'structure',
268 members: { bytes: { shape: 'Body' } },
269 },
270 },
271}
272
273const PRICE_OFFER = {
274 products: {
275 input: {
276 attributes: {
277 usagetype: 'USE1-example.model-mantle-input-tokens-standard',
278 inferenceType: 'Input tokens',
279 service_tier: 'standard',
280 feature: '',
281 model: 'Example Model',
282 },
283 },
284 output: {
285 attributes: {
286 usagetype: 'USE1-example.model-mantle-output-tokens-standard',
287 inferenceType: 'Output tokens',
288 service_tier: 'standard',
289 feature: '',
290 model: 'Example Model',
291 },
292 },
293 },
294 terms: {
295 OnDemand: {
296 input: {
297 t: {
298 priceDimensions: {
299 d: {
300 unit: '1M tokens',
301 beginRange: '0',
302 endRange: 'Inf',
303 pricePerUnit: { USD: '3' },
304 },
305 },
306 },
307 },
308 output: {
309 t: {
310 priceDimensions: {
311 d: {
312 unit: '1M tokens',
313 beginRange: '0',
314 endRange: 'Inf',
315 pricePerUnit: { USD: '9' },
316 },
317 },
318 },
319 },
320 },
321 },
322}
323
324const PRICE_PAGE = `<h2>Geo and In-region Cross-region Inference</h2>
325<table><thead><tr><th>Models</th><th>Price per 1M input tokens</th><th>Price per 1M output tokens</th></tr></thead>
326<tbody><tr><td>Page Only</td><td>$2.00</td><td>$4.00</td></tr></tbody></table>`
327
328const PAGES: Record<string, string> = {
329 ...nativeThinkingGuides,
330 [BEDROCK_CARDS_URL]: INDEX,
331 [`${DOCS}model-card-anthropic-claude-sonnet-4-5.md`]: SONNET,
332 [`${DOCS}model-card-openai-gpt-6-sol.md`]: GPT6,
333 [`${DOCS}model-card-openai-gpt-54.md`]: GPT54,
334 [BEDROCK_SDK_MODEL_URL]: JSON.stringify(nativeSdk),
335 [BEDROCK_PRICE_LIST_URL]: JSON.stringify(PRICE_OFFER),
336 [BEDROCK_PRICING_PAGE_URL]: PRICE_PAGE,
337 [BEDROCK_METERED_URL]: JSON.stringify({
338 regions: { 'US East (N. Virginia)': {} },
339 }),
340}
341
342const originalFetch = globalThis.fetch
343let urls: Array<string> = []
344
345function serve(pages: Record<string, string>): void {
346 urls = []
347 globalThis.fetch = ((input: string, init?: RequestInit) => {
348 const url = String(input)
349 urls.push(url)
350 // docs.aws.amazon.com answers 403 without a User-Agent.
351 const agent = new Headers(init?.headers).has('User-Agent')
352 const body = url.startsWith(DOCS) && !agent ? undefined : pages[url]
353 return Promise.resolve(
354 body === undefined
355 ? new Response('missing', { status: 404 })
356 : new Response(body),
357 )
358 }) as typeof fetch
359}
360
361afterEach(() => {
362 globalThis.fetch = originalFetch
363})
364
365it('keeps native reasoning capability ticks while leaving the control unknown', () => {
366 const source = {
367 url: 'https://docs.aws.amazon.com/bedrock/latest/userguide/native-test.md',
368 hash: 'hash',
369 extractedAt: '2026-10-09T00:00:00Z',
370 }
371 const card = SONNET.replace('+ **Reasoning:** Supported', '').concat(
372 `\n${YES} [Reasoning](reasoning.html)\n`,
373 )
374 expect(parseBedrockCard(card, source)?.capabilities).toContain('reasoning')
375 expect(parseBedrockCard(card, source)?.reasoning).toBeNull()
376})
377
378describe('amazon-bedrock', () => {
379 it('lists models from the model cards and nothing else', async () => {
380 serve(PAGES)
381 const { models, skipped } = await provider.listModels({})
382
383 expect(skipped).toBeUndefined()
384 expect(urls.filter((url) => !url.startsWith(DOCS)).sort()).toEqual(
385 [
386 BEDROCK_METERED_URL,
387 BEDROCK_SDK_MODEL_URL,
388 'https://docs.aws.amazon.com/nova/latest/nova2-userguide/using-converse-api.md',
389 BEDROCK_PRICE_LIST_URL,
390 BEDROCK_PRICING_PAGE_URL,
391 ].sort(),
392 )
393 expect(models.map((model) => model.rawId)).toEqual([
394 'anthropic.claude-sonnet-4-5-20250929-v1:0',
395 'openai.gpt-6-sol',
396 'openai.gpt-5.4',
397 'us.anthropic.claude-sonnet-4-5-20250929-v1:0',
398 'eu.anthropic.claude-sonnet-4-5-20250929-v1:0',
399 'global.anthropic.claude-sonnet-4-5-20250929-v1:0',
400 'us.openai.gpt-6-sol',
401 'global.openai.gpt-6-sol',
402 'global.openai.gpt-5.4',
403 ])
404 const cardUrl = `${DOCS}model-card-anthropic-claude-sonnet-4-5.md`
405 const source = {
406 derivation: 'docs-derived' as const,
407 sourceUrl: cardUrl,
408 sourceHash: await sha256Text(SONNET),
409 }
410 expect(models[0]).toEqual({
411 rawId: 'anthropic.claude-sonnet-4-5-20250929-v1:0',
412 displayName: 'Claude Sonnet 4.5',
413 activity: 'chat',
414 contextWindow: 200_000,
415 maxOutput: 64_000,
416 modalities: { input: ['image', 'text'], output: ['text'] },
417 // The card names no dollar amount, and the fixtures do not price it.
418 pricing: null,
419 capabilities: ['reasoning'],
420 reasoning: { mode: 'budget', mandatory: null },
421 // Converse roles are user, assistant, system. No reasoning_effort.
422 requestMap: {
423 thinking: null,
424 maxTokensField: null,
425 developerRole: false,
426 replayReasoningContent: null,
427 store: null,
428 strictTools: null,
429 sessionAffinity: null,
430 cacheControl: null,
431 toolStream: null,
432 reasoningEffort: false,
433 },
434 schemaEndpointId: 'model/{modelId}/converse',
435 aliases: [],
436 deprecated: true,
437 releasedAt: Date.UTC(2025, 8, 30) / 1000,
438 factSources: {
439 schemaEndpointId: {
440 derivation: 'docs-derived',
441 sourceUrl: cardUrl,
442 sourceHash: await sha256Text(SONNET),
443 path: 'Programmatic Access: bedrock-runtime model ID; APIs supported: Converse',
444 },
445 requestMap: {
446 derivation: 'generated',
447 sourceUrl: BEDROCK_SDK_MODEL_URL,
448 sourceHash: await sha256Text(JSON.stringify(nativeSdk)),
449 path: '#/operations/Converse/input',
450 },
451 reasoning: {
452 derivation: 'docs-derived',
453 sourceUrl: `${DOCS}claude-messages-extended-thinking.md`,
454 sourceHash: await sha256Text(
455 nativeThinkingGuides[
456 `${DOCS}claude-messages-extended-thinking.md` as keyof typeof nativeThinkingGuides
457 ],
458 ),
459 path: 'reasoning',
460 },
461 contextWindow: { ...source, path: 'contextWindow' },
462 maxOutput: { ...source, path: 'maxOutput' },
463 modalities: { ...source, path: 'modalities' },
464 capabilities: {
465 reasoning: { ...source, path: 'capabilities.reasoning' },
466 },
467 },
468 })
469 })
470
471 it('prices the base id at the in-Region rate with the long-context tier', async () => {
472 serve(PAGES)
473 const { models } = await provider.listModels({})
474 const sol = models[1]
475 const card = sol?.pricing as RateCard
476
477 expect(
478 price(card, {}, { input_tokens: 1e5, output_tokens: 1e6 }),
479 ).toBeCloseTo(0.1 * 2.2 + 11)
480 expect(
481 price(card, {}, { input_tokens: 3e5, output_tokens: 1e6 }),
482 ).toBeCloseTo(0.3 * 4.4 + 16.5)
483 // The column says "cache write". The card's only TTL is 30m, so the
484 // 5-minute lever stays empty. Cache read stays.
485 expect(card.inputs.cache_write_tokens).toBeUndefined()
486 expect(card.inputs.cache_write_1h_tokens).toBeUndefined()
487 expect(card.inputs.cache_read_tokens).toBeDefined()
488 // The global profile bills less, so it must not resolve to this card.
489 expect(sol?.aliases).toEqual([])
490 expect(sol?.releasedAt).toBe(Date.UTC(2026, 8, 22) / 1000)
491 // Only a cross-Region profile is priced: no card for the base id.
492 expect(models[2]?.pricing).toBeNull()
493 expect(models[2]?.aliases).toEqual([])
494 expect(models[2]?.schemaEndpointId).toBe('model/{modelId}/converse')
495 })
496
497 it('keeps native profiles distinct and prices global from its own card table', async () => {
498 serve(PAGES)
499 const { models } = await provider.listModels({})
500 const global = models.find(
501 (model) => model.rawId === 'global.openai.gpt-6-sol',
502 )
503 const card = global?.pricing as RateCard
504 expect(global?.aliases).toEqual([])
505 expect(
506 price(card, {}, { input_tokens: 100_000, output_tokens: 1_000_000 }),
507 ).toBeCloseTo(10.2)
508 expect(
509 price(card, {}, { input_tokens: 300_000, output_tokens: 1_000_000 }),
510 ).toBeCloseTo(16.2)
511 expect(global?.factSources?.pricing?.sourceUrl).toBe(
512 `${DOCS}model-card-openai-gpt-6-sol.md`,
513 )
514 const eu = models.find(
515 (model) => model.rawId === 'eu.anthropic.claude-sonnet-4-5-20250929-v1:0',
516 )
517 expect(eu).toMatchObject({
518 pricing: null,
519 aliases: [],
520 absent: { pricing: 'cleared' },
521 })
522 expect(eu?.factSources?.pricing).toBeUndefined()
523 const unpricedGlobal = models.find(
524 (model) =>
525 model.rawId === 'global.anthropic.claude-sonnet-4-5-20250929-v1:0',
526 )
527 expect(unpricedGlobal).toMatchObject({
528 pricing: null,
529 absent: { pricing: 'cleared' },
530 })
531 expect(unpricedGlobal?.factSources?.pricing).toBeUndefined()
532 expect(
533 models.find((model) => model.rawId === 'global.openai.gpt-5.4')?.pricing,
534 ).not.toBeNull()
535 })
536
537 it('prices a documented global profile from the global page, never the geo row', async () => {
538 serve({
539 ...PAGES,
540 [BEDROCK_PRICING_PAGE_URL]: `<h2>Global Cross-region Inference</h2>
541<table><tr><th>Models</th><th>Price per 1M input tokens</th><th>Price per 1M output tokens</th></tr>
542<tr><td>Claude Sonnet 4.5</td><td>$7</td><td>$21</td></tr></table>
543<h2>Geo and In-region Cross-region Inference</h2>
544<table><tr><th>Models</th><th>Price per 1M input tokens</th><th>Price per 1M output tokens</th></tr>
545<tr><td>Claude Sonnet 4.5</td><td>$9</td><td>$27</td></tr></table>`,
546 })
547 const { models } = await provider.listModels({})
548 const base = models.find(
549 (model) => model.rawId === 'anthropic.claude-sonnet-4-5-20250929-v1:0',
550 )
551 const global = models.find(
552 (model) =>
553 model.rawId === 'global.anthropic.claude-sonnet-4-5-20250929-v1:0',
554 )
555 expect((base!.pricing as RateCard).tables.rate?.base).toMatchObject({
556 input_tokens: 9 / 1e6,
557 })
558 expect((global!.pricing as RateCard).tables.rate?.base).toMatchObject({
559 input_tokens: 7 / 1e6,
560 })
561 expect(global?.factSources?.pricing?.sourceUrl).toBe(
562 BEDROCK_PRICING_PAGE_URL,
563 )
564 })
565
566 it('fails the poll when most cards stop stating a model id', async () => {
567 const blank = '# Card\n'
568 serve({
569 ...PAGES,
570 [`${DOCS}model-card-openai-gpt-6-sol.md`]: blank,
571 [`${DOCS}model-card-openai-gpt-54.md`]: blank,
572 })
573 await expect(provider.listModels({})).rejects.toThrow(
574 '1 of 3 cards state a model id',
575 )
576 })
577
578 it('reads the reasoning control a card names', () => {
579 expect(bedrockReasoning('Supported')).toBeNull()
580 expect(
581 bedrockReasoning('Supported (configurable: none, low, medium, high)'),
582 ).toEqual({
583 mode: 'effort',
584 mandatory: null,
585 efforts: ['none', 'low', 'medium', 'high'],
586 })
587 expect(
588 bedrockReasoning(
589 'Supported (adaptive thinking is always on and cannot be disabled; effort level is configurable)',
590 ),
591 ).toEqual({ mode: 'adaptive', mandatory: true })
592 expect(
593 bedrockReasoning(
594 'Supported (adaptive thinking is always on and cannot be disabled; effort level configurable — low, medium, high, xhigh, max; default: high)',
595 ),
596 ).toEqual({
597 mode: 'adaptive',
598 mandatory: true,
599 efforts: ['low', 'medium', 'high', 'xhigh', 'max'],
600 })
601 })
602
603 it('reads a two-space limit bullet and ignores the GovCloud table', () => {
604 const card = parseBedrockCard(
605 `# GPT
606+ **Context window:** 1M tokens
607+ **Max output tokens:** 131,072
608
609| **Endpoint** | **Model ID** | **In-Region endpoint URL** | **Geo inference ID** | **Global inference ID** |
610| --- | --- | --- | --- | --- |
611| bedrock-runtime | openai.gpt-6.1-sol | https://example | Not supported | Not supported |
612`,
613 { url: 'https://example.test/card', hash: 'h', extractedAt: 't' },
614 )
615 expect(card?.contextWindow).toBe(1_000_000)
616 expect(card?.maxOutput).toBe(131_072)
617 expect(card?.requestMap).toBeNull()
618
619 const priced = `
620## Pricing
621| **Inference option** | **Input** | **Output** | **Cache read** |
622| --- | --- | --- | --- |
623| In-Region | $1.25 | $2.50 | $0.20 |
624
625**AWS GovCloud (US-West)**
626
627| **Inference option** | **Input** | **Output** | **Cache read** |
628| --- | --- | --- | --- |
629| In-Region | $1.50 | $3.00 | $0.24 |
630
631*All prices are per 1 million tokens.*
632`
633 const govPrice = bedrockCardPrice(priced)
634 expect(govPrice?.uniform).toBe(true)
635 expect(govPrice?.base.input_tokens).toBeCloseTo(1.25 / 1e6)
636 expect(govPrice?.base.cache_read_tokens).toBeCloseTo(0.2 / 1e6)
637 })
638
639 it('prices GPT-6 Astra standard in-region and drops 30-minute writes and Ultrafast', () => {
640 // Published rows from model-card-openai-gpt-6-astra.md.
641 const card = bedrockCardPrice(`
642## Pricing
643
644All prices are in USD per 1 million tokens. The following tables list Standard and Ultrafast prices.
645
646### Standard — Commercial Regions, short context (272K input tokens or fewer)
647
648| **Inference option** | **Input** | **Input — 30m cache write** | **Input — cache read** | **Output** |
649| --- | --- | --- | --- | --- |
650| In-Region | $11.00 | $13.75 | $1.10 | $55.00 |
651| Geo CRIS | $11.00 | $13.75 | $1.10 | $55.00 |
652| Global CRIS | $10.00 | $12.50 | $1.00 | $50.00 |
653
654### Standard — Commercial Regions, long context (more than 272K input tokens)
655
656| **Inference option** | **Input** | **Input — 30m cache write** | **Input — cache read** | **Output** |
657| --- | --- | --- | --- | --- |
658| In-Region | $22.00 | $27.50 | $2.20 | $82.50 |
659| Geo CRIS | $22.00 | $27.50 | $2.20 | $82.50 |
660| Global CRIS | $20.00 | $25.00 | $2.00 | $75.00 |
661
662### Ultrafast — Commercial Regions, short context (272K input tokens or fewer)
663
664| **Inference option** | **Input** | **Input — 30m cache write** | **Input — cache read** | **Output** |
665| --- | --- | --- | --- | --- |
666| In-Region (us-east-1) | $66.00 | $82.50 | $6.60 | $330.00 |
667| Global CRIS | $60.00 | $75.00 | $6.00 | $300.00 |
668
669### Ultrafast — Commercial Regions, long context (more than 272K input tokens)
670
671| **Inference option** | **Input** | **Input — 30m cache write** | **Input — cache read** | **Output** |
672| --- | --- | --- | --- | --- |
673| In-Region (us-east-1) | $132.00 | $165.00 | $13.20 | $495.00 |
674| Global CRIS | $120.00 | $150.00 | $12.00 | $450.00 |
675`)
676 expect(card?.base).toEqual({
677 input_tokens: 11 / 1e6,
678 output_tokens: 55 / 1e6,
679 cache_read_tokens: 1.1 / 1e6,
680 })
681 expect(card?.tiers).toEqual([
682 {
683 minPromptTokens: 272_000,
684 rates: {
685 input_tokens: 22 / 1e6,
686 output_tokens: 82.5 / 1e6,
687 cache_read_tokens: 2.2 / 1e6,
688 },
689 },
690 ])
691 })
692
693 it('leaves a 30-minute cache-write column empty', () => {
694 // Published rows from model-card-openai-gpt-56-sol.md. The write is
695 // $5.50 on the $4.40 tier and $11.00 on the long tier.
696 const card = bedrockCardPrice(`
697## Pricing
698
699All prices are in USD per 1 million tokens for the Standard tier.
700
701### Commercial Regions — short context (272K input tokens or fewer)
702
703| **Inference option** | **Input** | **Input — 30m cache write** | **Input — cache read** | **Output** |
704| --- | --- | --- | --- | --- |
705| In-Region | $4.40 | $5.50 | $0.44 | $22.00 |
706| Global CRIS | $4.00 | $5.00 | $0.40 | $20.00 |
707
708### Commercial Regions — long context (more than 272K input tokens)
709
710| **Inference option** | **Input** | **Input — 30m cache write** | **Input — cache read** | **Output** |
711| --- | --- | --- | --- | --- |
712| In-Region | $8.80 | $11.00 | $0.88 | $33.00 |
713| Global CRIS | $8.00 | $10.00 | $0.80 | $30.00 |
714
715### AWS GovCloud (US-East and US-West)
716
717#### Long context (more than 272K input tokens)
718
719| **Inference option** | **Input** | **Input — 30m cache write** | **Input — cache read** | **Output** |
720| --- | --- | --- | --- | --- |
721| In-Region | $5.40 | $6.75 | $0.54 | $24.30 |
722`)
723 expect(card?.base).toEqual({
724 input_tokens: 4.4 / 1e6,
725 output_tokens: 22 / 1e6,
726 cache_read_tokens: 0.44 / 1e6,
727 })
728 expect(card?.tiers).toEqual([
729 {
730 minPromptTokens: 272_000,
731 rates: {
732 input_tokens: 8.8 / 1e6,
733 output_tokens: 33 / 1e6,
734 cache_read_tokens: 0.88 / 1e6,
735 },
736 },
737 ])
738 })
739
740 it('maps a 5-minute write, a 1-hour write, and a bare write with no TTL', () => {
741 const named = bedrockCardPrice(`
742## Pricing
743
744All prices are in USD per 1 million tokens.
745
746| **Inference option** | **Input** | **Input — 5m cache write** | **Input — 1h cache write** | **Input — cache read** | **Output** |
747| --- | --- | --- | --- | --- | --- |
748| In-Region | $1.00 | $1.25 | $2.00 | $0.10 | $5.00 |
749`)
750 expect(named?.base).toEqual({
751 input_tokens: 1 / 1e6,
752 cache_write_tokens: 1.25 / 1e6,
753 cache_write_1h_tokens: 2 / 1e6,
754 cache_read_tokens: 0.1 / 1e6,
755 output_tokens: 5 / 1e6,
756 })
757
758 const bare = bedrockCardPrice(`
759## Pricing
760
761All prices are in USD per 1 million tokens.
762
763| **Inference option** | **Input** | **Input — cache write** | **Output** |
764| --- | --- | --- | --- |
765| In-Region | $2.00 | $2.50 | $6.00 |
766`)
767 expect(bare?.base.cache_write_tokens).toBeCloseTo(2.5 / 1e6)
768 })
769
770 it('reads named reasoning levels from the effort section', () => {
771 const card = parseBedrockCard(
772 `# Model
773
774**Reasoning effort**
775
776Set reasoning effort to \`none\`, \`low\`, \`medium\`, \`high\`, \`xhigh\`, or \`max\`.
777
778| **Endpoint** | **Model ID** | **In-Region endpoint URL** | **Geo inference ID** | **Global inference ID** |
779| --- | --- | --- | --- | --- |
780| bedrock-runtime | openai.gpt-6-sol | https://example | Not supported | Not supported |
781`,
782 { url: 'https://example.test/card', hash: 'h', extractedAt: 't' },
783 )
784 expect(card?.reasoning).toEqual({
785 mode: 'effort',
786 mandatory: null,
787 efforts: ['none', 'low', 'medium', 'high', 'xhigh', 'max'],
788 })
789 expect(card?.capabilities).toEqual(['reasoning'])
790 })
791
792 it('generates the Converse schema from the SDK service model', async () => {
793 serve({ ...PAGES, [BEDROCK_SDK_MODEL_URL]: JSON.stringify(SDK_MODEL) })
794 const spec = await provider.fetchSpec({})
795 const doc = spec.specs[0]
796
797 expect(urls).toEqual([BEDROCK_SDK_MODEL_URL])
798 expect(spec.skipped).toBeUndefined()
799 expect(Object.keys(doc?.paths ?? {})).toEqual([
800 '/model/{modelId}/converse',
801 '/model/{modelId}/converse-stream',
802 '/model/{modelId}/invoke',
803 '/model/{modelId}/invoke-with-response-stream',
804 ])
805 expect(provider.classify('/model/{modelId}/converse', {})).toBe('chat')
806 expect(provider.classify('/model/{modelId}/converse-stream', {})).toBe(
807 'chat',
808 )
809 expect(provider.classify('/model/{modelId}/invoke', {})).toBe('chat')
810 expect(
811 provider.classify('/model/{modelId}/invoke-with-response-stream', {}),
812 ).toBe('chat')
813 const stream = doc?.paths?.['/model/{modelId}/converse-stream']?.post
814 expect(responseContent(stream)).toEqual({
815 'application/vnd.amazon.eventstream': {
816 schema: { $ref: '#/components/schemas/ConverseStreamOutput' },
817 },
818 })
819 const invoke = doc?.paths?.['/model/{modelId}/invoke']?.post
820 expect(invoke?.requestBody).toEqual({
821 required: true,
822 content: {
823 'application/json': { schema: { description: 'The prompt.' } },
824 },
825 })
826 expect(invoke?.parameters).toEqual([
827 {
828 name: 'modelId',
829 in: 'path',
830 required: true,
831 schema: { type: 'string' },
832 },
833 {
834 name: 'Content-Type',
835 in: 'header',
836 required: false,
837 schema: { $ref: '#/components/schemas/MimeType' },
838 },
839 ])
840 expect(doc?.components?.schemas).toEqual({
841 // modelId rides the path; the body schema leaves it out.
842 ConverseRequest: {
843 type: 'object',
844 properties: {
845 messages: {
846 $ref: '#/components/schemas/Messages',
847 description: 'The messages.',
848 },
849 },
850 required: ['messages'],
851 },
852 ConverseResponse: {
853 type: 'object',
854 properties: { stopReason: { $ref: '#/components/schemas/StopReason' } },
855 },
856 ModelId: { type: 'string' },
857 Messages: {
858 type: 'array',
859 items: { $ref: '#/components/schemas/ContentBlock' },
860 minItems: 1,
861 },
862 ContentBlock: {
863 type: 'object',
864 properties: {
865 text: { $ref: '#/components/schemas/Text' },
866 json: { $ref: '#/components/schemas/Document' },
867 },
868 minProperties: 1,
869 maxProperties: 1,
870 },
871 Text: { type: 'string', maxLength: 10 },
872 Document: {},
873 StopReason: { type: 'string', enum: ['end_turn', 'max_tokens'] },
874 ConverseStreamRequest: {
875 type: 'object',
876 properties: {
877 messages: {
878 $ref: '#/components/schemas/Messages',
879 description: 'The messages.',
880 },
881 },
882 required: ['messages'],
883 },
884 ConverseStreamResponse: {
885 type: 'object',
886 properties: {
887 stream: { $ref: '#/components/schemas/ConverseStreamOutput' },
888 },
889 },
890 ConverseStreamOutput: {
891 type: 'object',
892 properties: {
893 messageStart: { $ref: '#/components/schemas/MessageStartEvent' },
894 throttled: { $ref: '#/components/schemas/Throttled' },
895 },
896 minProperties: 1,
897 maxProperties: 1,
898 },
899 MessageStartEvent: {
900 type: 'object',
901 properties: { role: { $ref: '#/components/schemas/StopReason' } },
902 },
903 Throttled: { type: 'object', properties: {} },
904 InvokeModelRequest: {
905 type: 'object',
906 properties: {
907 body: {
908 $ref: '#/components/schemas/Body',
909 description: 'The prompt.',
910 },
911 },
912 required: ['body'],
913 },
914 InvokeModelResponse: {
915 type: 'object',
916 properties: { body: { $ref: '#/components/schemas/Body' } },
917 required: ['body'],
918 },
919 InvokeModelWithResponseStreamResponse: {
920 type: 'object',
921 properties: { body: { $ref: '#/components/schemas/ResponseStream' } },
922 required: ['body'],
923 },
924 Body: { type: 'string', contentEncoding: 'base64' },
925 MimeType: { type: 'string' },
926 ResponseStream: {
927 type: 'object',
928 properties: { chunk: { $ref: '#/components/schemas/PayloadPart' } },
929 minProperties: 1,
930 maxProperties: 1,
931 },
932 PayloadPart: {
933 type: 'object',
934 properties: { bytes: { $ref: '#/components/schemas/Body' } },
935 },
936 })
937 })
938})
939
940// A published current quote is not source silence when its markup is unreadable.
941describe('Bedrock malformed current quotes', () => {
942 it('rejects an unreadable Global long-context tier without a flat substitute', () => {
943 const malformed = GPT6.replace(
944 '| Global CRIS | $4.00 | $5.00 | $0.40 | $15.00 |',
945 '| Global CRIS | unreadable | unreadable | unreadable | unreadable |',
946 )
947 expect(() => bedrockCardPrice(malformed, 'global')).toThrow(
948 'amazon-bedrock model card pricing: unreadable long-context tier',
949 )
950 })
951 it('rejects a malformed Global card quote rather than inheriting in-Region', () => {
952 expect(() =>
953 bedrockCardPrice(GPT54.replace('$2.00', '$unreadable'), 'global'),
954 ).toThrow('amazon-bedrock model card pricing: unreadable quote')
955 })
956
957 it('states the maker and model a card id names, minus Bedrock version and geography', () => {
958 const upstream = (rawId: string) => {
959 const identity = provider.upstreamModelIdentity?.(rawId)
960 return identity ? `${identity.providerNamespace}/${identity.rawId}` : null
961 }
962 // Ids from the live listing, 2026-11-21.
963 expect(upstream('anthropic.claude-opus-4-5-20251101-v1:0')).toBe(
964 'anthropic/claude-opus-4-5-20251101',
965 )
966 expect(upstream('global.anthropic.claude-opus-4-6-v1')).toBe(
967 'anthropic/claude-opus-4-6',
968 )
969 expect(upstream('us-gov.openai.gpt-oss-120b-1:0')).toBe(
970 'openai/gpt-oss-120b',
971 )
972 expect(upstream('apac.anthropic.claude-sonnet-4-20250514-v1:0')).toBe(
973 'anthropic/claude-sonnet-4-20250514',
974 )
975 expect(upstream('us.xai.grok-4.7')).toBe('xai/grok-4.7')
976 expect(upstream('stability.stable-image-core-v1:1')).toBe(
977 'stability/stable-image-core',
978 )
979 // A maker's own version stays: only Bedrock's v1 is stripped.
980 expect(upstream('cohere.embed-v4:0')).toBe('cohere/embed-v4')
981 expect(upstream('deepseek.v3.2')).toBe('deepseek/v3.2')
982 // Bedrock's own models name no other host.
983 expect(upstream('amazon.nova-pro-v1:0')).toBeNull()
984 // An unknown geography is not a maker.
985 expect(upstream('me.anthropic.claude-opus-5')).toBeNull()
986 expect(upstream('mx.amazon.nova-pro-v1:0')).toBeNull()
987 // Every id the card parser emits from the fixture card.
988 const source = { url: BEDROCK_CARDS_URL, hash: 'h', extractedAt: 'now' }
989 const parsed = [
990 parseBedrockCard(SONNET, source),
991 ...parseBedrockProfileRows(SONNET, source),
992 ].map((row) => (row ? upstream(row.rawId) : null))
993 expect(parsed).toEqual(
994 Array(4).fill('anthropic/claude-sonnet-4-5-20250929'),
995 )
996 expect(upstream('eu.amazon.nova-lite-v1:0')).toBeNull()
997 expect(provider.upstreamModelIdentity?.('openai.gpt-5.5')?.source).toEqual({
998 derivation: 'docs-derived',
999 sourceUrl: BEDROCK_CARDS_URL,
1000 path: 'Programmatic Access: Model ID',
1001 })
1002 })
1003})