Open History to see the last commit
1import { describe, expect, it } from "@effect/vitest";
2
3import { lookupRate, normalizeModelName, parseRateTable } from "./usagePricing.ts";
4
5const rate = (input: number, cacheRead?: number) => ({
6 input_cost_per_token: input,
7 output_cost_per_token: input * 5,
8 ...(cacheRead === undefined ? {} : { cache_read_input_token_cost: cacheRead }),
9});
10
11describe("usage pricing", () => {
12 it("keeps the existing model-name normalization contract", () => {
13 expect(normalizeModelName(" Anthropic/Claude-Opus-5 ")).toBe("claude-opus-5");
14 });
15
16 it("keeps the canonical Fable rate separate from DeepInfra in either order", () => {
17 const canonical = ["claude-fable-5", rate(1e-5, 1e-6)] as const;
18 const deepInfra = ["deepinfra/anthropic/claude-fable-5", rate(1e-5)] as const;
19
20 for (const entries of [
21 [canonical, deepInfra],
22 [deepInfra, canonical],
23 ]) {
24 const table = parseRateTable(Object.fromEntries(entries));
25
26 expect(lookupRate(table, "claude-fable-5")?.cacheReadCostPerToken).toBe(1e-6);
27 expect(lookupRate(table, "deepinfra/anthropic/claude-fable-5")?.cacheReadCostPerToken).toBe(
28 1e-5,
29 );
30 expect(lookupRate(table, "other/claude-fable-5")).toBeNull();
31 }
32 });
33
34 it("adds a bare alias when every qualified entry has the same rate", () => {
35 const table = parseRateTable({
36 "provider-a/example-model": rate(1),
37 "provider-b/example-model": rate(1),
38 });
39
40 expect(lookupRate(table, "example-model")).toEqual(
41 lookupRate(table, "provider-a/example-model"),
42 );
43 });
44
45 it("leaves an ambiguous bare name unpriced", () => {
46 const table = parseRateTable({
47 "provider-a/example-model": rate(1),
48 "provider-b/example-model": rate(3),
49 });
50
51 expect(lookupRate(table, "provider-a/example-model")?.inputCostPerToken).toBe(1);
52 expect(lookupRate(table, "provider-b/example-model")?.inputCostPerToken).toBe(3);
53 expect(lookupRate(table, "example-model")).toBeNull();
54 });
55});