MCPcopy Create free account
hub / github.com/github/gh-aw / computeModelInferenceCostUSD

Function computeModelInferenceCostUSD

pkg/cli/model_costs.go:160–192  ·  view source on GitHub ↗
(provider, model string, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens int)

Source from the content-addressed store, hash-verified

158}
159
160func computeModelInferenceCostUSD(provider, model string, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens int) float64 {
161 pricing, ok := findModelPricing(provider, model)
162 if !ok {
163 return 0
164 }
165
166 input := inputTokens
167 cacheRead := cacheReadTokens
168 if cacheRead > 0 && providerIncludesCacheReadsInInput(strings.ToLower(strings.TrimSpace(provider))) {
169 input = max(inputTokens-cacheReadTokens, 0)
170 }
171
172 promptPrice := pricing["input"]
173 completionPrice := pricing["output"]
174 cacheReadPrice := pricing["cache_read"]
175 if cacheReadPrice == 0 {
176 cacheReadPrice = promptPrice
177 }
178 cacheWritePrice := pricing["cache_write"]
179 if cacheWritePrice == 0 {
180 cacheWritePrice = promptPrice
181 }
182 reasoningPrice := pricing["reasoning"]
183 if reasoningPrice == 0 {
184 reasoningPrice = completionPrice
185 }
186
187 return float64(input)*promptPrice +
188 float64(outputTokens)*completionPrice +
189 float64(cacheRead)*cacheReadPrice +
190 float64(cacheWriteTokens)*cacheWritePrice +
191 float64(reasoningTokens)*reasoningPrice
192}
193
194func computeModelInferenceAIC(provider, model string, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens int) float64 {
195 return usdToAIC(computeModelInferenceCostUSD(provider, model, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens))

Callers 1

computeModelInferenceAICFunction · 0.85

Calls 3

ToLowerMethod · 0.80
findModelPricingFunction · 0.70

Tested by

no test coverage detected