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("prices a bracketed context-tier variant at the base model's rate", () => {
35 const table = parseRateTable({ "claude-fable-5-1": rate(1e-5, 2.5e-7) });
36
37 expect(lookupRate(table, "claude-fable-5-1[1m]")).toEqual(
38 lookupRate(table, "claude-fable-5-1"),
39 );
40 expect(lookupRate(table, "anthropic/Claude-Fable-5-1[1m]")).toBeNull();
41 });
42
43 it("adds a bare alias when every qualified entry has the same rate", () => {
44 const table = parseRateTable({
45 "provider-a/example-model": rate(1),
46 "provider-b/example-model": rate(1),
47 });
48
49 expect(lookupRate(table, "example-model")).toEqual(
50 lookupRate(table, "provider-a/example-model"),
51 );
52 });
53
54 it("leaves an ambiguous bare name unpriced", () => {
55 const table = parseRateTable({
56 "provider-a/example-model": rate(1),
57 "provider-b/example-model": rate(3),
58 });
59
60 expect(lookupRate(table, "provider-a/example-model")?.inputCostPerToken).toBe(1);
61 expect(lookupRate(table, "provider-b/example-model")?.inputCostPerToken).toBe(3);
62 expect(lookupRate(table, "example-model")).toBeNull();
63 });
64});