@@ -47,8 +47,13 @@ const FALLBACK_PRICING: Record<string, ModelCosts> = {
4747 'gpt-4.1' : { inputCostPerToken : 2e-6 , outputCostPerToken : 8e-6 , cacheWriteCostPerToken : 2e-6 , cacheReadCostPerToken : 0.5e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
4848 'gpt-4.1-mini' : { inputCostPerToken : 0.4e-6 , outputCostPerToken : 1.6e-6 , cacheWriteCostPerToken : 0.4e-6 , cacheReadCostPerToken : 0.1e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
4949 'gpt-4.1-nano' : { inputCostPerToken : 0.1e-6 , outputCostPerToken : 0.4e-6 , cacheWriteCostPerToken : 0.1e-6 , cacheReadCostPerToken : 0.025e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
50- 'o3' : { inputCostPerToken : 10e -6, outputCostPerToken : 40e -6, cacheWriteCostPerToken : 10e -6, cacheReadCostPerToken : 2 .5e-6, webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
50+ 'o3' : { inputCostPerToken : 2e -6, outputCostPerToken : 8e -6, cacheWriteCostPerToken : 2e -6, cacheReadCostPerToken : 0 .5e-6, webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
5151 'o4-mini' : { inputCostPerToken : 1.1e-6 , outputCostPerToken : 4.4e-6 , cacheWriteCostPerToken : 1.1e-6 , cacheReadCostPerToken : 0.275e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
52+ 'codex-mini-latest' : { inputCostPerToken : 1.5e-6 , outputCostPerToken : 6e-6 , cacheWriteCostPerToken : 1.5e-6 , cacheReadCostPerToken : 0.375e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
53+ 'codex-mini' : { inputCostPerToken : 1.5e-6 , outputCostPerToken : 6e-6 , cacheWriteCostPerToken : 1.5e-6 , cacheReadCostPerToken : 0.375e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
54+ 'gpt-5.1-codex' : { inputCostPerToken : 1.25e-6 , outputCostPerToken : 10e-6 , cacheWriteCostPerToken : 1.25e-6 , cacheReadCostPerToken : 0.625e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
55+ 'gpt-5.1-codex-mini' : { inputCostPerToken : 0.25e-6 , outputCostPerToken : 2e-6 , cacheWriteCostPerToken : 0.25e-6 , cacheReadCostPerToken : 0.125e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
56+ 'gpt-5.2-codex' : { inputCostPerToken : 1.75e-6 , outputCostPerToken : 14e-6 , cacheWriteCostPerToken : 1.75e-6 , cacheReadCostPerToken : 0.875e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
5257 'MiniMax-M2.7-highspeed' : { inputCostPerToken : 0.6e-6 , outputCostPerToken : 2.4e-6 , cacheWriteCostPerToken : 0.375e-6 , cacheReadCostPerToken : 0.06e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
5358 'MiniMax-M2.7' : { inputCostPerToken : 0.3e-6 , outputCostPerToken : 1.2e-6 , cacheWriteCostPerToken : 0.375e-6 , cacheReadCostPerToken : 0.06e-6 , webSearchCostPerRequest : WEB_SEARCH_COST , fastMultiplier : 1 } ,
5459}
@@ -161,11 +166,13 @@ function getCanonicalName(model: string): string {
161166export function getModelCosts ( model : string ) : ModelCosts | null {
162167 const canonical = resolveAlias ( getCanonicalName ( model ) )
163168
164- if ( pricingCache ?. has ( canonical ) ) return pricingCache . get ( canonical ) !
169+ // Our curated prices (official direct API pricing) take precedence over
170+ // LiteLLM which may return third-party provider markups (e.g. Vertex AI
171+ // charges $1/$5 for Haiku 3.5 vs Anthropic direct at $0.80/$4).
172+ // Exact matches only here — prefix matching happens below after LiteLLM.
173+ if ( Object . hasOwn ( FALLBACK_PRICING , canonical ) ) return FALLBACK_PRICING [ canonical ] !
165174
166- for ( const [ key , costs ] of Object . entries ( FALLBACK_PRICING ) ) {
167- if ( canonical === key || canonical . startsWith ( key + '-' ) ) return costs
168- }
175+ if ( pricingCache ?. has ( canonical ) ) return pricingCache . get ( canonical ) !
169176
170177 for ( const [ key , costs ] of pricingCache ?? new Map ( ) ) {
171178 if ( canonical . startsWith ( key ) ) return costs
0 commit comments