Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/server/providers/adapters/amazon-bedrock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,71 @@ describe('amazon-bedrock', () => {
)
})

it('clears an Anthropic chat model the pricing page no longer names', async () => {
const dropped = (title: string, rawId: string) =>
SONNET.replace('# Claude Sonnet 4.5', `# ${title}`).replaceAll(
'anthropic.claude-sonnet-4-5-20250929-v1:0',
rawId,
)
serve({
...PAGES,
[BEDROCK_CARDS_URL]: `# Models at a glance
| Logo | Provider | Supported models |
| --- | --- | --- |
| x | [Anthropic](model-cards-anthropic.md) | [Claude Haiku 4.5](model-card-anthropic-claude-haiku-4-5.md), [Claude Sonnet 4.5](model-card-anthropic-claude-sonnet-4-5.md), [Claude Sonnet 4](model-card-anthropic-claude-sonnet-4.md), [Claude 3 Haiku](model-card-anthropic-claude-3-haiku.md) |
`,
[`${DOCS}model-card-anthropic-claude-haiku-4-5.md`]: dropped(
'Claude Haiku 4.5',
'anthropic.claude-haiku-4-5-20251001-v1:0',
),
[`${DOCS}model-card-anthropic-claude-sonnet-4-5.md`]: dropped(
'Claude Sonnet 4.5',
'anthropic.claude-sonnet-4-5-20250929-v1:0',
),
[`${DOCS}model-card-anthropic-claude-sonnet-4.md`]: dropped(
'Claude Sonnet 4',
'anthropic.claude-sonnet-4-20250514-v1:0',
),
[`${DOCS}model-card-anthropic-claude-3-haiku.md`]: dropped(
'Claude 3 Haiku',
'anthropic.claude-3-haiku-20240307-v1:0',
),
[BEDROCK_PRICING_PAGE_URL]: `<h2>Pricing examples</h2>
<h3>Model evaluation example 1:</h3>
<table><tr><th>Item</th><th>Price per 1M input tokens</th><th>Price per 1M output tokens</th></tr>
<tr><td>Claude 3 Haiku</td><td>$0.25</td><td>$1.25</td></tr></table>
<h2>Anthropic</h2>
<table><tr><th>Anthropic models</th><th>Price per 1M input tokens</th><th>Price per 1M output tokens</th></tr>
<tr><td>Claude Haiku 4.5</td><td>$1.00</td><td>$5.00</td></tr>
<tr><td>Claude Sonnet 4.5</td><td>{priceOf!bedrock/bedrock!missing}</td><td>{priceOf!bedrock/bedrock!missing}</td></tr>
</table>`,
})
const { models } = await provider.listModels({})
const row = (rawId: string) => models.find((model) => model.rawId === rawId)
const haiku = row('anthropic.claude-haiku-4-5-20251001-v1:0')
expect(
price(
haiku?.pricing as RateCard,
{},
{ input_tokens: 1e6, output_tokens: 1e6 },
),
).toBeCloseTo(6)
expect(haiku?.absent?.pricing).toBeUndefined()
// Still named in the table; the meter did not resolve. Keep a stored card.
const stillNamed = row('anthropic.claude-sonnet-4-5-20250929-v1:0')
expect(stillNamed?.pricing).toBeNull()
expect(stillNamed?.absent?.pricing).toBeUndefined()
for (const rawId of [
'anthropic.claude-sonnet-4-20250514-v1:0',
'anthropic.claude-3-haiku-20240307-v1:0',
]) {
expect(row(rawId)).toMatchObject({
pricing: null,
absent: { pricing: 'cleared' },
})
}
})

