API key not being read correctly

Resolved 💬 2 comments Opened Aug 29, 2025 by ieuanb74 Closed Aug 29, 2025

What version of Codex is running?

codex-cli 0.23.0

Which model were you using?

gpt-4.1

What platform is your computer?

Darwin 24.6.0 x86_64 i386

What steps can reproduce the bug?

When running codex cli with the --profile argument and an Azure OpenAI provider, the agent says there is a missing environment variable with a name that matches the value supplied as env_key in config.toml.

  1. Define config.toml

```preferred_auth_method = "apikey"

[model_providers.azure]
name = "Azure"
base_url = "https://dummy.openai.azure.com/openai/deployments/dummy-deployment"
env_key = "11112222333344445555"
query_params = { "api-version" = "2025-04-01-preview" }
wire_api = "chat"

[profiles.az]
model_provider = "azure"
model = "dummy-deployment"


2. Export API key as env var

export OPENAI_API_KEY="11112222333344445555"


3. Run codex cli with --profile argument

codex --profile az


4. Select option 2 (Require approval of edit or commands)
5. Write any prompt and hit enter

### What is the expected behavior?

Codex CLI should accept either the `env_key` provided in the config.toml, the `OPENAI_API_KEY` environment variable, or both. It should not require setting a separate environment variable.

### What do you see instead?

Results in

🖐 Missing environment variable: 11112222333344445555.


Workaround is to export the env var with the same name and value e.g.

export 11112222333344445555=11112222333344445555


### Additional information

_No response_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