Codex

Codex

Configure AnyRouter in Codex CLI and Codex Desktop.

Codex CLI and Codex Desktop read the same local configuration. Add AnyRouter to ~/.codex/config.toml, then launch Codex from the terminal or the desktop app, and both use the same API Key and model settings.

This guide uses the OpenAI-compatible API. The API Base URL is https://ai.cloudtay.com/v1. Use the model ID shown in the AnyRouter console; the examples use gpt-5.5.

Overview of configuring Codex to use AnyRouterOverview of configuring Codex to use AnyRouter

1. Prepare an API Key

Register on the AnyRouter console and create an API Key. Copy it once after it is created, and never write the key into a project repository.

If you have not created an API Key yet, read Create an API Key first.

2. Install or check Codex CLI

If Codex CLI is already installed, check the version first.

bash15 B
codex --version

If the command is not found, install it with npm.

bash28 B
npm install -g @openai/codex

After installing, run codex --version again.

3. Edit ~/.codex/config.toml

Open ~/.codex/config.toml and merge in the config below. If the file already has model, model_provider, or [model_providers.*], change only the relevant fields instead of overwriting the whole file.

toml187 B
model = "gpt-5.5"model_provider = "anyrouter" [model_providers.anyrouter]name = "AnyRouter"base_url = "https://ai.cloudtay.com/v1"env_key = "ANYROUTER_API_KEY"wire_api = "responses"

The API Key is not stored in the TOML. Codex reads it from an environment variable instead.

bash51 B
export ANYROUTER_API_KEY="<your AnyRouter API Key>"

To make it permanent, add this line to your shell config file, for example ~/.zshrc.

4. Verify the CLI configuration

Run codex doctor to check configuration, authentication, and network connectivity.

bash22 B
codex doctor --summary

Once there are no authentication errors, start Codex in your project directory.

bash44 B
cd /path/to/my-projectcodex --model gpt-5.5

You can also start it with an initial prompt.

bash79 B
codex --model gpt-5.5 "Read this project and summarize its directory structure"

Starting Codex CLI with AnyRouter and checking the configurationStarting Codex CLI with AnyRouter and checking the configuration

5. Launch Codex Desktop

Codex Desktop can be opened from Codex CLI.

bash29 B
codex app /path/to/my-project

If the desktop app is not installed yet, codex app opens the installer. After installing, run the same command again to open the project.

Codex Desktop still reads ~/.codex/config.toml. If the desktop settings page shows model or provider options, choose AnyRouter and gpt-5.5. If there is no separate option, model_provider = "anyrouter" in the config file takes effect.

Codex Desktop reads the same AnyRouter configurationCodex Desktop reads the same AnyRouter configuration

Switch models temporarily

To use AnyRouter for a single command only, override the config with -c:

bash350 B
ANYROUTER_API_KEY="<your AnyRouter API Key>" codex \  -c 'model_provider="anyrouter"' \  -c 'model_providers.anyrouter.name="AnyRouter"' \  -c 'model_providers.anyrouter.base_url="https://ai.cloudtay.com/v1"' \  -c 'model_providers.anyrouter.env_key="ANYROUTER_API_KEY"' \  -c 'model_providers.anyrouter.wire_api="responses"' \  --model gpt-5.5

This is handy for quick checks but not for everyday use. For long-term use, write the settings to ~/.codex/config.toml.

FAQ

  • 401 or authentication failure: make sure ANYROUTER_API_KEY is an API Key created on the AnyRouter console and that the terminal launching Codex can read this environment variable.
  • 404 or model does not exist: make sure base_url is https://ai.cloudtay.com/v1 and the model ID matches the one shown on the platform.
  • The CLI works but the desktop app does not pick up the config: quit Codex Desktop, relaunch it with codex app /path/to/project, and make sure ~/.codex/config.toml has been saved.
  • The client reports that the Responses API is incompatible: change wire_api = "responses" to wire_api = "chat", retry, and choose a model that supports Chat Completions.