(usage: any)
| 99 | * See: investigation notes + scripts/refund-openrouter-overcharge.ts |
| 100 | */ |
| 101 | export 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 | |
| 117 | function extractRequestMetadataWithN(params: { |
| 118 | body: unknown |
no outgoing calls
no test coverage detected