When using a Deepseek provider, the tool sends a request to the OpenAI API and results in a 401 authentication error

Resolved 💬 8 comments Opened May 20, 2025 by deadmau5v Closed Aug 7, 2025

What version of Codex is running?

0.1.2505172129

Which model were you using?

deepseek-chat

What platform is your computer?

darwin | arm64 | 24.5.03

What steps can reproduce the bug?

Configure the tool (OpenAI Codex v0.1.2505172129) to use provider: deepseek and model: deepseek-chat.
Ensure the Deepseek provider's API key is correctly configured in the settings (Note: although the error message mentions an OpenAI key, this is the prerequisite for the user when configuring Deepseek).
Attempt to interact with the tool, e.g., send a simple message ("hello") in the session.
Observe the error message in the output panel.

What is the expected behavior?

The tool should use the deepseek provider and deepseek-chat model as specified in the configuration, send the request to Deepseek's API endpoint, and authenticate using the Deepseek API key. A model response should be received upon successful interaction.

What do you see instead?

The tool does not use the Deepseek provider. Instead, it attempts to send the request to the OpenAI API endpoint. The request is rejected by OpenAI, returning a 401 Authentication Error. The error message explicitly states that the OpenAI API key is invalid (401 Authentication Fails, Your api key: ****hmUA is invalid).

Additional information

<img width="1136" alt="Image" src="https://github.com/user-attachments/assets/97ede004-ee11-4e19-80c3-d17d3f63ee8f" />

Tool Version: OpenAI Codex (research preview) v0.1.2505172129
Configuration at the time of the error (as shown in the screenshot or pasted):

╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.2505172129            │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: 647a0b4e671541318ed03222e710a9dc          │
│ ↳ workdir: ~/Code/Test-Codex                                 │
│ ↳ model: deepseek-chat                                       │
│ ↳ provider: deepseek                                         │
│ ↳ approval: suggest                                          │
╰──────────────────────────────────────────────────────────────╯

Full error message received:

⚠️  OpenAI rejected the request. Error details: Status: 401, Code: invalid_request_error, Type: authentication_error,
Message: 401 Authentication Fails, Your api key: ****hmUA is invalid. Please verify your settings and try again.

View original on GitHub ↗

8 Comments

via007 · 1 year ago

这个就很神奇,把OPENAI_API_KEY 改成 deepseek的就可以了

deadmau5v · 1 year ago

Modify the OPENAI_API_KEY field of ~/.codex/auth.json and it will work properly

<img width="1136" alt="Image" src="https://github.com/user-attachments/assets/6410ce36-ce95-405d-ad01-84f20dd0e9b8" />

shibing624 · 1 year ago

👍🏻,我以为必须responses api.

mostafa-gado · 1 year ago

I can't find auth.json! Can you provide the json parameters in that file?

deadmau5v · 1 year ago
I can't find auth.json! Can you provide the JSON parameters in that file?

You may need to log in using openai

DXXS · 1 year ago

Ya me too; I have DEEPSEEK_API_KEY (and OPENAI_API_KEY which it displays) set up correctly, and curl to deepseek site works fine with that key, so I am wondering WTF?

Zachary-Lee-Jaeho · 1 year ago

user
hello

system
⚠️ Network error while contacting OpenAI. Please check your connection and try again.

Not working with changing OPENAI_API_KEY

codex-maintainers · 11 months ago

Thank you for the feedback! Please try using the latest version of Codex CLI as we are actively addressing issues in the new Rust implementation. If the issue persists, feel free to report it again.