Skip to main content

API Info and Metadata

When you create a FastAPI application, you can configure global metadata that appears in the autogenerated OpenAPI schema and interactive documentation (Swagger UI and ReDoc). This metadata is defined using the FastAPI constructor and follows the OpenAPI Info object structure.

Configure Basic Metadataโ€‹

You can set the API title, version, and a detailed description directly in the FastAPI class. The description field supports Markdown, allowing you to include formatted text, lists, and links.

from fastapi import FastAPI

description = """
ChimichangApp API helps you do awesome stuff. ๐Ÿš€

## Items

You can **read items**.

## Users

You will be able to:

* **Create users** (_not implemented_).
* **Read users** (_not implemented_).
"""

app = FastAPI(
title="ChimichangApp",
description=description,
summary="Deadpool's favorite app. Nuff said.",
version="0.0.1",
terms_of_service="http://example.com/terms/",
)

Metadata Fieldsโ€‹

  • title: The name of your API. Defaults to "FastAPI".
  • summary: A short summary of the API (available in OpenAPI 3.1.0+).
  • description: A long description of the API. Supports CommonMark Markdown.
  • version: The version of your specific API (e.g., 2.5.0). This is distinct from the FastAPI or OpenAPI version.
  • terms_of_service: A URL to the terms of service for the API.

Add Contact Informationโ€‹

To provide contact details for the API, pass a dictionary to the contact parameter. This dictionary corresponds to the Contact model in fastapi.openapi.models.

from fastapi import FastAPI

app = FastAPI(
contact={
"name": "Deadpoolio the Amazing",
"url": "http://x-force.example.com/contact/",
"email": "dp@x-force.example.com",
},
)

The contact dictionary can include:

  • name: The identifying name of the contact person/organization.
  • url: A URL pointing to the contact information.
  • email: The email address of the contact person/organization.

Define License Informationโ€‹

You can specify the license for your API using the license_info parameter. This maps to the License model in fastapi.openapi.models.

Using a License URLโ€‹

The traditional way to provide a license is by name and a URL:

from fastapi import FastAPI

app = FastAPI(
license_info={
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html",
},
)

Using an SPDX Identifierโ€‹

OpenAPI 3.1.0 (supported in FastAPI 0.99.0+) allows using an SPDX license identifier instead of a URL. The identifier and url fields are mutually exclusive.

from fastapi import FastAPI

app = FastAPI(
license_info={
"name": "Apache 2.0",
"identifier": "Apache-2.0",
},
)

Internal OpenAPI Modelsโ€‹

FastAPI uses Pydantic models defined in fastapi.openapi.models to represent the OpenAPI schema. While you typically pass dictionaries to the FastAPI constructor, these dictionaries are validated against and converted into the following classes:

  • Info: The container for all global metadata.
  • Contact: Represents contact information.
  • License: Represents license information.

These models inherit from BaseModelWithConfig, which is configured to allow extra fields (extra: "allow"), enabling you to include custom OpenAPI extensions (fields starting with x-) in your metadata.

Troubleshootingโ€‹

Email Validationโ€‹

The email field in the Contact model uses a custom EmailStr type.

  • If the email-validator package is installed, FastAPI performs full email validation.
  • If email-validator is not installed, FastAPI treats the field as a plain string and logs a warning: email-validator not installed, email fields will be treated as str.

To enable validation, install the dependency:

pip install email-validator

Field Namingโ€‹

Note that while the FastAPI constructor uses Python-style snake_case for parameters (e.g., terms_of_service), the underlying Info model uses the camelCase names required by the OpenAPI specification (e.g., termsOfService). FastAPI handles this conversion automatically when generating the schema.