[PR #9518] feat: for openrouter session uses cost from metadata #13137

Open
opened 2026-02-16 18:18:00 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9518

State: open
Merged: No


What does this PR do?

It takes cost of the message from provider's metadata for openrouter.
If there is no cost in metadata, it calculates it in an old way based on price and used tokens.

How did you verify your code works?

  1. Added log.info("***** use metadata cost: ${usage.cost}") to packages/opencode/src/session/index.ts:419
  2. bun dev web
  3. opened a project, sent message to chat
  4. Found INFO 2026-01-19T22:41:13 +0ms service=session ***** use metadata cost: 0.00073491 in logs (~/.local/share/opencode/log/dev.log)
  5. Verified cost in web: image
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9518 **State:** open **Merged:** No --- ### What does this PR do? It takes cost of the message from provider's metadata for openrouter. If there is no cost in metadata, it calculates it in an old way based on price and used tokens. ### How did you verify your code works? 1) Added `log.info("***** use metadata cost: ${usage.cost}")` to packages/opencode/src/session/index.ts:419 2) `bun dev web` 3) opened a project, sent message to chat 4) Found `INFO 2026-01-19T22:41:13 +0ms service=session ***** use metadata cost: 0.00073491` in logs (~/.local/share/opencode/log/dev.log) 5) Verified cost in web: <img width="258" height="236" alt="image" src="https://github.com/user-attachments/assets/93e49ab3-0696-44b2-9a4f-a80b775e9062" />
yindo added the pull-request label 2026-02-16 18:18:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13137