OpenAI API Key Authentication Fails when OpenRouter as provider
Resolved 💬 4 comments Opened May 23, 2025 by HaiyiMei Closed Aug 7, 2025
What version of Codex is running?
0.1.2505172129
Which model were you using?
_No response_
What platform is your computer?
_No response_
What steps can reproduce the bug?
export OPENAI_API_KEY="your-actual-openai-api-key"
export OPENROUTER_API_KEY="your-openrouter-api-key"
codex -q --provider openrouter --model openai/gpt-4.1 "hello"
What is the expected behavior?
But when we set:
export OPENAI_API_KEY="your-openrouter-api-key" # Why this should be Openrouter Key
export OPENROUTER_API_KEY="your-openrouter-api-key"
codex -q --provider openrouter --model openai/gpt-4.1 "hello"
It runs smoothly
What do you see instead?
_No response_
Additional information
_No response_
4 Comments
Here's the lowdown on the proposed pull request. It's been noted that the providers in question are doing what they're supposed to. After entering the command "-p openrouter," the system displays a prompt asking to use Chat GPT, OpenAI, or OPENROUTER_API_KEY.
Try removing the ~/.codex/config.json
Thanks for reporting this issue! Please try again on the latest version of Codex CLI. If the problem persists, feel free to let us know. We're focused on improving the native/Rust implementation, which you can try here.
Is provider deprecated? There is no such an option in --help.