Skip to content

fix(core): restore ChatGPT model discovery for token sharing - #64528

Open
rekram1-node wants to merge 4 commits into
devfrom
chatgpt-discovery
Open

rekram1-node wants to merge 4 commits into
devfrom
chatgpt-discovery

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Related: #52878 (sync turned off in #53466 while OpenAI's /v1/models left out models some accounts could use)

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Sign in with ChatGPT shows one list for every account: the models.dev openai-chatgpt list since #65579, or the built-in list. Some plans can't use every model on it (the Codex catalog marks gpt-6.2-* as unavailable on free plans, for example). This turns the per-account model sync back on, using the code that was commented out. Like GitHub Copilot, the account's live list decides what shows, and the models.dev list stands in until it loads or when it fails.

A token-sharing token sent to GET https://api.openai.com/v1/models returned 200 on 2026-11-22: 12 models, 10 with visibility: "list" and supported_in_api (the 6.2, 6.1, 6 and 5.6 models), matching the existing schema.

It uses the same plumbing as GitHub Copilot's model list (ProviderRefresh.start with SharedCache), so one fetch serves every open project:

startup / account switch / every 10 minutes
  GET /v1/models with the account's token (shared across open projects, 15s timeout)
    usable list (>=1 listed, API-supported model) -> show it
    error, timeout, bad body or empty list -> keep the last good list for this account
no list for this account yet -> the models.dev openai-chatgpt list, else the built-in list

Notes:

  • The list is cached per connection, so one account's list never shows under another.
  • Lists aren't saved to disk anymore; the models.dev list covers startup until the first fetch finishes. The migration from chatgpt-browser still strips the old models from credential metadata.
  • The live list only names base models, so variants (-fast, -pro, ...) are kept only when the models.dev list (or the built-in one) has them. This route rejects service_tier: "flex" (tested live), so -flex stays hidden.
  • I didn't bring back the model transform rule that disabled any OpenAI model missing from the account list. Models added in config stay visible.

Trade-off: when discovery succeeds, the account list decides what shows up. If OpenAI leaves out a model the account can still use, which is the bug from #52878, it disappears until the list includes it. The models.dev list is used only when there is no usable account list; merging the two would show models the account may not be able to use.

How did you verify your code works?

packages/core/test/plugin/provider-chatgpt.test.ts, with controlled HTTP responses and the test clock:

  • Before the account list loads, the models.dev list shows. After, the account list does: hidden entries dropped, -fast kept from the models.dev list, -flex hidden.
  • After a good list, an empty list and a 401 keep the list; a later good list replaces it.
  • Switching accounts while the first account's request is pending doesn't show its late answer, and switching back shows the first account's own list.

Rebased on dev after #65579. provider-chatgpt.test.ts passes with --rerun-each 5; provider-openai.test.ts, provider-github-copilot.test.ts and models.test.ts pass. bun typecheck in packages/core passes.

Not tested: a live run of this build against a ChatGPT account.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks sound. I couldn't test discovery live (no ChatGPT credentials). The plugin tests pass (29/29, and 145/145 over 5 repeat runs) and tsc -b for packages/core passes.

I read the restored refresh path closely:

  • Late answers are dropped when the credential or cache key changed while the request was pending.
  • Failures, timeouts, bad bodies and empty or filtered-to-empty lists keep the current list and save nothing. A failure only logs a warning.
  • The new models:<credential>:<client> key prevents one account's list from showing under another account that reuses the same client ID.
  • Not seeding the old models:<clientID> snapshot during migration matches the stated intent.

The trade-off you call out is the main risk: for accounts whose /v1/models list leaves out a model they can still use (the #52878 case), that model disappears again until OpenAI lists it. Config-defined models stay visible, so users have a workaround.

A small side effect: entries under the old models:<clientID> key are no longer read but stay in plugin storage.

Public API: unchanged. The plugin storage keys are internal.

Related: #52878

@AKOrojo

AKOrojo commented Nov 21, 2026

Copy link
Copy Markdown

I opened #65417 for the same area and it was closed as a duplicate of this one, which is right — this is the better PR and it has the per-credential keying and the stale-answer guard that mine did not have. One difference is worth making the case on here, since the trade-off is spelled out above: adding the account's list to the fixed list instead of replacing it.

The case for the union:

So the change on top of this PR would be small — the union, and deriveModels keeping the catalog models the account's list omits rather than dropping them:

// the models the sign-in serves are the fixed set plus the ones the account's
// list names; the account's list only adds, because it omits models the
// sign-in still serves
const reported = available?.map((model) => model.slug)
const supported = catalog.filter(
  (model) => fallbackModels.has(model.id) || reported?.includes(model.modelID),
)
models: available ? deriveModels(available, supported) : supported

with deriveModels mapping the existing models it does not find in the remote list to themselves instead of dropping them.

I have that version written and tested (bun typecheck clean, the chatgpt provider tests pass, and a new test covers the union: a model the account reports is offered, a model the account leaves out is still offered, a model neither names is not). The branch is AKOrojo:fix/chatgpt-model-list-additive if it is easier to take the diff from there than to re-apply it.

Happy to drop it if you think the replacement is the right call — the argument above is only about not losing the fixed models, and you have the account data to judge whether that matters.

This branch has not been deployed

No deployments
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.

2 participants