feat(openai): sync the official OpenAI model catalog at runtime so new models don't wait for a release
Summary
Sub2API already follows upstream client versions without a code change:
OpenAICodexVersionSyncService for Codex, and now ClaudeCodeVersionSyncService (#7532) for Claude Code.
New OpenAI models still need a release: the model list in openai.DefaultModels is compiled in, and so are the rules that build local Codex catalog entries.
This issue proposes a runtime sync for the OpenAI model catalog. It uses the same design as #7532: a sync service writes to a setting, a runtime resolver reads it, and the result is merged with the built-in baseline.
Problem
When OpenAI ships a model (for example gpt-6-sol / gpt-6-luna on 2026-09-23), requests for it work on day one. Unmapped and passthrough accounts forward any model name, and mapped accounts work once an admin adds a mapping. Discovery does not work on day one:
| Surface | Source today | Follows upstream? |
|---|---|---|
POST /v1/responses |
forwarded as-is | ✅ |
Codex catalog, pinned-manifest groups (CodexModelsManifestConfig.Enabled) |
chatgpt.com/backend-api/codex/models, proxied |
✅ |
| Codex catalog, scheduler fallback (group has no mappings) | same upstream manifest | ✅ |
Codex catalog, groups with account model_mapping |
BuildGroupConfiguredCodexModelsManifest builds it locally: candidates from openai.DefaultModelIDs(), metadata from hard-coded rules (configuredCodexGPTReasoningLevels, isOpenAIGPT6Model, context-window constants, …) |
❌ |
GET /v1/models |
account mappings ∪ openai.DefaultModels (defaultModelIDsForPlatform, supplementUnmappedOpenAIModels, admin_group.go, admin account model list) |
❌ |
The result: until a release updates pkg/openai/constants.go (e.g. #7509), users can't select the new model in Codex /model. If they hard-code the model name, Codex shows Model metadata … not found, and reasoning levels and context window fall back to generic defaults.
Related reports: #7515 ("发布新模型了,更新一下呗", 30+ comments), #6614 (gpt-6-astra not selectable in Codex), #7042 (local catalog loses max_context_window), #7517 / #6647 (listing falls back to built-in defaults).
Proposal
Mirror OpenAICodexVersionSyncService / ClaudeCodeVersionSyncService:
-
OpenAIModelCatalogSyncService- Runs every hour, plus once at startup with the same first-run debounce as the version sync.
- Fetches the catalog from the source described under "Data source" below: by default Codex's public
models-manager/models.jsonat the synced stable tag, and optionally live manifests from designated OAuth accounts via the existingFetchCodexModelsManifest. - Stores the result in a new setting that only this service writes. The value is JSON:
{slug → raw manifest entry}plussynced_at,source_tag, andsource_account_ids. Settings is a key-value table, so no migration is needed. - Add-only. A failed fetch keeps the last value. A model that disappears upstream is kept for a grace period (e.g. 7 days), not dropped immediately, so one bad fetch can't shrink the listing.
-
Settings (same pattern as #7532):
openai_model_catalog_auto_sync_enabled: on/off switch. A read failure counts as enabled.openai_model_catalog_source_account_ids: optional overlay. When empty, only the public Codex catalog is used.openai_model_catalog_synced: sync-owned. Panel PUT must not overwrite it. Shown read-only in the panel ("last synced at, N models").
-
Runtime resolver. Turn
openai.DefaultModels/DefaultModelIDs()from package-level vars into functions backed by a resolver, the same move #7532 made forclaude.DefaultHeaders. Resolution: built-in baseline ∪ synced slugs. When no resolver is injected, the behavior is identical to today, so existing unit tests keep passing without wire. -
Metadata reuse. In
buildCodexModelsManifestForAccounts, when a configured model (or its mapped upstream model) exists in the synced catalog, start from the official entry: reasoning levels, context windows, service tiers,input_modalities, instructions template. Apply the existing rules only to models the catalog doesn't know. This also fixes #7042-class drift. -
Unchanged: group
model_allowlistfiltering,FilterCodexModelIDsForGroup(media/auto-mode exclusion), and the GPT-identity scrub for non-GPT slugs all still apply after the merge.
Data source
Unlike a client version, the live model catalog is not public and not global:
- The live source (
/backend-api/codex/models) needs an OAuth credential. - It differs by plan. Free accounts don't see plan-gated models, and requesting them returns 400
codex_plan_gated_model.
Options:
-
C. The Codex bundled catalog (recommended primary). Codex ships its fallback catalog in the repo at
codex-rs/models-manager/models.json. Verified againstrust-v0.157.1:- It has the same entry schema as
/backend-api/codex/models(slug,visibility,supported_reasoning_levels,context_window/max_context_window,service_tiers,input_modalities,model_messages, …). No conversion is needed. - It also carries
available_in_plansandminimal_client_versionper model. These are useful for plan-aware listing and for not advertising a model to a client too old to use it. - It is public, needs no credentials, and works for API-key-only deployments.
- It tracks launches closely. GPT-6 Sol/Luna were added in openai/codex#47332 (2026-09-22 18:17 UTC) and first shipped in stable
rust-v0.156.1(2026-09-23 02:41 UTC), on launch day.rust-v0.156.0(2026-09-22 19:51 UTC) did not have them yet. OpenAICodexVersionSyncServicealready resolves the latest stablerust-v*tag, so the sync can fetchraw.githubusercontent.com/openai/codex/<that tag>/codex-rs/models-manager/models.json. That pins the catalog to the same client version Sub2API presents upstream, nevermain.
Caveats:
- It contains only Codex-client models: 11 entries in 0.157.1, no
gpt-image-*. The built-in baseline must stay for the others. - It includes hidden entries (
visibility: "hide", e.g. internalgpt-daybreak-*codenames). These must keep their visibility and never be promoted into/v1/models. - Retired models are deleted from the file (openai/codex#47932 removed GPT-5.4), so the add-only/grace-period rule above matters.
model_messagesis large (~15–60 KB per model), so store the instructions template separately or re-derive it rather than duplicating it per request.
- It has the same entry schema as
-
A. Designated source accounts (optional enrichment). The admin picks one or more plus/pro OAuth accounts, and their live
/backend-api/codex/modelsmanifests are merged over C. This catches server-side-only changes (e.g. tier or plan gating that changes without a client release) and reuses the pinned-manifest plumbing. -
B. Automatic union over schedulable OAuth accounts. This needs zero configuration, but a single high-plan account can advertise a model to groups whose accounts can't serve it. It is probably not worth it once C exists.
Suggestion: C as the default source (on by default, like the version syncs), and A as an opt-in overlay.
Note: available_in_plans alone shouldn't gate listing yet. It lists free for gpt-6-astra, but we have seen free-plan accounts get 400 codex_plan_gated_model for that model. Treat it as advisory until verified.
Non-goals
- Pricing for new models (#7465). Billing rates are a separate, riskier sync.
- Routing. Forwarding already works without code changes.
- Non-OpenAI platforms. The design could extend to them, but each has its own catalog source.
Relation to existing work
- #7526 (open): stops passthrough accounts from hiding mapped models in discovery. It makes the manual path (add a mapping, no release) work in mixed groups. This issue adds the automatic path on top. Both change
supplementUnmappedOpenAIModels/GetAvailableModels, so they compose: that is where the resolver-backedDefaultModelIDs()plugs in. - #5473: per-account "sync upstream models" for OAuth could reuse the same fetch code, and its result could seed
openai_model_catalog_synced. - #1181: generic per-account periodic model refresh. This issue is the platform-level version for OpenAI.
Acceptance
- A model added to the upstream manifest shows up in
/v1/modelsand in the Codex catalog of mapped/unmapped groups within one sync interval, with its official metadata, and without a release. - A fetch failure or an upstream removal never shrinks the listing below the built-in baseline.
- With the switch off, or with the service not wired, the behavior is identical to today.
- Multi-instance deployments see the same catalog because it lives in settings (cf. #6232).
I'm happy to send a PR if the direction looks right.
补充一条可复现结果,供维护者判断这是配置缺口还是模型目录同步问题。
环境:Codex CLI 0.164.0-alpha.11.1,自定义 provider。配置只有 base_url、wire_api = "responses" 和 requires_openai_auth = true,没有 model_catalog_url。
现象:
GET /v1/models返回标准 OpenAIdata列表,其中已经有gpt-6.1-terra。GET /v1/models?client_version=0.164.0也能返回 Codex manifest,models[].slug包含gpt-6.1-terra。POST /responses使用gpt-6.1-terra可以正常完成。- Codex 模型选择器仍然看不到该模型;手动执行
codex --model gpt-6.1-terra可以运行,但提示Unknown model ... fallback metadata。
验证:在 provider 中临时加入:
model_catalog_url = "http://localhost:8080/v1/models"
之后 Codex 仍能正常调用该模型,并且不再出现 Unknown model / Model metadata ... not found 警告。
因此当前直接原因是自定义 provider 配置没有带上 model_catalog_url。建议:
- “使用密钥”或其他 Codex 配置生成入口默认写入
model_catalog_url = "<base_url>/v1/models",并说明该地址返回 Codex manifest。 - 当新模型进入渠道或上游目录时,自动更新
/v1/models?client_version=...的 Codex metadata,避免用户等待客户端缓存或手工改配置。 - 在文档中说明 Codex 0.160+ 的模型发现配置,避免用户误以为普通
/v1/models会自动被 Codex 选择器读取。
本次实测表明 Sub2API 已经能生成 gpt-6.1-terra 的 Codex manifest;缺的是让客户端配置使用该 manifest 的默认路径。
补充当前源码边界:最新评论建议的“使用密钥”默认生成 model_catalog_url,已经由 #7736 合入,最新稳定版 v0.2.18 也包含该行为。
UseKeyModal.vue 默认选择远程目录;OpenAI 配置生成处 同时写入 provider 的 model_catalog_url 和 [features].api_key_model_discovery = true。选择本地目录模式,或 manifest 超过 1 MiB 自动切到本地模式时,使用的是 model_catalog_json。
因此这次自定义配置缺少 URL 的情况,可以先与当前面板生成结果核对;这与本 issue 原先提出的服务端运行时目录同步是两个边界,前者已有生成入口,后者的同步来源、缓存和分组策略仍需要设计确认。
以上是公开源码及版本标签核对,未复现该部署或客户端。AI-assisted analysis.