Keeps getting 401 issue when using Azure instance even everything is being passed correctly
What version of Codex is running?
0.1.2505172129
Which model were you using?
gpt-4.1
What platform is your computer?
macos
What steps can reproduce the bug?
codex --provider azure --model gpt-4.1 "explain the code to me"
● OpenAI Codex (research preview) v0.1.2505172129 │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: ac4797c9e1fa44398e7035723217d606 │
│ ↳ workdir: ~/Work/loa-parser │
│ ↳ model: gpt-4.1 │
│ ↳ provider: azure │
│ ↳ approval: suggest │
╰──────────────────────────────────────────────────────────────╯
user
explain the code to me
system
⚠️ OpenAI rejected the request. Error details: Status: 401, Code: 401, Type: unknown, Message: 401 Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid
key for an active subscription and use a correct regional API endpoint for your resource.. Please verify your settings and try again.
export AZURE_OPENAI_API_KEY="***"
export AZURE_OPENAI_API_VERSION=2025-01-01-preview
export AZURE_BASE_URL=https://xxxx.openai.azure.com/openai
What is the expected behavior?
_No response_
What do you see instead?
_No response_
Additional information
_No response_
4 Comments
I'm also experiencing this. Somebody help please!
JavaScript version fails with:
OpenAI rejected the request. Error details: Status: 401, Code: 401, Type: unknown, Message: 401 Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.. Please verify your settings and try again.and seams ignoring and required defining non-empty OPENAI_API_KEY even if alternate provider selected.I'm using the following
config.jsonfor JavaScript CLI:and surely define
AZURE_OPENAI_API_KEYin the env.Rust version fails with:
{ message: "stream error: unexpected status 404 Not Found: {\"error\":{\"code\":\"404\",\"message\": \"Resource not found\"}}.For Rust-based CLI i use the following config:
Yeah, I'm running into the second case explained above and consistently getting 404 errors.
I've got this
~/.codex/config.json(replacing<resource-name>with the correct value):I have these environment variables configured and ensured they are set in my env:
And I'm using those with https://github.com/simonw/llm to ensure they work as expected. With codex I consistently get this:
Thank you for the feedback! Please ensure you're using the latest version of Codex CLI. If the issue persists, try the native/Rust implementation of Codex CLI. If it still occurs, feel free to report back.