MCPcopy Create free account
hub / github.com/arctic-cli/interface / getModelPricing

Function getModelPricing

packages/arctic/src/provider/pricing.ts:175–246  ·  view source on GitHub ↗
(modelId: string)

Source from the content-addressed store, hash-verified

173 * Get pricing information for a specific model (sync - cached data only)
174 */
175 export function getModelPricing(modelId: string): ModelPricing | undefined {
176 const modelName = extractModelId(modelId)
177 const normalized = normalizeModelId(modelName)
178 const codexBase = codexBaseModelId(modelName)
179 const normalizedCodexBase = codexBase ? normalizeModelId(codexBase) : null
180
181 // Check fallback first
182 if (FALLBACK_PRICING[modelName]) {
183 return FALLBACK_PRICING[modelName]
184 }
185 if (FALLBACK_PRICING[normalized]) {
186 return FALLBACK_PRICING[normalized]
187 }
188 if (codexBase && FALLBACK_PRICING[codexBase]) {
189 return FALLBACK_PRICING[codexBase]
190 }
191 if (normalizedCodexBase && FALLBACK_PRICING[normalizedCodexBase]) {
192 return FALLBACK_PRICING[normalizedCodexBase]
193 }
194
195 if (!modelsDevCache) return undefined
196
197 // Search all providers for the model, prefer non-zero pricing
198 let zeroCostPricing: ModelPricing | undefined
199
200 for (const provider of Object.values(modelsDevCache.data)) {
201 // Try exact match first
202 let model = provider.models[modelName]
203 // Try normalized match if exact fails
204 if (!model) {
205 for (const [key, value] of Object.entries(provider.models)) {
206 if (normalizeModelId(key) === normalized) {
207 model = value
208 break
209 }
210 }
211 }
212 if (!model && codexBase) {
213 model = provider.models[codexBase]
214 if (!model) {
215 for (const [key, value] of Object.entries(provider.models)) {
216 if (normalizeModelId(key) === normalizedCodexBase) {
217 model = value
218 break
219 }
220 }
221 }
222 }
223
224 if (model?.cost) {
225 const pricing = {
226 input: model.cost.input,
227 output: model.cost.output,
228 cacheWrite: model.cost.cache_write,
229 cacheRead: model.cost.cache_read,
230 }
231
232 // If we find non-zero pricing, return it immediately

Callers 1

calculateCostFunction · 0.85

Calls 3

extractModelIdFunction · 0.85
normalizeModelIdFunction · 0.85
codexBaseModelIdFunction · 0.85

Tested by

no test coverage detected