You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add typed Copilot billing usage to the V2 runtime #35765
V2 calculates step cost from normalized tokens and catalog pricing, but it intentionally does not consume Copilot's provider-reported billed amount. Copilot currently exposes copilot_usage.total_nano_aiu through raw AI SDK provider chunks, and carrying arbitrary ProviderMetadata through the SessionRunner settlement solely for this value is the wrong contract.
Add a dedicated typed runtime contract for provider-reported billing, then use it for Copilot cost accounting.
Current behavior
V2 uses token-based catalog pricing for step cost.
Copilot's total_nano_aiu is not used by V2.
The SessionRunner does not retain generic provider metadata in its in-memory step settlement.
The current code leaves this TODO: Use Copilot's reported billed amount once billing has a dedicated typed runtime contract.
Expected behavior
Normalize provider-reported billing through a dedicated typed field in @opencode-ai/llm.
Bridge Copilot's raw copilot_usage.total_nano_aiu into that field at the provider/runtime boundary.
Prefer the reported billed amount when present.
Fall back to token-based catalog pricing when provider billing is unavailable.
Do not carry arbitrary provider metadata through SessionRunner settlements for billing.
Audit update (2026-07-08): this is now the focused remaining Copilot provider-reported billing slice after #35468 landed general V2 usage/cost accounting. Currently unassigned.
Thanks for opening this. I checked the latest dev (77a0fd6) and the code works as currently designed:
In packages/core/src/session/usage.ts, SessionUsage.record() already prefers Usage.cost when an endpoint reports it. Otherwise it falls back to catalog pricing in calculateCost(), which carries TODO(#35765) for normalizing Copilot's billed amount.
In packages/ai/src/protocols/shared.ts, ReportedBilling only decodes a USD cost field (OpenRouter, LiteLLM, OpenCode Zen). Nothing reads copilot_usage.total_nano_aiu yet.
So Copilot steps are priced from tokens and the catalog on purpose, as the issue's current-behavior section says. I didn't run anything: the behavior follows from the code, and seeing Copilot's billing would need a real Copilot account. I'm not treating this as a reproducible bug; it reads as planned work. The existing Usage.cost / ReportedBilling path looks like the natural place for the typed contract, with a bridge from nano-AIU to the reported amount at the Copilot provider boundary.
Activity
opencode-agent commentedon Jul 8, 2026
Audit update (2026-07-08): this is now the focused remaining Copilot provider-reported billing slice after #35468 landed general V2 usage/cost accounting. Currently unassigned.
opencodejr commentedon Oct 28, 2026
Thanks for opening this. I checked the latest
dev(77a0fd6) and the code works as currently designed:packages/core/src/session/usage.ts,SessionUsage.record()already prefersUsage.costwhen an endpoint reports it. Otherwise it falls back to catalog pricing incalculateCost(), which carriesTODO(#35765)for normalizing Copilot's billed amount.packages/ai/src/protocols/shared.ts,ReportedBillingonly decodes a USDcostfield (OpenRouter, LiteLLM, OpenCode Zen). Nothing readscopilot_usage.total_nano_aiuyet.So Copilot steps are priced from tokens and the catalog on purpose, as the issue's current-behavior section says. I didn't run anything: the behavior follows from the code, and seeing Copilot's billing would need a real Copilot account. I'm not treating this as a reproducible bug; it reads as planned work. The existing
Usage.cost/ReportedBillingpath looks like the natural place for the typed contract, with a bridge from nano-AIU to the reported amount at the Copilot provider boundary.