Status 400 Bad Request, Error Name: ZodError
What version of Codex is running?
0.56.0
What subscription do you have?
ChatGPT Plus
Which model were you using?
gpt-5-codex, gpt-5-codex-mini, gpt-5
What platform is your computer?
Microsoft Windows NT 10.0.26100.0 x64
What issue are you seeing?
This issue has been happening on my desktop for quite some time. I say it's my desktop because I've tried using codex on my other laptops and it doesn't give me this error. I've tried downgrading from 0.36.0 - 0.40.0 - 0.43.0 - 0.46.0 all the way up to 0.56.0, and the error is the same for all versions. It took me a long time to get to the point of opening an issue thread in this repository because I've been searching for a solution but haven't found one. I'm using Codex CLI as my primary, I tried using Codex Vscode Extension but the same error appears there too.
What steps can reproduce the bug?
This error occurs when I first send a message, and any message always responds with the same error.
Below, I've included screenshots from the Codex VSCode Extension and Codex CLI. You can see the error is the same and occurs no matter what message I send. I've tried changing the model, but the error persists.
<img width="373" height="588" alt="Image" src="https://github.com/user-attachments/assets/3113d727-eba4-4097-9f5b-b9c7f8461b49" />
<img width="585" height="503" alt="Image" src="https://github.com/user-attachments/assets/3f78fd2f-ef6e-4358-a525-0c34e4810a50" />
The Error Message
■ unexpected status 400 Bad Request: {"success":false,"error":{"name":"ZodError","message":"[\n {\n \"code\": \"invalid_union\",\n
\"errors\": [],\n \"note\": \"No matching discriminator\",\n \"discriminator\": \"type\",\n \"path\": [\n \"tools\",\n 5,
\n \"type\"\n ],\n \"message\": \"Invalid input\"\n }\n]"}}
What is the expected behavior?
Codex should run normally without errors
Additional information
i dont use any VPNs
my node.js version is 22.21.0
my npm version is 10.9.4
Here is when i tried using Codex CLI 0.36.0, The Error is different but still an error
<img width="718" height="457" alt="Image" src="https://github.com/user-attachments/assets/119f7469-6926-4661-b3d5-6c4f83905c56" />
This is when i tried using Codex CLI 0.46.0
<img width="546" height="452" alt="Image" src="https://github.com/user-attachments/assets/e73572f7-9604-4d51-9ddd-343d282edd8e" />
This is my /status output from Codex CLI
<img width="781" height="425" alt="Image" src="https://github.com/user-attachments/assets/d95831ab-8191-4791-a40b-d169a98373e0" />
19 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Same issue as of today on codex CLI (linux x64).
For me, It's only affecting one particular repo in which i'm working. Others are fine.
I tried:
Update - tried also:
Same issue. Now it also seems to affect any directory from which I launch codex in.
Even same issue on Remove Machine as well API Key also.
What is the state ?
OpenAI Codex (v0.63.0)
│ model: gpt-5.1-codex-max
unexpected status 400 Bad Request: {"success":false,"error":
{"name":"ZodError","message":"[\n {\n \"code\": \"invalid_union\",
\n \"errors\": [],\n \"note\": \"No matching discriminator\",\n
\"discriminator\": \"type\",\n \"path\": [\n \"tools\",\n 5,\n
\"type\"\n ],\n \"message\": \"Invalid input\"\n }\n]"}}
downgrade only. or wait for fix
I have the exact same issue. I cannot use codex! Is there any fix for this?
onlly wait for fix.
0.50.0 is ok on ubuntu, but newer vers. crush
Can confirm this is also an issue for me on MacOS.
Using codex v0.63.0.
Got the same Issue using codex-cli 0.63.0 in Fedora 42
The problem still exists on macOS. Has anyone found a fix for this?
■ unexpected status 400 Bad Request: {"success":false,"error":
{"name":"ZodError","message":"[\n {\n \"code\": \"invalid_union\",
\n \"errors\": [],\n \"note\": \"No matching discriminator\",\n
\"discriminator\": \"type\",\n \"path\": [\n \"tools\",\n 5,\n
<img width="566" height="431" alt="Image" src="https://github.com/user-attachments/assets/fd093c1f-c002-4269-9d0f-cd97ef8821ef" />
Im experiencing the same issue. I'm using Codex v0.64.0, MacOS Version 26.1 (25B78)
<img width="762" height="960" alt="Image" src="https://github.com/user-attachments/assets/0288db58-5ccf-42b2-8d8b-c20065a0348b" />
I will also note that Codex works on the same account and network on my windows PC, its just on my Mac/MacOS that it doesn't work
Actually, I managed to solve it for myself. My problem was that I had set OpenAI token URL and API keys in my .zshrc file, pointing to my OpenRouter keys, and had forgotten about it. Despite the fact that I had signed into my Codex with my ChatGPT account, apparently the environment variables were taking priority.
I was able to confirm this by enabling debug logging and checking the output of "~/.codex/log/codex-tui.log", you can see the Zod error appears, and you can see it was trying to connect to OpenRouter
2025-12-03T13:23:54.782586Z WARN stream disconnected - retrying turn (1/5 in 190ms)...
2025-12-03T13:23:54.982593Z DEBUG starting new connection: https://openrouter.ai/
2025-12-03T13:23:54.984617Z DEBUG connecting to xxxx
2025-12-03T13:23:55.010431Z DEBUG connected to xxxx
2025-12-03T13:23:55.214141Z DEBUG pooling idle connection for ("https", openrouter.ai)
2025-12-03T13:23:55.214167Z INFO event.name="codex.api_request" event.timestamp=xxxx conversation.id=xxxx app.version=0.64.0 auth_mode="ChatGPT" user.account_id="xxxx" user.email="xxxxxxx" terminal.type=Apple_Terminal/465 model=gpt-5.1-codex-max slug=gpt-5.1-codex-max duration_ms=231 http.response.status_code=400 error.message="http 400 Bad Request: Some(\"{\\\"success\\\":false,\\\"error\\\":{\\\"name\\\":\\\"ZodError\\\",\\\"message\\\":\\\"[\\\\n {\\\\n \\\\\\\"code\\\\\\\": \\\\\\\"invalid_union\\\\\\\",\\\\n \\\\\\\"errors\\\\\\\": [],\\\\n \\\\\\\"note\\\\\\\": \\\\\\\"No matching discriminator\\\\\\\",\\\\n \\\\\\\"discriminator\\\\\\\": \\\\\\\"type\\\\\\\",\\\\n \\\\\\\"path\\\\\\\": [\\\\n \\\\\\\"tools\\\\\\\",\\\\n 5,\\\\n \\\\\\\"type\\\\\\\"\\\\n ],\\\\n \\\\\\\"message\\\\\\\": \\\\\\\"Invalid input\\\\\\\"\\\\n }\\\\n]\\\"}}\")" attempt=0
i fixed it with claude cli
SOLUTION: Environment Variable Conflict
### Problem Description
Getting persistent
400 Bad Requestwith ZodError:```json
{
"code": "invalid_union",
"note": "No matching discriminator",
"discriminator": "type",
"path": ["tools", 5, "type"],
"message": "Invalid input"
}
Root Cause
Environment variables for third-party API providers override Codex's
built-in authentication.
If you have these variables set (for OpenRouter, custom proxies, etc.):
export OPENAI_API_KEY="sk-or-v1-..." # OpenRouter or other provider
export OPENAI_BASE_URL="https://openrouter.ai/api/v1" # Non-OpenAI
endpoint
Codex will send requests to that URL instead of api.openai.com.
Third-party providers don't support Codex's tools schema, causing
validation errors.
How to Fix
Step 1: Find where the variables are set
grep -n "OPENAI" ~/.zshrc ~/.bashrc ~/.bash_profile ~/.profile
Step 2: Comment them out
# Example from ~/.zshrc
# export OPENAI_API_KEY="sk-or-v1-..."
# export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
Step 3: Reload shell and verify
source ~/.zshrc
env | grep OPENAI # Should return nothing
Step 4: Run Codex
codex # Will use OAuth via ~/.codex/auth.json
Why This Works
~/.codex/auth.json)
tool definitions
Confirmed Working On
Additional Notes
Related Issues
This may also explain similar errors in:
Hope this helps others! 🎉
need to be fixed
@aohan237 The solution has already been specified in the reply by @afilaga above: https://github.com/openai/codex/issues/6408#issuecomment-3609350307
@jmsmistral no, if you use openrouter as your provider, this still exist. it is not the environment issue.
and it is easy to replicate, just switch your provider to openrouter
Mac-Specific Bug (Apple Silicon)
I can confirm this is a Mac binary bug. Here's proof:
BROKEN ❌ - Mac (Apple Silicon)
WORKING ✅ - Windows
Proof this is Mac-specific:
Same version, same API key, same model, same config → Windows works, Mac fails consistently.
Error:
```json
{"code": "invalid_union", "note": "No matching discriminator",
"discriminator": "type", "path": ["tools", 5, "type"]}
Impact: Blocks ALL Mac Apple Silicon users. Tested v0.50.0, v0.76.0, v0.77.0 - all fail on Mac.
Request: Please audit the Mac binary build (aarch64-apple-darwin) for tool serialization differences vs Windows.
★ Insight ─────────────────────────────────────Cross-platform debugging:
─────────────────────────────────────────────────This info will massively help OpenAI prioritize the fix since it narrows the bug to the Mac build specifically.
Sources:
If you encounter this problem, you probably have a
OPENAI_BASE_URLenvironment variable defined that points to a LLM proxy or router, which is returning this error. To fix, unset theOPENAI_BASE_URLenv variable and/or report the bug to the maintainers of the proxy or router.