Skip to content

fix: rename provider id to github-copilot-amplifier for exact cost - #15

Open
David Koleczek (DavidKoleczek) wants to merge 1 commit into
mainfrom
fix/opencode-exact-cost
Open

fix: rename provider id to github-copilot-amplifier for exact cost#15
David Koleczek (DavidKoleczek) wants to merge 1 commit into
mainfrom
fix/opencode-exact-cost

Conversation

@DavidKoleczek

Copy link
Copy Markdown
Collaborator

Bug

When opencode uses amplifier-agent as an OpenAI-compatible provider through this bridge, the session cost opencode displays is overstated. amplifier-agent's own cost_usd is Anthropic-exact, but opencode ignores it and re-derives cost from token counts times the static per-model rate table this bridge writes. Under Anthropic prompt caching that is wrong: cache-read tokens get folded into the input bucket at the full input rate, and cache-creation tokens are dropped (recorded as 0), producing a systematic overcharge.

Reported in microsoft-amplifier/amplifier-support#352.

Fix

opencode only enables raw-usage passthrough (includeRawChunks) when the provider id contains the substring github-copilot. That passthrough is what lets amplifier-agent's per-turn copilot_usage.total_nano_aiu reach opencode, which then overrides its token-times-rate estimate with the exact value.

  • Rename DEFAULT_PROVIDER_ID from amplifier to github-copilot-amplifier to turn that path on. The provider's display name stays Amplifier, so the model picker is unchanged for users.
  • On config rewrite, drop any stale provider block previously written under a different id but the same baseURL. Without this, upgrading an existing config leaves a duplicate Amplifier provider (the old amplifier id plus the new one).

Only the loose github-copilot substring is matched. The exact-match Copilot machinery (OAuth, device-flow login, request-body rewriting) is gated on === "github-copilot" or the Copilot npm loader, neither of which this hits.

This depends on the companion change in amplifier-agent (emit copilot_usage on the terminal SSE chunk). Both changes are required together; neither has any effect alone.

Verification

Verified end-to-end in an isolated environment (opencode 1.17.15, amplifier-agent) with a 3-turn, cache-heavy session on claude-haiku-4-5:

  • Before: opencode recorded $0.04905320 vs amplifier-agent cost_usd $0.03107695 (+57.8%).
  • After: opencode recorded $0.03055695 == amplifier-agent cost_usd $0.03055695 (penny-exact).
  • After the stale-cleanup change, re-running prepare on a config that had both ids leaves exactly one provider (github-copilot-amplifier).

The session completed with no 4xx. ruff check and ruff format --check pass on the changed file.

@DavidKoleczek

Copy link
Copy Markdown
Collaborator Author

Companion PR (required together): microsoft/amplifier-agent#96

opencode only enables raw-usage passthrough (includeRawChunks) when the
provider id contains the substring "github-copilot". That passthrough is what
lets amplifier-agent's per-turn copilot_usage.total_nano_aiu reach opencode and
override its inaccurate token-times-rate cost estimate, which otherwise
overstates session cost under Anthropic prompt caching.

- Rename DEFAULT_PROVIDER_ID from "amplifier" to "github-copilot-amplifier".
  The provider's display name stays "Amplifier".
- On config rewrite, drop any stale provider block previously written under a
  different id but the same baseURL, so upgrading configs do not end up with a
  duplicate "Amplifier" provider.

Requires the companion change in amplifier-agent (emit copilot_usage on the
terminal chunk). Both are required together.

Refs: microsoft-amplifier/amplifier-support#352

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant