fix(usage): avoid cross-provider pricing fallback

This commit is contained in:
Tam Nhu Tran
2026-04-28 15:55:35 -04:00
parent fc90b6f473
commit f736190196
2 changed files with 22 additions and 3 deletions
@@ -174,9 +174,11 @@ export function resolveModelsDevPricing(
const provider = options.provider ?? prefixed.provider;
const modelId = prefixed.model;
return (
resolveProviderModel(registry, provider, modelId) ?? resolveUnambiguousModel(registry, modelId)
);
if (provider) {
return resolveProviderModel(registry, provider, modelId);
}
return resolveUnambiguousModel(registry, modelId);
}
export function getKnownModelsDevModels(): string[] {
+17
View File
@@ -327,6 +327,11 @@ describe('model-pricing', () => {
name: 'GPT-5.5',
cost: { input: 5, output: 30, cache_read: 0.5 },
},
'openai-exclusive-model': {
id: 'openai-exclusive-model',
name: 'OpenAI Exclusive Model',
cost: { input: 9, output: 18 },
},
},
},
'github-copilot': {
@@ -373,6 +378,18 @@ describe('model-pricing', () => {
expect(hasCustomPricing('gpt-5.5', { provider: 'openai' })).toBe(true);
});
it('does not use another provider pricing when explicit provider lookup misses', () => {
const fallback = getModelPricing('unknown-model-xyz');
expect(getModelPricing('openai-exclusive-model', { provider: 'github-copilot' })).toEqual(
fallback
);
expect(getModelPricing('github-copilot/openai-exclusive-model')).toEqual(fallback);
expect(hasCustomPricing('openai-exclusive-model', { provider: 'github-copilot' })).toBe(
false
);
});
it('calculates cost with provider-aware models.dev pricing', () => {
const usage: TokenUsage = {
inputTokens: 1_000_000,