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: setSet your API key in the shell (or add it to your profile):model_context_windowandmodel_max_output_tokensto 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 changemodel. See Context window values below.
codex as usual.
Context window values
Use these values formodel_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 usesPOST /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: