The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 07:00 UTC
fix(server): usage prices bare model names at the maker's rate when a reseller marks them up (#28004)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 1, 2026 at 21:33 UTC
a51164c52b12356bb10ed142a72550003ce8ddb9
2 files changed
+46
-6
apps/server/src/usage/usagePricing.test.ts
+28
@@ -258,4 +258,32 @@ describe("usage pricing", () => {
258
expect(lookupRate(table, "provider-b/example-model")?.inputCostPerToken).toBe(3);
259
expect(lookupRate(table, "example-model")).toBeNull();
260
});
261
+
262
+ it("prices a bare name at the model maker's rate when a reseller marks it up", () => {
263
+ const reseller = { "kyma/gemini-4-argon": rate(5.4e-6) };
264
+ const makers = {
265
+ "gemini/gemini-4-argon": rate(2e-6, 1e-7),
266
+ "vertex_ai/gemini-4-argon": rate(2e-6, 1e-7),
267
+ };
268
+
269
+ for (const document of [
270
+ { ...reseller, ...makers },
271
+ { ...makers, ...reseller },
272
+ ]) {
273
+ const table = parseRateTable(document);
274
+ expect(lookupRate(table, "gemini-4-argon")).toEqual(
275
+ lookupRate(table, "gemini/gemini-4-argon"),
276
+ );
277
+ }
278
+ });
279
+
280
+ it("leaves a bare name unpriced when model makers' own entries disagree", () => {
281
+ const table = parseRateTable({
282
+ "openai/example-model": rate(1),
283
+ "xai/example-model": rate(3),
284
+ "kyma/example-model": rate(1),
285
+ });
286
+
287
+ expect(lookupRate(table, "example-model")).toBeNull();
288
+ });
289
});
apps/server/src/usage/usagePricing.ts
+18
-6
@@ -89,6 +89,17 @@ function fastMultiplier(entry: LiteLlmEntry): number | null {
89
return fast !== null && fast > 0 ? fast : null;
90
}
91
92
+// LiteLLM prefixes for the model makers' own APIs; their price beats a cloud's or reseller's for a bare name.
93
+const FIRST_PARTY_PROVIDERS = new Set([
94
+ "anthropic",
95
+ "deepseek",
96
+ "gemini",
97
+ "meta",
98
+ "mistral",
99
+ "openai",
100
+ "xai",
101
+]);
102
+
103
/** Drops models missing input or output rates to avoid understating cost. */
104
export function parseRateTable(document: unknown): RateTable {
105
const table = new Map<string, ModelRate>();
@@ -113,18 +124,19 @@ export function parseRateTable(document: unknown): RateTable {
124
});
125
}
126
116
- const aliasCandidates = new Map<string, ModelRate | null>();
127
+ const aliasCandidates = new Map<string, { rate: ModelRate | null; firstParty: boolean }>();
128
for (const [key, rate] of table) {
129
const alias = bareModelName(key);
130
if (alias.length === 0 || alias === key || table.has(alias)) continue;
131
+ const firstParty = FIRST_PARTY_PROVIDERS.has(key.slice(0, key.indexOf("/")));
132
const held = aliasCandidates.get(alias);
121
- if (held === undefined) {
122
- aliasCandidates.set(alias, rate);
123
- } else if (held !== null) {
124
- aliasCandidates.set(alias, mergeAliasRate(held, rate));
133
+ if (held === undefined || (firstParty && !held.firstParty)) {
134
+ aliasCandidates.set(alias, { rate, firstParty });
135
+ } else if (held.rate !== null && firstParty === held.firstParty) {
136
+ aliasCandidates.set(alias, { rate: mergeAliasRate(held.rate, rate), firstParty });
137
}
138
}
127
- for (const [alias, rate] of aliasCandidates) {
139
+ for (const [alias, { rate }] of aliasCandidates) {
140
if (rate !== null) table.set(alias, rate);
141
}
142