@@ -89,6 +89,17 @@ function fastMultiplier(entry: LiteLlmEntry): number | null {
8989 return fast !== null && fast > 0 ? fast : null ;
9090}
9191
92+ // LiteLLM prefixes for the model makers' own APIs; their price beats a cloud's or reseller's for a bare name.
93+ const FIRST_PARTY_PROVIDERS = new Set ( [
94+ "anthropic" ,
95+ "deepseek" ,
96+ "gemini" ,
97+ "meta" ,
98+ "mistral" ,
99+ "openai" ,
100+ "xai" ,
101+ ] ) ;
102+
92103/** Drops models missing input or output rates to avoid understating cost. */
93104export function parseRateTable ( document : unknown ) : RateTable {
94105 const table = new Map < string , ModelRate > ( ) ;
@@ -113,18 +124,19 @@ export function parseRateTable(document: unknown): RateTable {
113124 } ) ;
114125 }
115126
116- const aliasCandidates = new Map < string , ModelRate | null > ( ) ;
127+ const aliasCandidates = new Map < string , { rate : ModelRate | null ; firstParty : boolean } > ( ) ;
117128 for ( const [ key , rate ] of table ) {
118129 const alias = bareModelName ( key ) ;
119130 if ( alias . length === 0 || alias === key || table . has ( alias ) ) continue ;
131+ const firstParty = FIRST_PARTY_PROVIDERS . has ( key . slice ( 0 , key . indexOf ( "/" ) ) ) ;
120132 const held = aliasCandidates . get ( alias ) ;
121- if ( held === undefined ) {
122- aliasCandidates . set ( alias , rate ) ;
123- } else if ( held !== null ) {
124- aliasCandidates . set ( alias , mergeAliasRate ( held , rate ) ) ;
133+ if ( held === undefined || ( firstParty && ! held . firstParty ) ) {
134+ aliasCandidates . set ( alias , { rate, firstParty } ) ;
135+ } else if ( held . rate !== null && firstParty === held . firstParty ) {
136+ aliasCandidates . set ( alias , { rate : mergeAliasRate ( held . rate , rate ) , firstParty } ) ;
125137 }
126138 }
127- for ( const [ alias , rate ] of aliasCandidates ) {
139+ for ( const [ alias , { rate } ] of aliasCandidates ) {
128140 if ( rate !== null ) table . set ( alias , rate ) ;
129141 }
130142
0 commit comments