Repository navigation
[AISAGE-733] fix(ai-gateway): only expect is_byok from upstreams that report it - #8875
Conversation
The "openrouters cost accounting doesn't make sense" check treated a cost without is_byok as broken accounting for every upstream. Probing showed which upstreams report is_byok next to cost: OpenRouter (chat completions, Messages, Responses, embeddings) and Vercel AI Gateway (chat completions). Martian reports cost but never is_byok, so every stealth-model response raised the report. Billing is unchanged.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe change threads the upstream provider through the usage parsers and scopes the Assumptions: Files Reviewed (9 files)
Reviewed by deepseek-flash-latest · Input: 72.9K · Output: 15.2K · Cached: 1.6M Review guidance: REVIEW.md from base branch |
…-byok-cost Pass providerReportsIsByok(provider) to computeOpenRouterCostFields for embeddings now that #8875 made requireIsByok a required argument.
Summary
"SUSPICIOUS: openrouters cost accounting doesn't make sense" (KILOCODE-WEB-28E4/-28D1, previously -1R) fires when a response has a
costbut nois_byok. With BYOK, OpenRouter'scostis only its 5% fee, so a cost without a BYOK status can't be trusted. But the check ran for every upstream.I sent small requests to each upstream to see which report
is_byoknext tousage.cost:costis_byokcost_details.upstream_inference_costMost events came from Martian (stealth models), which never reports
is_byok. The check now runs only for upstreams that report it (OpenRouter and Vercel), usingproviderReportsIsByok. The same gating applies to theis_byok is nullexception inparseMicrodollarUsageFromString. Billing is unchanged.OpenRouter transcriptions keep reporting here because their cost really can't be trusted. #8877 fixes that.
Split out of #8791.
Verification
pnpm --filter @kilocode/web-shared typecheckjest packages/web-shared/src/lib/ai-gateway/processUsage packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.test.ts packages/web-shared/src/lib/ai-gateway/handlers/audio-transcriptionsis_byokis still reported; Martian usage is billed at its reported cost without a report.Models: Claude Opus 5.5 (
kilo/anthropic/claude-opus-5.5), no subagents.