Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

core: OpenRouter BYOK sessions record cost = 0 since v2.2.0 (ignores cost_details.upstream_inference_cost)

Open Beginner friendly
#60,558 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@tneemo is already working on this.

Since Oct 30, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend, databases

Research direction

The issue points to cost parsing in packages/ai and persistence in session_message and session_v2; start by tracing where OpenRouter's streaming usage cost is read. Check how cost_details.upstream_inference_cost and catalog pricing are handled when is_byok is true and cost is zero. Done means BYOK usage records the upstream or catalog cost instead of zero.

Written by the indexing model from the issue text.

Description

reproduced

Summary

Since v2.2.0 (#58562), OpenRouter sessions using BYOK (is_byok: true) record cost = 0 on every assistant message and session. For BYOK requests, OpenRouter sets usage.cost: 0 (OpenRouter's own platform fee) and puts the actual upstream API cost in usage.cost_details.upstream_inference_cost. Because usage.cost is 0 (not undefined), OpenCode records $0 instead of reading upstream_inference_cost or falling back to catalog pricing.

Environment

  • opencode version: 2.2.2 (regression started in 2.2.0)
  • OS: Linux 7.0.0-38-generic (linux x64)
  • Terminal: TERM_PROGRAM=tmux, TERM=tmux-256color, COLORTERM=truecolor
  • Shell: /bin/bash
  • Install/channel: latest
  • Active plugins: @dietrichgebert/ponytail, superpowers@git+https://github.com/obra/superpowers.git

Reproduction

  1. Configure openrouter with BYOK enabled on OpenRouter (e.g. Google AI Studio or OpenAI key).
  2. Run a session in OpenCode >= 2.2.0 (e.g. openrouter/google/gemini-4-argon or openrouter/openai/gpt-6.1-sol).
  3. Inspect the final SSE chunk from OpenRouter and the stored session cost in opencode.db.

Expected Behavior

OpenCode should account for usage.cost_details.upstream_inference_cost (e.g. usage.cost + usage.cost_details.upstream_inference_cost) when present, or fall back to catalog pricing when is_byok: true and usage.cost === 0.

Actual Behavior

OpenRouter returns the following usage payload in the final streaming chunk:

"usage": {
  "prompt_tokens": 33,
  "completion_tokens": 5,
  "total_tokens": 38,
  "cost": 0,
  "is_byok": true,
  "cost_details": {
    "upstream_inference_cost": 0.000232,
    "upstream_inference_prompt_cost": 0.000132,
    "upstream_inference_completions_cost": 0.0001
  }
}

OpenCode reads usage.cost (0), treats 0 as authoritative, and persists cost = 0 in session_message and session_v2.

Additional Context

  • Introduced by #58562 in v2.2.0 (packages/ai only parses usage.cost).
  • Up to v2.1.4, catalog pricing was used and recorded accurate non-zero costs for the same OpenRouter BYOK models.
Dominant language
TypeScript
Stars
221k
Forks
29.6k
Avg merge
7h 41m
Merged PRs (30d)
510

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from anomalyco/opencode

All issues in anomalyco/opencode

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.