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%.
@@ -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],
*,
### 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)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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
- GitHub issue: #10236
- Fix PR: https://github.com/fastapi/fastapi/pull/10240
- First fixed release: 0.128.5
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.38
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…”
“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…”
“hi @Kludex Is this still a valid issue? I want to help on this issue if no one is interested”
“Hi.. is closed? I like FastAPI and want to contribute..”
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 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
### 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
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.
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
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
| Version | Status |
|---|---|
| 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.