symfonic.core.codex_provider¶
codex_provider ¶
CodexOAuthProvider — DEV/TEST USE ONLY.
Calls OpenAI's Codex backend using a ChatGPT Plus/Pro/Team subscription
token instead of a metered OPENAI_API_KEY. Credentials are supplied
via environment variables (the same shape openwiki writes); this
provider does NOT run an interactive OAuth flow and does NOT read the
Codex CLI's on-disk token store.
When to use¶
- Local development against Codex models without provisioning a separate
metered
OPENAI_API_KEY. - Experimenting with the pipeline against a real LLM during development.
When NOT to use¶
- ❌ Production / multi-tenant SaaS — a subscription token doesn't bill per-tenant and its rate limits differ from API-key plans.
- ❌ Cost-tracking — subscription usage doesn't map to the per-token
pricing in :mod:
symfonic.core.observability.pricing.
This provider explicitly refuses to work in production-like environments
(SYMFONIC_ENV/ENVIRONMENT/ENV/NODE_ENV set to
production/prod) to prevent accidental subscription billing under
multi-tenant load. Unlike
:class:~symfonic.core.oauth_provider.AnthropicOAuthProvider -- whose
credentials_resolver is a real multi-tenant seam that must keep
working in prod -- Codex is env-vars-only and dev/test-only, so the guard
fires regardless of how the token is supplied and allow_production=True
is the sole reviewed escape hatch.
ToS caveat¶
Replaying a ChatGPT-subscription token to the Codex backend from a
third-party program is subscription-auth reuse. OpenAI ships "Sign in
with ChatGPT" for its own Codex CLI, but programmatic reuse elsewhere
may be throttled or disallowed under your plan. Treat this as the same
risk class as :class:~symfonic.core.oauth_provider.AnthropicOAuthProvider
— dev/test only.
Credentials (environment variables)¶
OPENAI_CHATGPT_ACCESS_TOKEN(required) subscription access token.OPENAI_CHATGPT_ACCOUNT_ID(optional) →chatgpt-account-idrequest header, which the Codex backend uses to attribute usage to the right plan.OPENAI_CHATGPT_BASE_URL(optional) override the Codex backend base URL (defaults to the ChatGPT Codex endpoint).
You obtain these by signing in with the Codex CLI (codex login) or an
openwiki-style flow and exporting the resulting values, e.g.::
export OPENAI_CHATGPT_ACCESS_TOKEN=...
export OPENAI_CHATGPT_ACCOUNT_ID=...
CodexCredentialError ¶
Bases: RuntimeError
Raised when a ChatGPT subscription token cannot be resolved.
CodexOAuthProvider ¶
CodexOAuthProvider(
*,
access_token: str | None = None,
account_id: str | None = None,
base_url: str | None = None,
use_responses_api: bool = True,
allow_production: bool = False,
)
DEV/TEST provider that calls the Codex backend via a ChatGPT token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str | None
|
ChatGPT subscription access token. Defaults to the
|
None
|
account_id
|
str | None
|
Plan/account id. Defaults to
|
None
|
base_url
|
str | None
|
Codex backend base URL. Defaults to
|
None
|
use_responses_api
|
bool
|
Route via the OpenAI Responses API (the Codex
backend's protocol). Default True; set False only if you point
|
True
|
allow_production
|
bool
|
Skip the production-env guard. Default False. Set True only if you have an explicit, ToS-reviewed reason. |
False
|
Raises:
| Type | Description |
|---|---|
CodexCredentialError
|
No access token supplied via arg or env. |
CodexProductionMisuseError
|
A production env var is set and
|
Source code in src/symfonic/core/codex_provider.py
token_fingerprint
property
¶
Short, non-leaking identifier for the active token.
get_chat_model ¶
Return a ChatOpenAI pointed at the Codex backend.
The subscription access token is passed as api_key — LangChain
sends it as Authorization: Bearer <token> — alongside the
chatgpt-account-id header and the Codex base URL.
Source code in src/symfonic/core/codex_provider.py
CodexProductionMisuseError ¶
Bases: RuntimeError
Raised when CodexOAuthProvider is used in a production-like env.