Skip to content

Commit 9c82254

Browse files
committed
fix(opencode): add model alias for gemini-3-pro-high pricing lookup
1 parent faf0f90 commit 9c82254

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

apps/opencode/src/cost-utils.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import type { LiteLLMPricingFetcher } from '@ccusage/internal/pricing';
2-
import type { LoadedUsageEntry } from './data-loader';
2+
import type { LoadedUsageEntry } from './data-loader.ts';
33
import { Result } from '@praha/byethrow';
44

5+
/**
6+
* Model aliases for OpenCode-specific model names that don't exist in LiteLLM.
7+
* Maps OpenCode model names to their LiteLLM equivalents for pricing lookup.
8+
*/
9+
const MODEL_ALIASES: Record<string, string> = {
10+
// OpenCode uses -high suffix for higher tier/thinking mode variants
11+
'gemini-3-pro-high': 'gemini-3-pro-preview',
12+
};
13+
14+
function resolveModelName(modelName: string): string {
15+
return MODEL_ALIASES[modelName] ?? modelName;
16+
}
17+
518
/**
619
* Calculate cost for a single usage entry
720
* Uses pre-calculated cost if available, otherwise calculates from tokens
@@ -14,14 +27,15 @@ export async function calculateCostForEntry(
1427
return entry.costUSD;
1528
}
1629

30+
const resolvedModel = resolveModelName(entry.model);
1731
const result = await fetcher.calculateCostFromTokens(
1832
{
1933
input_tokens: entry.usage.inputTokens,
2034
output_tokens: entry.usage.outputTokens,
2135
cache_creation_input_tokens: entry.usage.cacheCreationInputTokens,
2236
cache_read_input_tokens: entry.usage.cacheReadInputTokens,
2337
},
24-
entry.model,
38+
resolvedModel,
2539
);
2640

2741
return Result.unwrap(result, 0);

0 commit comments

Comments
 (0)