Codex CLI · API access

Point Codex CLI at an OpenAI-compatible gateway

Codex CLI works with any OpenAI-compatible base URL. Add one provider block, export one key, and switch between GPT, Claude and Gemini models without changing your tooling.

Configuration

Add a provider to ~/.codex/config.toml. The base URL includes /v1; Codex appends the endpoint path.

model = "gpt-6.2-astra"
model_provider = "apitokenrouter"

[model_providers.apitokenrouter]
name = "API Token Router"
base_url = "https://apitokenrouter.com/v1"
env_key = "APITOKENROUTER_API_KEY"

Then export the key before starting a session:

export APITOKENROUTER_API_KEY="sk-atr-your-key"
codex

Use --model or the config value to choose a model from the live catalog, such as gpt-6.2-astra or deepseek-v4-pro.

Why a gateway instead of direct provider keys

Model choice

Change the model string, not the integration. The same key reaches several families.

Failover

Requests retry across upstream lines for the family, with a circuit breaker for unhealthy lines.

One bill

Usage and balance live in one dashboard, with per-key records for audits.

Compatibility

Codex featureGateway support
Chat CompletionsSupported at /v1/chat/completions, including streaming.
Responses APISupported at /v1/responses for clients that request it.
Reasoning modelsModel ids and parameters are passed through to the selected upstream.
Custom headersAuthorization: Bearer is accepted; x-api-key works too.

Billing

Pay-as-you-go in USD, priced per million input and output tokens. The catalog shows list and net prices side by side so you can compare against official rates before you commit. Top up from the dashboard; balance is shared by every key on the account.

FAQ

Does Codex require a specific model name?

No. Use any model id in the catalog. The gateway maps it to a compatible upstream; if a model is not served by any connected line, the request returns a clear model-not-available error.

Can I keep using my OpenAI SDK?

Yes. Set base_url="https://apitokenrouter.com/v1" and the API key; the request and response shapes stay OpenAI-compatible.

Is streaming supported?

Yes. Server-sent events are relayed as they arrive, so Codex renders output progressively.

Where can I see upstream health?

The upstream lines page publishes the connected vendors, protocols, model counts and last free model-list check.