Jump to solution
Verify

The Fix

pip install fastapi==0.128.4

Based on closed fastapi/fastapi issue #13400 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -51,6 +51,22 @@ For example, if the client tries to send a `tool` header with a value of `plumbu ``` +## Disable Convert Underscores + +The same way as with regular header parameters, when you have underscore characters in the parameter names, they are **automatically converted to hyphens**.
repro.py
from typing import Annotated, TypeAlias from fastapi import FastAPI, Header from pydantic import BaseModel app = FastAPI() class CommonHeaders(BaseModel): host: str save_data: bool if_modified_since: str | None = None traceparent: str | None = None x_tag: list[str] = [] CommonHeadersAnnotated: TypeAlias = Annotated[CommonHeaders, Header()] @app.get("/items/") async def read_items(headers: CommonHeadersAnnotated): return headers @app.get("/items2/") async def read_items2(x_prd_code: Annotated[str, Header()], headers: CommonHeadersAnnotated): return headers
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install fastapi==0.128.4\nWhen NOT to use: This fix is not applicable if you require underscores in header names for compatibility with certain clients.\n\n

Why This Fix Works in Production

  • Trigger: Header parameter and model handling does not work as expected
  • Mechanism: The underscore characters in header parameter names were not being converted to hyphens in FastAPI's Pydantic models
  • Why the fix works: Fixes the bug where underscore characters in header parameter names were not being converted to hyphens in FastAPI's Pydantic models. (first fixed release: 0.128.4).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • The underscore characters in header parameter names were not being converted to hyphens in FastAPI's Pydantic models
  • Production symptom (often without a traceback): Header parameter and model handling does not work as expected

Proof / Evidence

Verified Execution

We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.

  • Status: PASS
  • Ran: 2026-02-11T16:52:29Z
  • Package: fastapi
  • Fixed: 0.128.4
  • Mode: fixed_only
  • Outcome: ok
Logs
affected (exit=None)
fixed (exit=0)

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Thanks for the discussion, everyone! Let's split this into two things”
@tiangolo · 2025-03-23 · confirmation · source
“I'll look into cleaning up the code to fit more within the analyze_param function and then could look into creating a PR for it”
@Whizzo123 · 2025-02-27 · source
“I will not have time to look into this myself, but it would be good to have this fixed as one should be able to…”
@DuplosFidibuss · 2025-02-21 · source
“This is a feature request, not a bug. FastAPI doesn't support it yet.”
@Kludex · 2025-02-21 · source

Failure Signature (Search String)

  • Header parameter and model handling does not work as expected
  • traceparent: str | None = None
Copy-friendly signature
signature.txt
Failure Signature ----------------- Header parameter and model handling does not work as expected traceparent: str | None = None

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Header parameter and model handling does not work as expected traceparent: str | None = None

Minimal Reproduction

repro.py
from typing import Annotated, TypeAlias from fastapi import FastAPI, Header from pydantic import BaseModel app = FastAPI() class CommonHeaders(BaseModel): host: str save_data: bool if_modified_since: str | None = None traceparent: str | None = None x_tag: list[str] = [] CommonHeadersAnnotated: TypeAlias = Annotated[CommonHeaders, Header()] @app.get("/items/") async def read_items(headers: CommonHeadersAnnotated): return headers @app.get("/items2/") async def read_items2(x_prd_code: Annotated[str, Header()], headers: CommonHeadersAnnotated): return headers

What Broke

Swagger UI fails to display headers correctly, leading to confusion in API usage.

Why It Broke

The underscore characters in header parameter names were not being converted to hyphens in FastAPI's Pydantic models

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install fastapi==0.128.4

When NOT to use: This fix is not applicable if you require underscores in header names for compatibility with certain clients.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/fastapi/fastapi/pull/13515

First fixed release: 0.128.4

Last verified: 2026-02-08. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if you require underscores in header names for compatibility with certain clients.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Version Compatibility Table

VersionStatus
0.128.4 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.