MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / applyLongContextPricing

Function applyLongContextPricing

src/shared/cost.ts:10–40  ·  view source on GitHub ↗
(modelInfo: ModelInfo, totalInputTokens: number, serviceTier?: ServiceTier)

Source from the content-addressed store, hash-verified

8}
9
10function 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
42function calculateApiCostInternal(
43 modelInfo: ModelInfo,

Callers 1

calculateApiCostOpenAIFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected