FastAPI on Vercel

FastAPI is a modern, high-performance, web framework for building APIs with Python based on standard Python type hints. You can deploy a FastAPI app to Vercel with zero configuration.

You can quickly deploy a FastAPI application to Vercel by creating a FastAPI app or using an existing one:

Get started by initializing a new FastAPI project using Vercel CLI init command:

terminal
vc init fastapi

This will clone the FastAPI example repository in a directory called fastapi.

To run a FastAPI application on Vercel, define an app instance that initializes FastAPI at any of the following entrypoints:

  • app.py
  • index.py
  • server.py
  • src/app.py
  • src/index.py
  • src/server.py
  • app/app.py
  • app/index.py
  • app/server.py

For example:

src/index.py
from fastapi import FastAPI   app = FastAPI()   @app.get("/") def read_root():  return {"Python": "on Vercel"}

Use vercel dev to run your application locally.

terminal
python -m venv .venv source .venv/bin/activate pip install -r requirements.txt vercel dev
Minimum CLI version required: 48.1.8

To deploy, connect your Git repository or use Vercel CLI:

terminal
vc deploy
Minimum CLI version required: 48.1.8

To serve static assets, place them in the public/** directory. They will be served as a part of our Edge Network using default headers unless otherwise specified in vercel.json.

app.py
from fastapi import FastAPI from fastapi.responses import RedirectResponse   app = FastAPI()   @app.get("/favicon.ico", include_in_schema=False) async def favicon():  # /vercel.svg is automatically served when included in the public/** directory.  return RedirectResponse("/vercel.svg", status_code=307)
app.mount("/public", ...) is not needed and should not be used.

When you deploy a FastAPI app to Vercel, the application becomes a single Vercel Function and uses Fluid compute by default. This means your FastAPI app will automatically scale up and down based on traffic.

All Vercel Functions limitations apply to FastAPI applications, including:

  • Application size: The FastAPI application becomes a single bundle, which must fit within the 250MB limit of Vercel Functions. Our bundling process removes __pycache__ and .pyc files from the deployment's bundle to reduce size, but does not perform application bundling.

Learn more about deploying FastAPI projects on Vercel with the following resources:


Was this helpful?