Codex CLI is OpenAI’s open-source local coding agent that runs in your terminal. It supports multiple model providers, including OpenRouter, so you can use OpenRouter’s unified API, provider failover, and organizational controls with Codex’s agentic coding workflows.
Follow the Codex CLI installation instructions to install the CLI on your system.
sk-or-...)Codex uses a config.toml file, typically located at ~/.codex/config.toml. Create or edit this file with the following configuration:
Export your OpenRouter API key in your shell profile:
Codex reads the API key from the environment variable specified in env_key (default: OPENROUTER_API_KEY). Ensure this is set before starting Codex.
Navigate to your project directory and run:
Your requests will now be routed through OpenRouter.
base_url: OpenRouter API endpoint. Use https://openrouter.ai/api/v1 for production.env_key: Environment variable name for your API key.Codex supports per-project trust levels. Add project paths to control what the agent can access:
trusted: Agent has full access (e.g., run commands, edit files).untrusted: Agent has restricted access for safety.OpenRouter routes requests across multiple providers. If one provider is unavailable or rate-limited, OpenRouter can fail over to another, keeping your coding sessions uninterrupted.
For teams, OpenRouter provides centralized budget management. Set spending limits, allocate credits, and prevent unexpected cost overruns across developers using Codex.
Track Codex usage in real-time via the OpenRouter Activity Dashboard. Monitor costs, token usage, and request patterns.
Point model at any OpenRouter slug (e.g. ~openai/gpt-latest, ~anthropic/claude-sonnet-latest) or a pinned version to switch models without changing your Codex installation—just update config.toml.
OPENROUTER_API_KEY is set and valid. Check at openrouter.ai/keys.~openai/gpt-latest).