FastAPI 0.159.1 has landed with a focused feature release aimed at developers working with form-encoded request bodies. The headline addition is support for optional unions of form models, a change that extends how the framework handles form data validation and parsing in more complex type annotations.
The release is small but targeted. The concrete change:
- Optional union support for form models: FastAPI can now accept form payloads typed as an optional union of form models, meaning endpoints can declare a form parameter that is either one of several model shapes or absent entirely. Contributed by @tiangolo in PR #16586.
For developers, this closes a long-standing gap between what type annotations express and what FastAPI's form parsing could actually handle at runtime. Optional unions are common in real APIs: a form submission may carry different field sets depending on context, or may be omitted altogether. Previously, modeling this with form data required looser typing or manual request parsing. With 0.159.1, the declared type better reflects the runtime behavior, and FastAPI's validation and generated docs follow the model definition automatically.
This matters because form-heavy endpoints, such as uploads, settings panels, and legacy-compatible APIs, tend to accumulate conditional fields. Being able to express those as optional unions of form models keeps schemas explicit, improves OpenAPI output, and reduces boilerplate validation code. Teams on recent releases should consider bumping to 0.159.1 if their form endpoints use optional or union-typed payloads. As always, pin the version in your dependency file and run your test suite after upgrading.
Source: https://github.com/fastapi/fastapi/releases/tag/0.159.1