Protected_Protected_Protected_Protected_Protected ReadonlydiscoveryProtected ReadonlylanguageProtected ReadonlyloggerProtected ReadonlyopenProtected ReadonlyresponseProtectedcalculateTriggered from frontend. In case you want to use the models on the backend without a frontend then call this yourself
Fetches the ids of the text-chat models OpenAI currently offers from its /v1/models endpoint,
retrying transient connection failures and caching a snapshot for offline use. The endpoint
exposes no capability metadata, so non-chat models are filtered out heuristically. Returns an
empty result when no key is configured; falls back to the cached snapshot on failure.
Reports where the effective API key comes from (preference, environment, or none).
ProtectedisHeuristic for the text-chat models among everything /v1/models reports: the gpt-*,
chatgpt-* and o1/o3/o4-style families, minus the variants that speak a different API
than chat completions: audio, realtime, live, transcription, speech, image, embeddings,
moderation, the search and computer-use tool endpoints, and the legacy -instruct completion
models.
The terms match anywhere in the id, so a family that carries one in a longer word goes with it
(o3-deep-research, which speaks the responses API and not this one). Anything this drops or
misses can still be configured as a custom endpoint.
ProtectedlistIterates the (auto-paginated) /v1/models endpoint. Overridable for testing.
ProtectedresolveMerges description overrides with model-id-based defaults from getOpenAiModelDefaults.
Description fields win, allowing custom-endpoint preferences to override capabilities for
non-OpenAI models. Custom endpoints (with a url) skip the context window lookup since we
don't know which model is actually behind the endpoint.
ProtectedresolveAllows or refuses the use of an API key found in the environment. Refused by default: an
environment key is only used once the user has confirmed it, and setting this back to false
stops it being used immediately, wherever it would have been used.
ProtectedtoMaps the endpoint's entries onto DiscoveredModels and adds the undated alias of every release-pinned id. The endpoint reports no display name or description — only the id, the owner and a creation timestamp — so a discovered OpenAI model carries no label.
Whether a key found in the environment may be used. Withheld until the user confirms it, so the gate sits on the key itself: every path that reaches for one — discovery, a custom endpoint, a manually configured model — is covered, and revoking the consent takes effect at once.