Skip to content
Closed
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
98 changes: 98 additions & 0 deletions apps/gateway/src/lib/costs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,104 @@ describe("calculateCosts", () => {
expect(result.cacheWriteTokens).toBe(1000);
});

it("applies AWS Bedrock 10% regional pricing but not global pricing", async () => {
const global = await calculateCosts(
"claude-opus-4-8",
"aws-bedrock",
"global",
1_000_000,
1_000_000,
null,
);

expect(global.inputCost).toBeCloseTo(5);
expect(global.outputCost).toBeCloseTo(25);

const geo = await calculateCosts(
"claude-opus-4-8",
"aws-bedrock",
"us",
1_000_000,
1_000_000,
null,
);

expect(geo.inputCost).toBeCloseTo(5.5);
expect(geo.outputCost).toBeCloseTo(27.5);

const inRegionCrossRegion = await calculateCosts(
"claude-opus-4-6",
"aws-bedrock",
"eu-west-2",
1_000_000,
1_000_000,
null,
);

expect(inRegionCrossRegion.inputCost).toBeCloseTo(5.5);
expect(inRegionCrossRegion.outputCost).toBeCloseTo(27.5);

const geoCacheWrite5m = await calculateCosts(
"claude-opus-4-8",
"aws-bedrock",
"us",
1_000_000,
0,
0,
undefined,
null,
0,
undefined,
0,
null,
null,
undefined,
null,
null,
{
cacheWriteTokens: 1_000_000,
},
);

expect(geoCacheWrite5m.cacheWriteInputCost).toBeCloseTo(6.875);

const geoCacheWrite1h = await calculateCosts(
"claude-opus-4-8",
"aws-bedrock",
"us",
1_000_000,
0,
0,
undefined,
null,
0,
undefined,
0,
null,
null,
undefined,
null,
null,
{
cacheWriteTokens: 1_000_000,
cacheWrite1hTokens: 1_000_000,
},
);

expect(geoCacheWrite1h.cacheWriteInputCost).toBeCloseTo(11);

const geoCacheRead = await calculateCosts(
"claude-opus-4-8",
"aws-bedrock",
"us",
1_000_000,
0,
1_000_000,
);

expect(geoCacheRead.cachedInputCost).toBeCloseTo(0.55);
});

it("should calculate costs with cached tokens for Anthropic (subsequent request - cache read)", async () => {
// For Anthropic subsequent request: 4 non-cached + 1659 cache read = 1663 total tokens, 1659 cache reads
const result = await calculateCosts(
Expand Down
95 changes: 94 additions & 1 deletion packages/models/src/models/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ export const anthropicModels = [
vision: false,
tools: true,
jsonOutputSchema: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "us-east-1" },
{ id: "us-east-2" },
{ id: "us-west-2" },
{ id: "eu-central-1" },
{ id: "eu-north-1" },
{ id: "eu-west-1" },
{ id: "eu-west-2" },
{ id: "eu-west-3" },
],
},
],
},
Expand Down Expand Up @@ -215,6 +228,21 @@ export const anthropicModels = [
vision: false,
tools: true,
jsonOutputSchema: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "apac" },
{ id: "us-east-1" },
{ id: "us-east-2" },
{ id: "us-west-2" },
{ id: "eu-central-1" },
{ id: "eu-west-1" },
{ id: "eu-west-3" },
{ id: "ap-northeast-1" },
{ id: "ap-northeast-2" },
{ id: "ap-southeast-1" },
],
},
],
},
Expand Down Expand Up @@ -342,6 +370,13 @@ export const anthropicModels = [
vision: false,
tools: true,
jsonOutputSchema: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "au" },
{ id: "jp" },
],
},
{
test: "skip",
Expand Down Expand Up @@ -412,6 +447,13 @@ export const anthropicModels = [
vision: false,
tools: true,
jsonOutputSchema: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "au" },
{ id: "jp" },
],
},
],
},
Expand Down Expand Up @@ -462,6 +504,14 @@ export const anthropicModels = [
vision: true,
tools: true,
jsonOutputSchema: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "au" },
{ id: "jp" },
{ id: "eu-west-2" },
],
},
{
providerId: "vertex-anthropic",
Expand Down Expand Up @@ -527,7 +577,13 @@ export const anthropicModels = [
tools: true,
jsonOutput: true,
jsonOutputSchema: true,
regions: [{ id: "global" }, { id: "us" }, { id: "eu" }, { id: "apac" }],
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "au" },
{ id: "jp" },
],
},
{
providerId: "vertex-anthropic",
Expand Down Expand Up @@ -592,6 +648,13 @@ export const anthropicModels = [
tools: true,
jsonOutput: true,
jsonOutputSchema: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "au" },
{ id: "jp" },
],
},
],
},
Expand Down Expand Up @@ -695,6 +758,7 @@ export const anthropicModels = [
reasoningMaxTokens: true,
tools: true,
jsonOutputSchema: true,
regions: [{ id: "us" }],
},
],
},
Expand Down Expand Up @@ -801,6 +865,13 @@ export const anthropicModels = [
vision: false,
tools: true,
jsonOutputSchema: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "us-east-1" },
{ id: "us-east-2" },
{ id: "us-west-2" },
],
},
],
},
Expand Down Expand Up @@ -936,6 +1007,7 @@ export const anthropicModels = [
vision: true,
tools: true,
jsonOutputSchema: true,
regions: [{ id: "global" }, { id: "us" }, { id: "eu" }],
},
{
test: "skip",
Expand Down Expand Up @@ -1010,6 +1082,13 @@ export const anthropicModels = [
vision: true,
tools: true,
jsonOutputSchema: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "au" },
{ id: "eu-west-2" },
],
},
{
test: "skip",
Expand Down Expand Up @@ -1084,6 +1163,13 @@ export const anthropicModels = [
streaming: true,
vision: true,
tools: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "jp" },
{ id: "au" },
],
},
{
providerId: "vertex-anthropic",
Expand Down Expand Up @@ -1155,6 +1241,13 @@ export const anthropicModels = [
streaming: true,
vision: true,
tools: true,
regions: [
{ id: "global" },
{ id: "us" },
{ id: "eu" },
{ id: "jp" },
{ id: "au" },
],
},
],
},
Expand Down
Loading
Loading