fix(ai): read long-context thresholds from models.dev tiers
Merged
PA
19d ago+68+68+01234567890123456789-4-4-0123456789
Fixes #30144
Problem
The catalog sync prices long context from models.dev's context_over_200k and gives every model a 200K threshold (LONG_CONTEXT_THRESHOLD_TOKENS). models.dev deprecated that field on 2026-08-23 (anomalyco/models.dev#5335). The real threshold now comes from cost.tiers[].tier.size, and it isn't always 200K:
- 13 OpenAI models (gpt-6-luna, gpt-6-sol, gpt-6.1-sol, gpt-5.6, gpt-5.5, gpt-5.4 and others) switch to long-context rates above 272K.
computeCostBreakdownswitches them at 200K, so a request of 200K–272K is debited at double the input rate. - Claude Haiku 5.5 switches above 100K, to 5× its base rates. models.dev publishes that tier only in
tiers, so the catalog has nolongContextCostfor it, and requests over 100K are debited at base rates.
Debited by computeCostBreakdown today, against the provider's price (90% of input cache-read, 1K output):
| Model | Input | Provider price | Debited today |
|---|---|---|---|
| gpt-6-luna | 240K | $0.0051 | $0.0099 |
| gpt-6.1-sol | 240K | $0.0796 | $0.1542 |
| claude-haiku-5-5 | 150K | $0.0168 | $0.0034 |
Fix
extractCosttakes the lowestcontexttier fromcost.tiersand uses itssizeasthresholdTokens.- It falls back to
context_over_200kat 200K when a model has no tiers. ModelsDevModelgains thetiersfield.
Built against today's models.dev payload, the only catalog changes are:
- the 13 OpenAI thresholds (200K → 272K);
- Haiku 5.5 gaining its 100K tier;
- gpt-6.1-terra getting its 272K tier.
Rates and the Google and xAI entries are unchanged. ai-models.json and ai-providers.json aren't regenerated here; the next daily sync rewrites them. The regenerated catalog can be added to this PR if preferred.
Test plan
-
build-catalog.spec.ts: two new cases, a 272K tier quoted in both fields and a 100K tier quoted only intiers. Both fail onmain(200000 instead of 272000;longContextCostundefined) and pass with the fix. - All suites under
scripts/ai-catalog-syncandmetadata-modules/aipass, exceptbuild-front-component-shared-dependencies, which needs a localtwenty-uibuild. - oxlint and oxfmt are clean on the changed files.
tsgoreports no errors in them.
Written with Claude Code (Claude Opus 5.5).