Skip to content

Commit 54645fc

Browse files
t3dotggclaude
andcommitted
fix(usage): price Gemini 4 Argon usage from Antigravity
Bare model aliases no longer drop when a reseller entry omits a speed tier, and Antigravity ACP thinking-level suffixes price at the base model rate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5d5b6e0 commit 54645fc

4 files changed

Lines changed: 66 additions & 9 deletions

File tree

‎apps/server/src/provider/Drivers/antigravityUsageReader.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,36 @@ describe("readAntigravityUsage", () => {
162162
}).pipe(Effect.provide(NodeServices.layer)),
163163
);
164164

165+
it.effect("prices ACP effort variants at the base model rate", () =>
166+
Effect.gen(function* () {
167+
const path = yield* Path.Path;
168+
const dir = yield* tempDir;
169+
yield* seedDatabase(path.join(dir, "effort.db"), (db) =>
170+
Effect.gen(function* () {
171+
yield* createTables(db);
172+
for (const [idx, name] of ["gemini-4-argon-high", "gemini-4-argon"].entries()) {
173+
yield* db.run("INSERT INTO gen_metadata VALUES (?, ?)", [
174+
idx,
175+
new Uint8Array(protoBytes(1, protoText(19, name))),
176+
]);
177+
yield* db.run("INSERT INTO steps VALUES (?, ?)", [
178+
idx,
179+
new Uint8Array(protoBytes(9, protoNumber(2, 10 + idx))),
180+
]);
181+
}
182+
}),
183+
);
184+
const result = yield* readAntigravityUsage(dir, 0);
185+
assert.deepStrictEqual(
186+
records(result).map(({ model, rateModel }) => [model, rateModel]),
187+
[
188+
["gemini-4-argon-high", "gemini-4-argon"],
189+
["gemini-4-argon", undefined],
190+
],
191+
);
192+
}).pipe(Effect.provide(NodeServices.layer)),
193+
);
194+
165195
it.effect("merges Antigravity aliases that bridge previously separate step records", () =>
166196
Effect.gen(function* () {
167197
const path = yield* Path.Path;

‎apps/server/src/provider/Drivers/antigravityUsageReader.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ const MODEL_IDS: Record<number, string> = {
101101
1047: "gemini-3-flash-preview",
102102
};
103103

104+
// ACP slugs append the thinking level, which shares the base model's price.
105+
function withRateModel(record: UsageRecord): UsageRecord {
106+
const rateModel = record.model.replace(/-(?:low|medium|high)$/, "");
107+
return rateModel === record.model ? record : { ...record, rateModel };
108+
}
109+
104110
function modelName(name: string, id: number): string {
105111
if (name) {
106112
const normalized = name
@@ -470,7 +476,7 @@ export const readAntigravityUsage = Effect.fn("readAntigravityUsage")(function*
470476
}
471477
for (const [index, group] of groups.entries()) {
472478
if (group.parent === index && group.record.timestampMs >= sinceMs) {
473-
files[group.fileIndex]!.records.push(group.record);
479+
files[group.fileIndex]!.records.push(withRateModel(group.record));
474480
}
475481
}
476482
return { files, errors };

‎apps/server/src/usage/usagePricing.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,21 @@ describe("usage pricing", () => {
233233
);
234234
});
235235

236+
it("keeps a bare alias when a reseller entry omits the fast tier", () => {
237+
const table = parseRateTable({
238+
"provider-a/example-model": {
239+
...rate(1),
240+
input_cost_per_token_priority: 2,
241+
output_cost_per_token_priority: 10,
242+
},
243+
"provider-b/example-model": rate(1),
244+
});
245+
246+
expect(lookupRate(table, "example-model")).toEqual(
247+
lookupRate(table, "provider-a/example-model"),
248+
);
249+
});
250+
236251
it("leaves an ambiguous bare name unpriced", () => {
237252
const table = parseRateTable({
238253
"provider-a/example-model": rate(1),

‎apps/server/src/usage/usagePricing.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export function parseRateTable(document: unknown): RateTable {
120120
const held = aliasCandidates.get(alias);
121121
if (held === undefined) {
122122
aliasCandidates.set(alias, rate);
123-
} else if (held !== null && !sameRate(held, rate)) {
124-
aliasCandidates.set(alias, null);
123+
} else if (held !== null) {
124+
aliasCandidates.set(alias, mergeAliasRate(held, rate));
125125
}
126126
}
127127
for (const [alias, rate] of aliasCandidates) {
@@ -141,12 +141,18 @@ function sameTokenRates(a: TokenRates | null, b: TokenRates | null): boolean {
141141
);
142142
}
143143

144-
function sameRate(a: ModelRate, b: ModelRate): boolean {
145-
return (
146-
sameTokenRates(a, b) &&
147-
sameTokenRates(a.fast, b.fast) &&
148-
sameTokenRates(a.ultrafast, b.ultrafast)
149-
);
144+
// Resellers often omit speed tiers, so a missing tier fills from the other entry instead of conflicting.
145+
function mergeAliasRate(a: ModelRate, b: ModelRate): ModelRate | null {
146+
const fast = a.fast ?? b.fast;
147+
const ultrafast = a.ultrafast ?? b.ultrafast;
148+
if (
149+
!sameTokenRates(a, b) ||
150+
!sameTokenRates(fast, b.fast ?? fast) ||
151+
!sameTokenRates(ultrafast, b.ultrafast ?? ultrafast)
152+
) {
153+
return null;
154+
}
155+
return { ...a, fast, ultrafast };
150156
}
151157

152158
function ratesAt(rate: ModelRate, speed: UsageSpeed): TokenRates {

0 commit comments

Comments
 (0)