mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 00:05:30 +00:00
Root cause: Codex /models requests always fetch the manifest from a scheduled upstream. Custom API-key upstreams that do not implement /v1/models return 5xx, an empty catalog, or a non-standard body, so the gateway exhausts account failover and returns 502 even when the group can describe its models locally. Change: generate a local Codex manifest when every candidate fails (or the account switch budget is exhausted) and when an upstream returns an empty manifest. Sources follow the group's models_list_config, then the group accounts' model_mapping keys, then the default OpenAI catalog, with the same retired-model filter as /v1/models. The local list only replaces the upstream error when it is non-empty, keeps ETag/304 revalidation, and leaves successful upstream manifests untouched. Pinned discovery mode keeps its explicit FallbackToScheduler contract. Tests: cover 5xx/empty/non-JSON upstream fallback, all-candidates-failed fallback, source priority, upstream success regression, ETag revalidation, and preserving the original error when the local list is empty.