Skip to main content

Overview

FastAPI provides advanced configuration options for path operation decorators that give you fine-grained control over your API’s behavior and OpenAPI documentation.

Operation ID

You can set a custom operation ID for your path operation. This is particularly useful when generating API clients, as the operation ID becomes the function name in the generated client.
Make sure your operation_id is unique across all operations in your API. FastAPI won’t validate this for you.

Summary and Description

You can add a summary and description to your path operations:
The docstring becomes the description in the OpenAPI schema, while the summary parameter provides a short title.

Response Description

Customize the description of the successful response:
The default response_description is “Successful Response”.

Deprecation

Mark an endpoint as deprecated:
This will show the endpoint as deprecated in the interactive API docs.

Tags

Organize your endpoints with tags:
Tags group related endpoints together in the API documentation.

Include in Schema

Exclude an endpoint from the OpenAPI schema:
This is useful for internal endpoints that you don’t want to expose in your API documentation.

OpenAPI Extra

Add custom OpenAPI fields that aren’t directly supported:
The openapi_extra dictionary is merged into the OpenAPI schema for this path operation.

Generate Unique ID Function

Customize how operation IDs are generated:
This is particularly useful when generating API clients, as it affects the generated function names.

Callbacks

Define OpenAPI callbacks for webhooks that your API will call:
Callbacks are for documentation purposes in OpenAPI. You still need to implement the actual HTTP calls to the callback URLs in your endpoint logic.

Response Class

Specify the default response class for an endpoint:
See Custom Response Classes for more details.

All Parameters Together

Here’s an example using multiple advanced parameters: