Jump to solution
Verify

The Fix

pip install fastapi==0.128.5

Based on closed fastapi/fastapi issue #10236 · 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
@@ -1056,7 +1056,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: self, path: str, - endpoint: Callable[..., Coroutine[Any, Any, Response]], + endpoint: Callable[..., Any], *,
repro.py
### Direct mounting of routes import pathlib from fastapi import FastAPI, APIRouter import uvicorn import pydantic class HelloRequest(pydantic.BaseModel): id: str class HelloResponse(pydantic.BaseModel): hello: str class Hello: def __init__(self, name: str) -> None: self.name = name async def handle(self, request: HelloRequest) -> HelloResponse: return HelloResponse(hello=self.name) app = FastAPI() hello_handler = Hello(name="test") app.add_api_route("/hello", hello_handler.handle, methods=["POST"]) ### Mounting of paths via Router import pathlib from fastapi import FastAPI, APIRouter import uvicorn import pydantic class HelloRequest(pydantic.BaseModel): id: str class HelloResponse(pydantic.BaseModel): hello: str class Hello: def __init__(self, name: str) -> None: self.name = name async def handle(self, request: HelloRequest) -> HelloResponse: return HelloResponse(hello=self.name) class RootRouter: def __init__(self, name: str): self.router = APIRouter() hello_handler = Hello(name=name) self.router.add_api_route("/hello", hello_handler.handle, methods=["POST"]) app = FastAPI() root_router = RootRouter(name="test") app.include_router(root_router.router)
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.5\nWhen NOT to use: Do not apply this fix if the endpoint type needs to remain strict for specific use cases.\n\n

Why This Fix Works in Production

  • Trigger: error: Argument 2 to "add_api_route" of "FastAPI" has incompatible type "Callable[[HelloRequest], Coroutine[Any, Any, HelloResponse]]"; expected "Callable[...,…
  • Mechanism: Fixes the typing annotation for the `FastAPI.add_api_route()` method to ensure consistency with downstream calls and other utilities.
  • Why the fix works: Fixes the typing annotation for the `FastAPI.add_api_route()` method to ensure consistency with downstream calls and other utilities. (first fixed release: 0.128.5).
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

  • Surfaces as: error: Argument 2 to "add_api_route" of "FastAPI" has incompatible type "Callable[[HelloRequest], Coroutine[Any, Any, HelloResponse]]"; expected "Callable[..., Coroutine[Any, Any,…

Proof / Evidence

Discussion

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

“This is a valid issue. The type hint of both endpoint parameters should match. Should be easy to fix - I don't know which one…”
@Kludex · 2023-09-12 · source
“Hey @Kludex I want to help on this issue if no one is interested, I have used FastAPI before in some hobby projects but this…”
@annis-souames · 2023-09-12 · source
“hi @Kludex Is this still a valid issue? I want to help on this issue if no one is interested”
@eydenbarboza · 2023-11-09 · source
“Hi.. is closed? I like FastAPI and want to contribute..”
@devkan · 2024-03-14 · source

Failure Signature (Search String)

  • error: Argument 2 to "add_api_route" of "FastAPI" has incompatible type "Callable[[HelloRequest], Coroutine[Any, Any, HelloResponse]]"; expected "Callable[..., Coroutine[Any, Any,

Error Message

Stack trace
error.txt
Error Message ------------- error: Argument 2 to "add_api_route" of "FastAPI" has incompatible type "Callable[[HelloRequest], Coroutine[Any, Any, HelloResponse]]"; expected "Callable[..., Coroutine[Any, Any, Response]]" [arg-type]

Minimal Reproduction

repro.py
### Direct mounting of routes import pathlib from fastapi import FastAPI, APIRouter import uvicorn import pydantic class HelloRequest(pydantic.BaseModel): id: str class HelloResponse(pydantic.BaseModel): hello: str class Hello: def __init__(self, name: str) -> None: self.name = name async def handle(self, request: HelloRequest) -> HelloResponse: return HelloResponse(hello=self.name) app = FastAPI() hello_handler = Hello(name="test") app.add_api_route("/hello", hello_handler.handle, methods=["POST"]) ### Mounting of paths via Router import pathlib from fastapi import FastAPI, APIRouter import uvicorn import pydantic class HelloRequest(pydantic.BaseModel): id: str class HelloResponse(pydantic.BaseModel): hello: str class Hello: def __init__(self, name: str) -> None: self.name = name async def handle(self, request: HelloRequest) -> HelloResponse: return HelloResponse(hello=self.name) class RootRouter: def __init__(self, name: str): self.router = APIRouter() hello_handler = Hello(name=name) self.router.add_api_route("/hello", hello_handler.handle, methods=["POST"]) app = FastAPI() root_router = RootRouter(name="test") app.include_router(root_router.router)

What Broke

Mypy raises type errors when using add_api_route with certain callable types.

Fix Options (Details)

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

pip install fastapi==0.128.5

When NOT to use: Do not apply this fix if the endpoint type needs to remain strict for specific use cases.

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

First fixed release: 0.128.5

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not apply this fix if the endpoint type needs to remain strict for specific use cases.

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.5 Fixed

Related Issues

No related fixes found.

Sources

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