(provider, model string, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens int)
| 158 | } |
| 159 | |
| 160 | func 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 | |
| 194 | func computeModelInferenceAIC(provider, model string, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens int) float64 { |
| 195 | return usdToAIC(computeModelInferenceCostUSD(provider, model, inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens)) |
no test coverage detected