Skip to content

feat(model): per-model context limits and pricing for the usage display - #89

Open
justin-carper wants to merge 4 commits into
mainfrom
usage-metrics
Open

feat(model): per-model context limits and pricing for the usage display#89
justin-carper wants to merge 4 commits into
mainfrom
usage-metrics

Conversation

@justin-carper

Copy link
Copy Markdown
Collaborator

What

Populate Cursor models with per-model context window limits, per-token pricing, and output limits so opencode's TUI session header shows accurate tokens / context window % / cost.

Why

All Cursor models previously reported limit.context: 200_000 and cost: 0. The TUI session header rendered no context-window percentage and no dollar cost. Verified live (opencode 1.18.11): /config/providers returned "limit":{"context":0,"output":0} for all 33 models — the config channel (provider.<id>.models, built by toOpencodeModels()) emitted no limit/cost at all, and provider.models() hook output is discarded for providers absent from models.dev.

Changes

  • src/model-limits.ts (new): shared per-model maps + longest-prefix resolvers for context limits (Cursor docs default windows, not Max Mode 1M), pricing (cursor.com/docs/models-and-pricing, USD per million tokens), and output limits. Imports nothing — avoids a circular import with model-discovery.ts.
  • src/model-discovery.ts: OpencodeModelConfigEntry now carries limit and cost; toOpencodeModels() emits them on the config channel opencode actually reads. Cost uses the flat snake_case cache_read/cache_write keys the config schema requires (not the ModelV2 nested cache shape). Compile-time guards (_costKeyGuard/_limitKeyGuard) fail typecheck if the emitted keys drift from the accepted schema.
  • src/plugin/model-v2.ts: buildModelV2Map() now imports the resolvers instead of duplicating them; stale doc comment fixed.
  • Tests: 4 new config-channel tests (incl. a not.toHaveProperty("cache") shape trap guard), 7 new model-v2 tests. 405/405 passing, typecheck + build clean.

Verified end-to-end

Isolated opencode 1.18.11 server (published plugin excluded via XDG_CONFIG_HOME redirect) — /config/providers:

model context output in/out cache r/w
claude-opus-4-8 300000 64000 5/25 0.5/6.25
gpt-5.5 272000 64000 5/30 0.5/0
grok-4.5 256000 32000 0/0 0/0
claude-sonnet-4-6 200000 32000 3/15 0.3/3.75
claude-fable-5 300000 64000 10/50 1/12.5

Baseline before this branch: context: 0 for all 33.

Notes

  • Cursor Models pool models (Grok 4.5, Composer 2.5, Auto) keep $0 — no per-token API charge.
  • Values are a static snapshot; new Cursor model releases fall back to 200K/$0 until the maps are updated.
  • Pre-existing (out of scope): a user provider.cursor.models.<id> override in config still wins over these defaults at plugin/index.ts:211 and would keep context: 0 for that model.

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