Skip to main content

API Information and Metadata

To configure basic API details such as the title, version, contact information, and licensing terms in a FastAPI application, you pass metadata arguments directly to the FastAPI constructor. These details are used to populate the OpenAPI Info object, which is visible in the auto-generated documentation (e.g., /docs).

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/",
contact={
"name": "Deadpoolio the Amazing",
"url": "http://x-force.example.com/contact/",
"email": "dp@x-force.example.com",
},
license_info={
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html",
},
)

Metadata Fieldsโ€‹

The metadata you provide is internally mapped to the Info model defined in fastapi.openapi.models.

  • title: The name of your API. Defaults to "FastAPI".
  • summary: A short, one-line summary of the API.
  • description: A longer description of the API. This field supports Markdown (CommonMark), which will be rendered in the Swagger UI and ReDoc interfaces.
  • version: The version of your specific application (e.g., "2.5.0"), not the OpenAPI version.
  • terms_of_service: A URL string pointing to the terms of service for the API.
  • contact: A dictionary containing contact information. This maps to the Contact model and can include:
    • name: The name of the contact person or organization.
    • url: A URL pointing to the contact information.
    • email: A string that must be a valid email format.
  • license_info: A dictionary containing licensing information. This maps to the License model.

Configuring License Informationโ€‹

The license_info parameter requires a name and allows either a url or an identifier.

Using a License URLโ€‹

This is the standard way to link to a full license text.

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

Using an SPDX Identifierโ€‹

If you are using a standard license, you can provide an SPDX identifier instead of a URL. This is supported in OpenAPI 3.1.0.

app = FastAPI(
license_info={
"name": "MIT License",
"identifier": "MIT",
}
)

Troubleshootingโ€‹

Email Validation in Contactโ€‹

The email field in the contact dictionary uses the EmailStr type from fastapi.openapi.models.

  • Requirement: For actual email format validation, you must install the email-validator package:
    pip install email-validator
  • Fallback: If email-validator is not installed, FastAPI will treat the email field as a plain string and log a warning: "email-validator not installed, email fields will be treated as str."

License Field Conflictsโ€‹

In the OpenAPI 3.1.0 specification (which this version of FastAPI uses), the identifier and url fields in the License model are intended to be mutually exclusive. While the License class allows both, it is recommended to provide only one to ensure strict compliance with the OpenAPI schema.