Skip to content

fix(ai): read long-context thresholds from models.dev tiers - #30141

Merged
etiennejouan merged 4 commits into
twentyhq:mainfrom
PavleProd:fix/ai-catalog-context-tier-thresholds
Nov 13, 2026
Merged

etiennejouan merged 4 commits into
twentyhq:mainfrom
PavleProd:fix/ai-catalog-context-tier-thresholds

Conversation

@PavleProd

@PavleProd PavleProd commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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. computeCostBreakdown switches 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 no longContextCost for 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

  • extractCost takes the lowest context tier from cost.tiers and uses its size as thresholdTokens.
  • It falls back to context_over_200k at 200K when a model has no tiers.
  • ModelsDevModel gains the tiers field.

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 in tiers. Both fail on main (200000 instead of 272000; longContextCost undefined) and pass with the fix.
  • All suites under scripts/ai-catalog-sync and metadata-modules/ai pass, except build-front-component-shared-dependencies, which needs a local twenty-ui build.
  • oxlint and oxfmt are clean on the changed files. tsgo reports no errors in them.

Written with Claude Code (Claude Opus 5.5).

View guided diff

@twenty-ci-bot-public

Copy link
Copy Markdown

👋 Thanks for contributing to Twenty! We're excited to have you on board.

Your PR has been set to draft while you work on it. Once you're done, mark it as Ready for review and our automated checks will run.

By submitting your Pull Request, you acknowledge that you agree with the terms of our Contributor License Agreement.

@greptile-apps

greptile-apps Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Reads long-context prices and thresholds from models.dev context tiers instead of assuming 200K tokens.

  • AI model prices switch at each model’s published long-context threshold.

Reviews (3) · Last reviewed commit: "fix(ai): read long-context thresholds fr..." · Reviewed by Greptile

The catalog sync gave every long-context model a 200K threshold taken
from models.dev's deprecated context_over_200k field. OpenAI models
switch at 272K and Claude Haiku 5.5 at 100K, which models.dev publishes
only in cost.tiers. Take the threshold and rates from the lowest
context tier, falling back to context_over_200k at 200K.
@PavleProd
PavleProd force-pushed the fix/ai-catalog-context-tier-thresholds branch from 32d032b to 826787d Compare November 10, 2026 22:55
@twenty-ci-bot-public

twenty-ci-bot-public Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🤖 PR Review

Check Result
🔍 Build safety ✅ passed
🧭 Triage ✅ passed
📐 Quality ⏭️ skipped — trusted-only
🛡️ Security ⏭️ skipped — trusted-only
🚦 Auto-approve ⏭️ skipped — trusted-only
🔐 Permissions ⏭️ skipped: no endpoint permission change

🔍 Automated Pre-Review

✅ No issues detected - This PR is ready for human review.


🧭 External PR Triage Review

✅ Looks good — a maintainer can pick this up.

Checks

  • ⏳ CI: pending
  • 🔗 Linked issue: Fixes #30144

Detailed findings (duplicate candidates, standards notes, summary) are in the workflow run logs.


View details

Automated pre-review — human approval still required.

@etiennejouan etiennejouan left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Hi @PavleProd congrats for your first contribution to twenty repo !

@PavleProd

Copy link
Copy Markdown
Contributor Author

Thanks @etiennejouan, glad it was useful!!!!! :D

@PavleProd

Copy link
Copy Markdown
Contributor Author

Hey @etiennejouan, the server-integration-test failure is in application manifest sync (DEFERRED_WORKSPACE_MIGRATION_ACTIONS_IN_PROGRESS), which this PR doesn’t touch. Could you re-run the failed job when you get a chance?

BOHEUS pushed a commit to BOHEUS/twenty that referenced this pull request Nov 13, 2026
…0371)

## Summary

The AI catalog sync has failed every day since 2026-10-23 at "Create
pull request" with `GitHub Actions is not permitted to create or approve
pull requests`. That repo setting is off on purpose (twentyhq#29028), and i18n
moved to the Twenty PR app, but this workflow kept `GITHUB_TOKEN`. The
last catalog sync merged was twentyhq#28593, so `ai-models.json` and
`ai-providers.json` are three weeks stale and catalog builder fixes like
twentyhq#30141 can't reach billing.

```diff
 sync-catalog                          # GITHUB_TOKEN, contents: write
   run catalog sync
   compose PR body
-  peter-evans/create-pull-request     # pushes, then fails to open the PR
-  mint dispatcher token, trigger twenty-infra automerge
+  force-push chore/ai-catalog-sync
+open-pull-request                     # permissions: {}
+  open-pull-request.yaml              # Twenty PR app opens the PR, triggers automerge
```

The reusable `i18n-open-pull-request.yaml` becomes
`open-pull-request.yaml`, since it now serves more than i18n. It gets an
optional `body` input, defaulting to its current text, and refreshes the
body of an already open PR, so the catalog PR keeps a current coverage
report. Its CI-trigger commit is now `chore: run CI on the latest push`.
The i18n callers only change the path.

## Evidence

- **Before:** run 43375772095 (2026-11-13) pushes
`chore/ai-catalog-sync`, then fails with `GitHub Actions is not
permitted to create or approve pull requests.`
**After:** oxfmt and YAML parsing pass. The push step, replayed against
a bare repo holding a stale `chore/ai-catalog-sync`, force-updates it
with a single commit touching only the catalog folder. The app step only
runs on GitHub, so the real check is the first run after merge: a PR
from `twenty-pr` with CI running.

## Merge Danger

**Door:** two-way

Reverting brings back the current, failing workflow.

**Blast Radius:** small

- Catalog PRs now come from the Twenty PR app, so they get CI and
twenty-infra's automerge turns on auto-merge. Main still requires an
approval and the review bot only auto-approves translations, so a human
still approves each catalog PR.
- The first PR carries three weeks of catalog drift.
- The five i18n workflows call the renamed file and behave the same,
apart from the CI-trigger commit message. Nothing outside this repo
references the old name or message.
- The `ai, automated` labels are dropped. Nothing reads them.
@etiennejouan
etiennejouan added this pull request to the merge queue Nov 13, 2026
Merged via the queue into twentyhq:main with commit 6c95bf9 Nov 13, 2026
148 checks passed
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.

AI credits use a 200K long-context threshold for every model (OpenAI is 272K, Claude Haiku 5.5 is 100K)

2 participants