Skip to main content

OpenAI Codex

This guide walks you through connecting OpenAI Codex to LiteLLM. Using LiteLLM with Codex allows teams to:

  • Access 100+ LLMs through the Codex interface
  • Use powerful models like Gemini through a familiar interface
  • Track spend and usage with LiteLLM's built-in analytics
  • Control model access with virtual keys

Quickstart​

info

Requires LiteLLM v1.66.3.dev5 and higher

Make sure to set up LiteLLM with the LiteLLM Quickstart.

1. Install OpenAI Codex​

Install the OpenAI Codex CLI tool globally using npm:

curl -fsSL https://chatgpt.com/codex/install.sh | sh

2. Start LiteLLM Proxy​

docker run \
-v $(pwd)/litellm_config.yaml:/app/config.yaml \
-p 4000:4000 \
docker.litellm.ai/berriai/litellm:latest \
--config /app/config.yaml

LiteLLM should now be running on http://localhost:4000

3. Configure LiteLLM for Model Routing​

Ensure your LiteLLM Proxy is properly configured to route to your desired models. Create a litellm_config.yaml file with the following content:

model_list:
- model_name: o3-mini
litellm_params:
model: openai/o3-mini
api_key: os.environ/OPENAI_API_KEY
- model_name: claude-3-7-sonnet-latest
litellm_params:
model: anthropic/claude-3-7-sonnet-latest
api_key: os.environ/ANTHROPIC_API_KEY
- model_name: gemini-2.0-flash
litellm_params:
model: gemini/gemini-2.0-flash
api_key: os.environ/GEMINI_API_KEY
- model_name: gpt-5.6-luna
litellm_params:
model: openai/gpt-5.6-luna
api_key: os.environ/OPENAI_API_KEY
- model_name: gpt-5.6-sol
litellm_params:
model: openai/gpt-5.6-sol
api_key: os.environ/OPENAI_API_KEY
- model_name: gpt-5.6-terra
litellm_params:
model: openai/gpt-5.6-terra
api_key: os.environ/OPENAI_API_KEY

litellm_settings:
drop_params: true

This configuration enables routing to specific OpenAI, Anthropic, and Gemini models with explicit names.

4. Configure Codex to Use LiteLLM Proxy​

Set the required environment variables to point Codex to your LiteLLM Proxy:

# Use your LiteLLM API key (if you've set up authentication)
export LITELLM_API_KEY="sk-1234"

You can also configure Codex directly via ~/.codex/config.toml:

model = "gpt-5.6-terra"
model_provider = "litellm"
model_reasoning_effort = "medium"
approvals_reviewer = "user"

[model_providers.litellm]
name = "litellm"
base_url = "http://localhost:4000/v1"
env_key = "LITELLM_API_KEY"
wire_api = "responses"
stream_idle_timeout_ms = 7200000
stream_max_retries = 5
request_max_retries = 4

[projects."/path/to/your/project"]
trust_level = "trusted"

[tui.model_availability_nux]
"gpt-5.6-terra" = 1

5. Run Codex​

With everything configured, you can now run Codex:

codex

6. Advanced Options​

Using Different Models​

You can use any model configured in your LiteLLM proxy:

# Use Claude models
codex --model claude-3-7-sonnet-latest

# Use Google AI Studio Gemini models
codex --model gemini/gemini-2.0-flash

Troubleshooting​

  • If you encounter connection issues, ensure your LiteLLM Proxy is running and accessible at the specified URL
  • Verify your LiteLLM API key is valid if you're using authentication
  • Check that your model routing configuration is correct
  • For model-specific errors, ensure the model is properly configured in your LiteLLM setup

Additional Resources​