Skip to content

Commit 0ca73a1

Browse files
fix(server): usage prices Claude Mythos 5.2 from its Bedrock rate (pingdotgg#33721)
1 parent b48b8ea commit 0ca73a1

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎apps/server/src/usage/usagePricing.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,37 @@ describe("usage pricing", () => {
277277
}
278278
});
279279

280+
it("prices a bare name listed only under Bedrock IDs at the base anthropic rate", () => {
281+
const bedrock = (input: number, output: number, cacheRead: number, cacheCreation: number) => ({
282+
input_cost_per_token: input,
283+
output_cost_per_token: output,
284+
cache_read_input_token_cost: cacheRead,
285+
cache_creation_input_token_cost: cacheCreation,
286+
});
287+
const base = bedrock(8e-6, 4e-5, 2e-7, 1e-5);
288+
const regional = bedrock(8.8e-6, 4.4e-5, 2.2e-7, 1.1e-5);
289+
const govCloud = bedrock(9.6e-6, 4.8e-5, 2.4e-7, 1.2e-5);
290+
const rows = [
291+
["anthropic.claude-mythos-5-2", base],
292+
["global.anthropic.claude-mythos-5-2", base],
293+
["us.anthropic.claude-mythos-5-2", regional],
294+
["eu.anthropic.claude-mythos-5-2", regional],
295+
["us-gov.anthropic.claude-mythos-5-2", govCloud],
296+
["bedrock/us-gov-east-1/anthropic.claude-mythos-5-2", govCloud],
297+
["bedrock/us-gov-west-1/anthropic.claude-mythos-5-2", govCloud],
298+
] as const;
299+
300+
for (const entries of [rows, rows.toReversed()]) {
301+
const table = parseRateTable(Object.fromEntries(entries));
302+
expect(lookupRate(table, "claude-mythos-5-2")).toMatchObject({
303+
inputCostPerToken: 8e-6,
304+
outputCostPerToken: 4e-5,
305+
cacheReadCostPerToken: 2e-7,
306+
cacheCreationCostPerToken: 1e-5,
307+
});
308+
}
309+
});
310+
280311
it("leaves a bare name unpriced when model makers' own entries disagree", () => {
281312
const table = parseRateTable({
282313
"openai/example-model": rate(1),

‎apps/server/src/usage/usagePricing.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ export function parseRateTable(document: unknown): RateTable {
126126

127127
const aliasCandidates = new Map<string, { rate: ModelRate | null; firstParty: boolean }>();
128128
for (const [key, rate] of table) {
129-
const alias = bareModelName(key);
129+
const slash = key.indexOf("/");
130+
const alias = slash === -1 ? bedrockBaseModelName(key) : bareModelName(key);
130131
if (alias.length === 0 || alias === key || table.has(alias)) continue;
131-
const firstParty = FIRST_PARTY_PROVIDERS.has(key.slice(0, key.indexOf("/")));
132+
const firstParty = slash !== -1 && FIRST_PARTY_PROVIDERS.has(key.slice(0, slash));
132133
const held = aliasCandidates.get(alias);
133134
if (held === undefined || (firstParty && !held.firstParty)) {
134135
aliasCandidates.set(alias, { rate, firstParty });
@@ -180,6 +181,11 @@ function bareModelName(key: string): string {
180181
return slash === -1 ? key : key.slice(slash + 1);
181182
}
182183

184+
// Only Bedrock's base ID gives a bare alias; its regional (us., eu.) and GovCloud IDs carry markups.
185+
function bedrockBaseModelName(key: string): string {
186+
return key.startsWith("anthropic.") ? key.slice("anthropic.".length) : key;
187+
}
188+
183189
// Price Claude's bracketed context variants at the base tier, the only name the rate table knows.
184190
function stripVariantSuffix(key: string): string {
185191
const bracket = key.indexOf("[");

0 commit comments

Comments
 (0)