Status 400 Bad Request, Error Name: ZodError

Resolved 💬 19 comments Opened Nov 9, 2025 by SatuSattr Closed Jan 7, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

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" />

View original on GitHub ↗

19 Comments

github-actions[bot] contributor · 8 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #5990
  • #6004
  • #5002
  • #4437
  • #6226

Powered by Codex Action

SlapDrone · 8 months ago

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:

  • downgrading (0.56, 0.55, 0.54) to no avail.
  • logging out and in again
SlapDrone · 8 months ago

Update - tried also:

  • updating npm/node, fresh install
  • deleting ~/.codex
  • logging into a different account

Same issue. Now it also seems to affect any directory from which I launch codex in.

rajivmehtapy · 8 months ago

Even same issue on Remove Machine as well API Key also.

boethigp-github · 8 months ago

What is the state ?

afilaga · 8 months ago

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

Zenchess · 7 months ago

I have the exact same issue. I cannot use codex! Is there any fix for this?

afilaga · 7 months ago

onlly wait for fix.
0.50.0 is ok on ubuntu, but newer vers. crush

jmsmistral · 7 months ago

Can confirm this is also an issue for me on MacOS.
Using codex v0.63.0.

mospina · 7 months ago

Got the same Issue using codex-cli 0.63.0 in Fedora 42

afilaga · 7 months ago

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" />

nabagaca · 7 months ago

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

nabagaca · 7 months ago

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

afilaga · 7 months ago

i fixed it with claude cli

SOLUTION: Environment Variable Conflict

### Problem Description
Getting persistent 400 Bad Request with 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 uses OAuth authentication by default (stored in

~/.codex/auth.json)

  • Environment variables OPENAI_API_KEY and OPENAI_BASE_URL override this
  • Third-party API providers (OpenRouter, custom proxies) reject Codex's

tool definitions

  • Removing the env vars forces Codex to use official OpenAI API

Confirmed Working On

  • ✅ macOS Intel (x86_64)
  • ✅ macOS Apple Silicon (ARM64)
  • ✅ Linux
  • ✅ Codex versions: 0.29.0 - 0.64.0

Additional Notes

  • On Ubuntu/Linux servers without these env vars: works fine
  • On macOS with OpenRouter integration: fails with tools[5] error
  • This explains why the issue is environment-specific and not a Codex bug

Related Issues

This may also explain similar errors in:

  • #2204 (MCP tool conversion failures)
  • #5002 (web_search tool issues)
  • #7267 (version 0.63.0 specific problems)

Hope this helps others! 🎉

aohan237 · 7 months ago

need to be fixed

jmsmistral · 7 months ago
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

aohan237 · 7 months ago
> need to be fixed @aohan237 The solution has already been specified in the reply by @afilaga above: #6408 (comment)

@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

fuzzystripes · 6 months ago

Mac-Specific Bug (Apple Silicon)

I can confirm this is a Mac binary bug. Here's proof:

BROKEN ❌ - Mac (Apple Silicon)

  • OS: macOS Darwin 25.1.0 (arm64)
  • Codex: v0.77.0
  • Binary: aarch64-apple-darwin (31MB)
  • Result: ZodError at tools[5].type every single time

WORKING ✅ - Windows

  • Codex: v0.77.0 (same version)
  • API Key: Same account
  • Model: gpt-5.2-codex (same model)
  • Result: Works perfectly

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:

  1. Same binary version ≠ same compiled code - different platforms can have different dependencies/validation
  2. Rust binaries bundle everything - Mac vs Windows builds may have different Zod versions compiled in
  3. Binary size differences (31MB Mac vs 42MB Windows) hint at different compilation or dependencies

─────────────────────────────────────────────────

This info will massively help OpenAI prioritize the fix since it narrows the bug to the Mac build specifically.

Sources:

etraut-openai contributor · 6 months ago

If you encounter this problem, you probably have a OPENAI_BASE_URL environment variable defined that points to a LLM proxy or router, which is returning this error. To fix, unset the OPENAI_BASE_URL env variable and/or report the bug to the maintainers of the proxy or router.