FastAPI 0.159.0 Adds Optional Query, Header, and Cookie Parameter Models

FastAPI·22 Oct 2026·2 min read

#fastapi

FastAPI has released version 0.159.0, a feature update that expands how developers can declare request parameters. The headline addition is support for optional query, header, and cookie parameter models, contributed by @tiangolo in PR #16584. This builds on FastAPI's existing ability to group parameters into Pydantic models, extending it so those model-based parameters can now be optional rather than required.

Concrete changes in this release:

  • Optional parameter models: query, header, and cookie parameters can now be declared using models that are optional, giving developers finer control over which grouped inputs must be present.
  • Query parameters: optional model support for query strings.
  • Header parameters: optional model support for request headers.
  • Cookie parameters: optional model support for cookies.
  • Implemented via PR #16584 by @tiangolo.

Previously, grouping parameters into a single Pydantic model was a convenient way to keep endpoint signatures clean, but the model itself was effectively required. With 0.159.0, an optional model lets the entire set of parameters be absent from a request, which is useful for endpoints where a cluster of related inputs (for example, pagination or filtering options carried in a query model, or a bundle of optional headers or cookies) should only apply when the caller supplies them. FastAPI validates the grouped values against the model while allowing the whole group to be omitted.

For developers, this reduces boilerplate. Instead of individually marking every related parameter as optional or writing conditional validation logic, you can define one model and make it optional as a unit. It keeps route signatures tidy, preserves automatic validation and OpenAPI documentation, and makes the intent clearer for APIs that have optional clusters of inputs.

Upgrading is straightforward for projects already using parameter models. If you rely on grouped query, header, or cookie inputs that are only sometimes present, this version is worth adopting to simplify your schemas.

Source: https://github.com/fastapi/fastapi/releases/tag/0.159.0

Related

auto-curated · source linked above← all news