Home

Using Codex CLI with OpenRouter Instead of OpenAI

Yes — you can use OpenRouter with Codex CLI, but not via the built-in “login/auth” flow. You authenticate differently.

Two Separate Auth Paths in Codex CLI

1. Native Codex Login (OpenAI)

This is the only “official” login/auth flow.

2. OpenRouter (What You’re Looking For)

How OpenRouter Auth Actually Works

Instead of logging in, you:

1. Get API Key from OpenRouter

Format: sk-or-...

2. Set Environment Variable

export OPENROUTER_API_KEY="sk-or-..."

3. Configure Codex (~/.codex/config.toml)

model_provider = "openrouter"
model = "openai/gpt-5.3-codex"

[model_providers.openrouter]
name = "openrouter"
base_url = "https://openrouter.ai/api/v1"
env_key = "OPENROUTER_API_KEY"

4. Run Codex

codex

At this point, Codex will send requests through OpenRouter.

Key Limitation

So:

You cannot “authenticate OpenRouter” using codex --login

Practical Takeaway

References

Tags: CliAi_toolsAiAi-Assisted-Coding