Skip to content

fix(core): account for reported Copilot billing - #52556

Closed
535628443 wants to merge 1 commit into
anomalyco:devfrom
535628443:copilot-billing
Closed

535628443 wants to merge 1 commit into
anomalyco:devfrom
535628443:copilot-billing

Conversation

@535628443

@535628443 535628443 commented Oct 1, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #35765

V2 issue linking: This PR targets v2 per its contribution guide. GitHub closing links only apply to the default branch (dev), so the standards workflow flags this existing reference. A maintainer needs to link #35765 manually in Development.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

V2 currently discards Copilot's reported charge and estimates cost from catalog token prices. Add a dedicated Usage.billedCost field, branded as USD and restricted to finite nonnegative amounts.

The AI SDK bridge requests Copilot raw chunks and reads copilot_usage.total_nano_aiu from Chat chunks or the nested Responses response. It uses the existing Copilot conversion of 100 billion nano AIU per USD, retains the latest valid charge per physical request, and emits it in normalized usage. Other providers' raw chunks remain unaffected.

Session step settlement retains only that typed charge alongside normalized tokens, then prefers it over the catalog estimate for both successful and settled-failure steps. Zero is a valid reported charge; absent or malformed billing keeps the existing estimate. No arbitrary provider metadata is added to the step settlement.

How did you verify your code works?

  • Core: 304 passing tests across test/aisdk.test.ts, test/session-runner.test.ts, and test/session-runner-tool-events.test.ts; a subsequent shipped Copilot Chat decoder integration test also passes (53 total AISDK tests).
  • AI: bun test test/schema.test.ts — 23 passing tests.
  • Coverage includes Chat/Responses billing shapes, zero/malformed amounts, latest-valid-charge handling, isolation between physical requests and providers, catalog fallback, successful/failed step projection and Session lifetime totals.
  • bun run check — lint and all 36 repository typecheck tasks pass. Core typecheck also passes with the additional integration test.

Provider streams are fixture-driven; no live Copilot request or credentials are used.

Screenshots / recordings

N/A — billing normalization and persistence.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add typed Copilot billing usage to the V2 runtime

1 participant