(modelInfo: ModelInfo, totalInputTokens: number, serviceTier?: ServiceTier)
| 8 | } |
| 9 | |
| 10 | function applyLongContextPricing(modelInfo: ModelInfo, totalInputTokens: number, serviceTier?: ServiceTier): ModelInfo { |
| 11 | const pricing = modelInfo.longContextPricing |
| 12 | if (!pricing || totalInputTokens <= pricing.thresholdTokens) { |
| 13 | return modelInfo |
| 14 | } |
| 15 | |
| 16 | const effectiveServiceTier = serviceTier ?? "default" |
| 17 | if (pricing.appliesToServiceTiers && !pricing.appliesToServiceTiers.includes(effectiveServiceTier)) { |
| 18 | return modelInfo |
| 19 | } |
| 20 | |
| 21 | return { |
| 22 | ...modelInfo, |
| 23 | inputPrice: |
| 24 | modelInfo.inputPrice !== undefined && pricing.inputPriceMultiplier !== undefined |
| 25 | ? modelInfo.inputPrice * pricing.inputPriceMultiplier |
| 26 | : modelInfo.inputPrice, |
| 27 | outputPrice: |
| 28 | modelInfo.outputPrice !== undefined && pricing.outputPriceMultiplier !== undefined |
| 29 | ? modelInfo.outputPrice * pricing.outputPriceMultiplier |
| 30 | : modelInfo.outputPrice, |
| 31 | cacheWritesPrice: |
| 32 | modelInfo.cacheWritesPrice !== undefined && pricing.cacheWritesPriceMultiplier !== undefined |
| 33 | ? modelInfo.cacheWritesPrice * pricing.cacheWritesPriceMultiplier |
| 34 | : modelInfo.cacheWritesPrice, |
| 35 | cacheReadsPrice: |
| 36 | modelInfo.cacheReadsPrice !== undefined && pricing.cacheReadsPriceMultiplier !== undefined |
| 37 | ? modelInfo.cacheReadsPrice * pricing.cacheReadsPriceMultiplier |
| 38 | : modelInfo.cacheReadsPrice, |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | function calculateApiCostInternal( |
| 43 | modelInfo: ModelInfo, |
no outgoing calls
no test coverage detected