it('fails the poll when most cards stop stating a model id', async () => {
const blank = '# Card\n'
serve({
Expand Down
28 changes: 25 additions & 3 deletions src/server/providers/bedrock-cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* inference-profile ids, limits, modalities, lifecycle, and reasoning. A few
* cards (OpenAI, xAI, Moonshot) also state token prices. A card with no
* dollars is filled from the AWS price list, then the pricing page
* (`bedrock-pricing.ts`). Every card is fetched as the `.md` twin AWS
* publishes next to the HTML.
* (`bedrock-pricing.ts`). An Anthropic chat model the page's Claude
* tables do not name is cleared: the row was removed, and a stored
* card must not be kept. A name the table still lists, with a meter
* that does not resolve, stays a parser miss. Every card is fetched
* as the `.md` twin AWS publishes next to the HTML.
*/
import { compileTokenCard } from '@modelschemas/rate-card'
import type { TokenRateTier } from '@modelschemas/rate-card'
Expand Down Expand Up @@ -641,7 +644,26 @@ export async function bedrockCardListing(
model.rawId,
model.displayName ?? null,
)
if (!hit) continue
if (!hit) {
// The Claude tables parsed, and this name is not in them. EOL
// rows (Claude Sonnet 4, Claude 3 Haiku) left the page; the
// us-east-1 offer has no complete rate either (#775).
const mentioned = book.pageMentioned
const name = bedrockNameKey(model.displayName ?? '')
const claudeTablesRead = [...(mentioned ?? [])].some((key) =>
key.startsWith('claude '),
)
if (
model.activity === 'chat' &&
model.rawId.startsWith('anthropic.') &&
name.startsWith('claude ') &&
claudeTablesRead &&
mentioned?.has(name) === false
) {
model.absent = { ...model.absent, pricing: 'cleared' }
}
continue
}
const pricing = compileTokenCard(hit.rates, [], {
url: hit.url,
hash: hit.hash,
Expand Down
27 changes: 27 additions & 0 deletions src/server/providers/bedrock-pricing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,30 @@ it('resolves Global prices from provider-published encoded public meter paths',
),
).toEqual({ input_tokens: 7 / 1e6, output_tokens: 19 / 1e6 })
})

it('remembers a Claude row whose meter does not resolve, and ignores example prose', () => {
const html = `<h2>Pricing examples</h2>
<h3>Model evaluation example 1:</h3>
<table><tr><th>Item</th><th>Price per 1M input tokens</th><th>Price per 1M output tokens</th></tr>
<tr><td>Claude 3 Haiku</td><td>$0.25</td><td>$1.25</td></tr></table>
<h2>Anthropic</h2>
<table><tr><th>Anthropic models</th><th>Price per 1M input tokens</th><th>Price per 1M output tokens</th></tr>
<tr><td>Claude Haiku 4.5</td><td>$1</td><td>$5</td></tr>
<tr><td>Claude Sonnet 4.5</td><td>{priceOf!bedrock/bedrock!missing}</td><td>{priceOf!bedrock/bedrock!missing}</td></tr>
</table>`
const mentioned = new Set<string>()
const page = parseBedrockPricingPage(
html,
{ regions: { 'US East (N. Virginia)': {} } },
'regional',
mentioned,
)
expect(page.get(bedrockNameKey('Claude Haiku 4.5'))).toEqual({
input_tokens: 1 / 1e6,
output_tokens: 5 / 1e6,
})
expect(page.has(bedrockNameKey('Claude Sonnet 4.5'))).toBe(false)
expect(mentioned.has(bedrockNameKey('Claude Sonnet 4.5'))).toBe(true)
expect(mentioned.has(bedrockNameKey('Claude 3 Haiku'))).toBe(false)
expect(mentioned.has(bedrockNameKey('Claude Sonnet 4'))).toBe(false)
})
20 changes: 18 additions & 2 deletions src/server/providers/bedrock-pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export interface BedrockPriceBook {
pageByName: Map<string, Record<string, number>>
/** Only prices explicitly published for global cross-region inference. */
globalPageByName?: Map<string, Record<string, number>>
/**
* Model names in a standard token table, including a row whose meter
* did not resolve. A name that is absent was removed, not misread.
*/
pageMentioned?: Set<string>
offerHash: string
pageHash: string
}
Expand Down Expand Up @@ -370,6 +375,7 @@ export function parseBedrockPricingPage(
html: string,
meter: MeterFile,
scope: 'regional' | 'global' = 'regional',
mentioned?: Set<string>,
): Map<string, Record<string, number>> {
const region = meter.regions?.[USE1]
if (!region) {
Expand Down Expand Up @@ -440,6 +446,8 @@ export function parseBedrockPricingPage(
}
// A tab names the model. Rows are tiers. US CRIS is the standard rate.
if (head.some((cell) => /inference option/i.test(cell))) {
const labelKey = bedrockNameKey(pendingLabel)
if (labelKey) mentioned?.add(labelKey)
const chosen = rows.slice(1).find((row) => {
const tier = row[0] ?? ''
return scope === 'global'
Expand All @@ -465,6 +473,7 @@ export function parseBedrockPricingPage(
if (!name || /long context/i.test(name)) continue
const rates = ratesOf(row)
const key = bedrockNameKey(name)
if (key) mentioned?.add(key)
if (scope === 'global' && !complete(rates)) {
throw new Error(
`amazon-bedrock global pricing: unreadable quote ${key}`,
Expand Down Expand Up @@ -568,14 +577,21 @@ export async function fetchBedrockPriceBook(): Promise<BedrockPriceBook> {
])
const offer = parseBedrockOffer(JSON.parse(offerText) as OfferFile)
const meter = JSON.parse(meterText) as MeterFile
const page = parseBedrockPricingPage(html, meter)
const globalPage = parseBedrockPricingPage(html, meter, 'global')
const pageMentioned = new Set<string>()
const page = parseBedrockPricingPage(html, meter, 'regional', pageMentioned)
const globalPage = parseBedrockPricingPage(
html,
meter,
'global',
pageMentioned,
)
return {
offerById: offer.byId,
offerByName: offer.byName,
offerBySlug: offer.bySlug,
pageByName: page,
globalPageByName: globalPage,
pageMentioned,
offerHash: await sha256Text(offerText),
pageHash: await sha256Text(`${html}\n${meterText}`),
}
Expand Down
Loading