core: OpenRouter BYOK sessions record cost = 0 since v2.2.0 (ignores cost_details.upstream_inference_cost)
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
Issue では packages/ai でのコスト解析と session_message および session_v2 への永続化が指摘されています。まず、OpenRouter のストリーミング使用量から cost が読み取られる箇所を追跡してください。is_byok が true で cost がゼロの場合に、cost_details.upstream_inference_cost とカタログ価格がどのように扱われるかを確認してください。BYOK の使用記録にゼロではなく、上流またはカタログのコストが記録されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- Configure
openrouterwith BYOK enabled on OpenRouter (e.g. Google AI Studio or OpenAI key). - Run a session in OpenCode
>= 2.2.0(e.g.openrouter/google/gemini-4-argonoropenrouter/openai/gpt-6.1-sol). - 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/aionly parsesusage.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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
anomalyco/opencode のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
anomalyco/opencode#60541 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
anomalyco/opencode#60529 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
anomalyco/opencode#60469 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
TUI permission prompt for MCP tools doesn't show the call arguments対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
anomalyco/opencode#60350 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
reproduced
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
anomalyco/opencode#60306 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
anomalyco/opencode の issue をすべて見る
似ている issue
-
bug triage
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
hemi-earn
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
vetro-protocol/vetro-monorepo#1043 ·
メンテナーはふだん 1 日以内に返信
-
stage 2: bare names resolve against PATH differently from the shell (empty and relative entries)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
STRML/omp-classifier#206 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
atlassian-labs/mermaid-diagrams-viewer#188 ·
メンテナーはふだん 1 日以内に返信
-
dashboard enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Olanetsoft/agent-lookout#225 ·
メンテナーはふだん 1 日以内に返信