mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
fix(usage): avoid cross-provider pricing fallback
This commit is contained in:
@@ -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[] {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user