Skip to content

[AISAGE-733] fix(ai-gateway): stop warning about expected BYOK transcription cost mismatches - #8961

Merged
chrarnoldus merged 1 commit into
mainfrom
fix/byok-generation-cost-warning
Oct 27, 2026
Merged

chrarnoldus merged 1 commit into
mainfrom
fix/byok-generation-cost-warning

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Summary

processTokenData warns Cost from provider generation lookup differs from cost computed from response usage data whenever the OpenRouter/Vercel generation lookup cost differs from the response-derived cost, and then bills the generation cost.

OpenRouter BYOK transcriptions report only usage.cost, without is_byok or cost_details, so that cost is just OpenRouter's 5% BYOK fee (see parseTranscriptionUsageFromResponse in llm-proxy-helpers.ts, #8877). The generation lookup reports is_byok: true and the full upstream cost, so every successful BYOK transcription logged this warning with a roughly 20× mismatch (for example { generation: 467, response: 23 } for mistralai/voxtral-small-transcribe-3-0). Billing was already correct; the warning was noise that looked like a billing bug.

This skips the warning only when the response did not report BYOK status (is_byok == null) and the generation lookup reports is_byok === true. All other mismatches still warn. The billed cost and the SUSPICIOUS: OpenRouter generation lookup failed... path are unchanged.

Verification

  • pnpm --filter web test -- ../../packages/web-shared/src/lib/ai-gateway/processUsage.test.ts (90 passed), including:
    • the existing BYOK transcription test now asserts no mismatch warning
    • a new test asserting a non-BYOK generation/response mismatch still warns
  • pnpm --filter @kilocode/web-shared typecheck
  • oxlint --config .oxlintrc.json packages/web-shared/src
  • pnpm format

Models

Written with Claude Opus 5.5 (kilo/anthropic/claude-opus-5.5); no subagents were used.

@chrarnoldus chrarnoldus self-assigned this Oct 27, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The 5-line guard in processTokenData suppresses only the expected generation-vs-response cost mismatch when the response omits is_byok while the generation lookup reports BYOK, and the added tests cover both the suppressed and still-warning paths.

Assumptions: [INFERENCE] Tests and typecheck were not executed in read-only mode; assertions and billing behavior were verified by reading the source.

Files Reviewed (2 files)
  • packages/web-shared/src/lib/ai-gateway/processUsage.ts - 0 issues
  • packages/web-shared/src/lib/ai-gateway/processUsage.test.ts - 0 issues

Reviewed by deepseek-flash-latest · Input: 102.3K · Output: 12K · Cached: 740.4K

Review guidance: REVIEW.md from base branch main

@joshburt
joshburt self-requested a review October 27, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants