Skip to content
Open
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
42 changes: 42 additions & 0 deletions apps/server/src/usage/usagePricing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, expect, it } from "@effect/vitest";

import { lookupRate, type ModelRate, type RateTable } from "./usagePricing.ts";

const blueRate: ModelRate = {
inputCostPerToken: 5e-6,
outputCostPerToken: 3e-5,
cacheReadCostPerToken: 5e-7,
cacheCreationCostPerToken: 6.25e-6,
};
const redRate: ModelRate = {
inputCostPerToken: 1.25e-5,
outputCostPerToken: 7.5e-5,
cacheReadCostPerToken: 1.25e-6,
cacheCreationCostPerToken: 1.5625e-5,
};

describe("usage pricing", () => {
it("resolves Codex Daybreak rollout names to LiteLLM rates", () => {
const rates: RateTable = new Map([
["daybreak-blue-latest", blueRate],
["daybreak-red-latest", redRate],
]);

expect(lookupRate(rates, "gpt-daybreak-blue-latest")).toBe(blueRate);
expect(lookupRate(rates, "gpt-daybreak-red-latest")).toBe(redRate);
});

it("prefers an exact rate over a fallback alias", () => {
const exactRate: ModelRate = { ...blueRate, inputCostPerToken: 1 };
const rates: RateTable = new Map([
["gpt-daybreak-blue-latest", exactRate],
["daybreak-blue-latest", blueRate],
]);

expect(lookupRate(rates, "gpt-daybreak-blue-latest")).toBe(exactRate);
});

it("keeps unknown models unpriced", () => {
expect(lookupRate(new Map(), "unknown-model")).toBeNull();
});
});
16 changes: 15 additions & 1 deletion apps/server/src/usage/usagePricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,24 @@ const UNPRICEABLE_MODELS = new Set([
"fable",
]);

/**
* Codex rollout model names whose LiteLLM price entries use a different alias.
* Keep this translation at the pricing boundary so provider model selection stays unchanged.
*/
const LITELLM_RATE_ALIASES: Readonly<Record<string, string>> = {
"gpt-daybreak-blue-latest": "daybreak-blue-latest",
"gpt-daybreak-red-latest": "daybreak-red-latest",
};

export function lookupRate(table: RateTable, model: string): ModelRate | null {
const normalized = normalizeModelName(model);
if (normalized.length === 0 || UNPRICEABLE_MODELS.has(normalized)) return null;
return table.get(normalized) ?? null;

const direct = table.get(normalized);
if (direct !== undefined) return direct;

const alias = LITELLM_RATE_ALIASES[normalized];
return alias === undefined ? null : (table.get(alias) ?? null);
}

export interface PricedUsage {
Expand Down
Loading