anomalyco / anomalyco/opencode

Local cost estimate uses the 200k price below a model's real context threshold

Open
#44,224 1 comment 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Aug 22, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

getUsage prices any request between 200,001 tokens and the model's actual context threshold at the high tier. For the GPT-5.6 family, whose tier steps at 272k, a 250k-token request is estimated at $0.40/M input instead of the documented $0.20/M — 2× the real rate.

The cause is the ?? in the cost selection:

https://github.com/anomalyco/opencode/blob/3a31c4ea801915c0b050df4b3842997ea62b6e93/packages/opencode/src/session/session.ts#L380-L386

The tier filter returns empty exactly when the request is below every threshold. That is precisely when the ?? fires, handing control to experimentalOver200K && contextTokens > 200_000 — a different, hardcoded number. So being below the real threshold is what triggers the high price.

experimentalOver200K is not a second, cheaper threshold. Against today's https://models.dev/api.json:

  • 361 models carry both tiers and context_over_200k
  • in all 361, context_over_200k's prices equal the lowest context tier's exactly (input, output, cache read, cache write)
  • 0 models carry context_over_200k without tiers

It is the legacy spelling of the lowest tier, from when 200k was the only threshold in the catalog. 252 context tier entries now sit at some other number — 137 at 272k, 56 at 256k, 31 at 128k, 20 at 32k, 6 at 512k, 2 at 262144 — and every one of them has this band.

Steps to reproduce

Run the cost expression against the real models.dev payload for gpt-5.6-luna (input $0.20/M, tier at 272k):

context tokens costInfo.input documented
199 000 $0.20/M $0.20/M
200 001 $0.40/M $0.20/M ❌
250 000 $0.40/M $0.20/M ❌
271 999 $0.40/M $0.20/M ❌
272 001 $0.40/M $0.40/M

Same shape for gpt-5.6 ($5 → $10/M).

This affects the local estimate shown in the TUI, not what the provider actually bills.

OpenCode version

Read on dev at 3a31c4ea801915c0b050df4b3842997ea62b6e93.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.