Codex CLI configuration guide

Codex CLI Custom API Setup: Base URL and API Key

This guide shows how to connect Codex CLI to a custom OpenAI-compatible endpoint through the user-level ~/.codex/config.toml file. It covers macOS, Linux, Windows, environment variables, provider configuration, and common 401, 404, 429, and model errors.

Published: July 10, 2026Updated: July 21, 2026Reading time: 8 minutes
Short answerStore your API key in CODEXINFO_API_KEY. In the user-level ~/.codex/config.toml, define a custom provider with base_url = "https://api.codexinfo.top/v1", env_key = "CODEXINFO_API_KEY", and wire_api = "responses".

Create an account and API key   View current models and pricing

Before you begin

  1. Install Codex CLI using the instructions on the official Codex CLI page.
  2. Create your codexinfo.top account and generate an API key. Existing users can use the Sign in button in the navigation.
  3. Choose an exact model name from the current model and pricing list.
Security: Never paste a real API key into config.toml, Git, screenshots, or public logs. The setup below references an environment variable instead.

Step 1: Set the API key environment variable

macOS or Linux

Terminal
export CODEXINFO_API_KEY="sk-your-api-key"

For a persistent Zsh setting:

Terminal
echo 'export CODEXINFO_API_KEY="sk-your-api-key"' >> ~/.zshrc
source ~/.zshrc

Use ~/.bashrc instead when your shell is Bash.

Windows PowerShell

PowerShell
$env:CODEXINFO_API_KEY="sk-your-api-key"

To save it for the current Windows user:

PowerShell
[Environment]::SetEnvironmentVariable(
  "CODEXINFO_API_KEY",
  "sk-your-api-key",
  "User"
)

Close and reopen PowerShell after saving a user environment variable.

Step 2: Edit the user-level config.toml

Operating systemConfig path
macOS / Linux~/.codex/config.toml
WindowsC:\Users\your-name\.codex\config.toml
Important official behavior: Put custom-provider fields in the user-level configuration. The official Codex configuration reference states that project-level .codex/config.toml files ignore model_provider and model_providers.
~/.codex/config.toml
model = "gpt-5.5"
model_provider = "codexinfo"

[model_providers.codexinfo]
name = "codexinfo.top"
base_url = "https://api.codexinfo.top/v1"
env_key = "CODEXINFO_API_KEY"
wire_api = "responses"

gpt-5.5 is an example visible in the codexinfo.top model list when this guide was published. Replace it with the exact current model name when the list changes.

FieldPurpose
modelThe model Codex selects by default.
model_providerSelects the custom provider defined below.
base_urlThe compatible API endpoint. Keep the trailing /v1.
env_keyThe name of the environment variable containing the key.
wire_apiThe custom-provider protocol. The official reference currently supports responses.

Step 3: Verify the connection

Terminal
codex --version
Terminal
mkdir codex-api-test
cd codex-api-test
codex

You can also make a non-interactive test request:

Terminal
codex exec "Reply with exactly: connection successful"

After a successful request, check the codexinfo.top dashboard for the corresponding usage record.

Troubleshooting

401 Unauthorized or Invalid token

  • Confirm that env_key exactly matches CODEXINFO_API_KEY.
  • Run echo $CODEXINFO_API_KEY on macOS/Linux or $env:CODEXINFO_API_KEY in PowerShell.
  • Reopen the terminal after saving a persistent variable.
  • Copy the key again without spaces or line breaks.

404 Responses endpoint not found

  • Use https://api.codexinfo.top/v1 as the base URL.
  • Do not use the dashboard URL as the API endpoint.
  • Make sure the provider supports the Responses API.

Model not found

  • Model names must match the dashboard exactly.
  • Do not copy an outdated model name from an old tutorial.
  • Review the current model list.

429 Too many requests or insufficient quota

  • Check account balance and API-key quota.
  • Review model, IP, and request restrictions on the key.
  • Reduce concurrency and retry later.

Codex ignores the provider configuration

  • Confirm that you edited the user-level ~/.codex/config.toml.
  • Check TOML quotes, spelling, and table names.
  • Restart the Codex session and terminal.
  • Do not place the provider definition only in a project-level config file.

API key safety

  • Never commit a key to Git.
  • Do not expose a complete key in screenshots or support logs.
  • Create separate keys for different devices or projects.
  • Revoke and replace a key immediately if it leaks.
  • Use quota, model, and IP restrictions when appropriate.

Frequently asked questions

Can I only set OPENAI_BASE_URL and OPENAI_API_KEY?

Some tools support those variables, but Codex CLI has an explicit custom-provider configuration. Using model_providers, base_url, and env_key makes the configuration clearer and easier to troubleshoot.

Why use CODEXINFO_API_KEY instead of pasting the key into config.toml?

env_key stores the environment-variable name, not the secret. This reduces the risk of committing or sharing the actual API key.

Can different projects use different models?

Yes. Keep the reusable provider definition in user-level configuration, and use Codex configuration layers or launch options for project-specific model choices.

Official references

The fields in this guide were checked against the OpenAI Codex Configuration Reference and Codex Basic Configuration. Available models and service pricing come from the live codexinfo.top dashboard.

Ready to configure Codex CLI?

Create an account and API key, then paste the configuration from this guide.

Create an account