Codex CLI

Configure a dedicated OpenGateway provider and Codex CLI profile in ~/.codex/config.toml, then run it with --profile without changing your default provider.

Copy this to your agent
Paste it into any AI agent. It sets up the codex --profile opengateway profile and saves it as the opengateway-codex skill.

Run it once, nothing saved#

This one-off command applies provider and model settings with -c overrides; it does not edit Codex files. Replace the key placeholder before running it.

Bash
OPENGATEWAY_API_KEY="YOUR_OPENGATEWAY_API_KEY" codex \
-c 'model_provider="opengateway"' \
-c 'model="deepseek/deepseek-v4.1-flash-ultrafast"' \
-c 'model_context_window=1000000' \
-c 'model_providers.opengateway.name="OpenGateway"' \
-c 'model_providers.opengateway.base_url="https://apis.opengateway.ai/v1"' \
-c 'model_providers.opengateway.env_key="OPENGATEWAY_API_KEY"' \
-c 'model_providers.opengateway.wire_api="responses"' \
exec "Reply with OK"

Set it up by hand#

1. Get an API key#

opengateway.ai → API Keys → Create Key. Export it from ~/.zshrc or ~/.bashrc so Codex can read it without putting the secret in a TOML file:

Bash
export OPENGATEWAY_API_KEY="YOUR_OPENGATEWAY_API_KEY" # opengateway-codex

2. Add the provider and profile#

Add this provider table to ~/.codex/config.toml. Keep the marker comments so you can remove this block without disturbing other settings.

# opengateway-codex:start
[model_providers.opengateway]
name = "OpenGateway"
base_url = "https://apis.opengateway.ai/v1"
env_key = "OPENGATEWAY_API_KEY"
wire_api = "responses"
# opengateway-codex:end

Create a separate profile file at ~/.codex/opengateway.config.toml:

model_provider = "opengateway"
model = "deepseek/deepseek-v4.1-flash-ultrafast"
model_context_window = 1000000

Profiles are separate layers: codex --profile opengateway loads ~/.codex/config.toml and overlays ~/.codex/opengateway.config.toml. The [model_providers.<id>] table stays in the main config file; profile values are top-level TOML keys in the profile file. Codex 0.134.0 and later no longer loads [profiles.<name>] tables from config.toml, so do not use that older format. -c / --config overrides are for one invocation and parse their values as TOML.

Use deepseek/deepseek-v4.1-flash-ultrafast as the recommended UltraFast model; z-ai/glm-5.3-flash-ultrafast is the cheaper alternative. Both are active in the model catalog, support the Responses API, and have a 1M-token context window. Other models work when their active catalog entry's endpoints include responses; use its context_window as the profile's model_context_window.

Codex sends requests through the Responses API. The custom provider's wire_api = "responses" selects that protocol, and the base URL ends in /v1. To make OpenGateway the default rather than an optional profile, set model_provider and model in the main ~/.codex/config.toml too.

Each UltraFast model has a per-key limit on concurrent in-flight requests. Parallel agents may exceed it and receive 429 with concurrency_limit_exceeded and Retry-After; OpenGateway rejects excess requests immediately without sending them upstream. Reduce parallel work or wait before retrying, or contact support to request a higher limit. See UltraFast. For either of these two models, a request with more than 256K input tokens has double the input-token price for the whole request; cache reads and output tokens are excluded. Shared prompt prefixes can benefit from automatic prompt caching, so keep stable instructions and tools at the start. Check /models for current prices and any active time-based pricing.

3. Verify#

Bash
source ~/.zshrc # or open a new terminal
codex --profile opengateway exec "Reply with OK"

A response confirms the connection. Usage appears on the dashboard.

Codex CLI — OpenGateway