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