Skip to content

Add typed Copilot billing usage to the V2 runtime #35765

Closed

Description

@rekram1-node

Summary

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.
  • Cover successful and settled-failure steps.

Related

Activity

  1. added
    enhancementNew feature or request
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Jul 7, 2026
  2. opencode-agent commented on Jul 8, 2026

    @opencode-agent
    Contributor

    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.

  3. opencodejr commented on Oct 28, 2026

    @opencodejr

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.0coreAnything pertaining to core functionality of the application (opencode server stuff)enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions