Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#60,558 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@tneemo がすでに取り組んでいます。

2026年10月30日 から。

  • #60588 @tneemo による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
backend, databases

調査の方向性

Issue では packages/ai でのコスト解析と session_message および session_v2 への永続化が指摘されています。まず、OpenRouter のストリーミング使用量から cost が読み取られる箇所を追跡してください。is_byok が true で cost がゼロの場合に、cost_details.upstream_inference_cost とカタログ価格がどのように扱われるかを確認してください。BYOK の使用記録にゼロではなく、上流またはカタログのコストが記録されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
TypeScript
スター
221k
フォーク
29.6k
平均マージ
7時間 41分
マージ済み PR(30日)
510

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

anomalyco/opencode のほかの issue

anomalyco/opencode の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。