MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / extractUsageAndCost

Function extractUsageAndCost

web/src/llm-api/openrouter.ts:101–115  ·  view source on GitHub ↗
(usage: any)

Source from the content-addressed store, hash-verified

99 * See: investigation notes + scripts/refund-openrouter-overcharge.ts
100 */
101export function extractUsageAndCost(usage: any): UsageData {
102 const openRouterCost =
103 typeof usage?.cost === 'number' ? usage.cost : 0
104 const upstreamCost =
105 typeof usage?.cost_details?.upstream_inference_cost === 'number'
106 ? usage.cost_details.upstream_inference_cost
107 : 0
108 return {
109 inputTokens: usage?.prompt_tokens ?? 0,
110 outputTokens: usage?.completion_tokens ?? 0,
111 cacheReadInputTokens: usage?.prompt_tokens_details?.cached_tokens ?? 0,
112 reasoningTokens: usage?.completion_tokens_details?.reasoning_tokens ?? 0,
113 cost: Math.max(openRouterCost, upstreamCost),
114 }
115}
116
117function extractRequestMetadataWithN(params: {
118 body: unknown

Callers 3

openrouter.test.tsFile · 0.90
handleResponseFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected