Skip to main content

Codex CLI

Codex reads configuration from ~/.codex/config.toml. The OPENAI_BASE_URL environment variable was removed in recent Codex releases — use openai_base_url or a custom model provider instead.

Configuration

Add a custom provider in ~/.codex/config.toml:
Important: set model_context_window and model_max_output_tokens to match the model you selected. Codex assumes a 128k context window by default and starts compacting the session around ~100k tokens — far below what larger models support. Update both values whenever you change model. See Context window values below.
Set your API key in the shell (or add it to your profile):
Then run codex as usual.

Context window values

Use these values for model_context_window and model_max_output_tokens. The context window is the safe input budget — the model’s total context wall minus max_output_tokens, with a small ~2% safety buffer. Models with a smaller output cap get a larger input budget. GET /v1/models also advertises each model’s context_length and max_output_tokens, so you can always look up the current values:

Responses API

Codex uses POST /v1/responses. For models whose upstream only supports chat completions (GLM, DeepSeek, Kimi, Qwen, etc.), Openference translates Responses requests to /v1/chat/completions and converts the reply back to Responses JSON. Native Responses upstreams (when configured) are forwarded without translation. See also:

Quick smoke test