FastAPI 0.141.1 is now available, bringing a targeted fix for app.frontend() and improved CLI documentation. This patch release resolves inconsistency when combining background tasks with headers from dependencies in the frontend routing method, and clarifies the use of the FASTAPI_ENV environment variable in the CLI guide.
Key Changes
- Fixed background tasks in
app.frontend(): Dependencies that set response headers (e.g., viaResponse.headers) are now correctly processed before background tasks run. Previously, headers set by dependencies could be lost whenbackground_taskswere used in the same endpoint. Fixes PR #16105 by @tiangolo. - Added documentation for
FASTAPI_ENV: The FastAPI CLI guide now explains howFASTAPI_ENVcontrols environment-specific behavior (e.g., development vs. production) when using thefastapi devorfastapi runcommands. PR #16104 by @tiangolo.
Why It Matters
For developers building server-rendered frontends with app.frontend(), this fix ensures that background tasks (like sending emails or logging) see the correct headers, preserving important context from dependency injection. Meanwhile, the new docs on FASTAPI_ENV help teams standardize environment configuration, reducing surprises when moving from development to production. Together, these updates make FastAPI more robust for full-stack applications and enhance developer experience.
Source: https://github.com/fastapi/fastapi/releases/tag/0.141.1