Create or import your app
Frameworks

Create a FastAPI app or use an existing one:
FastAPI
Deploy a FastAPI app to Vercel with the Python runtime and Vercel Functions. Vercel looks for a FastAPI instance named app at supported entrypoints in your repository.
Copy page
Deploy a FastAPI app on Vercel
Initialize a new FastAPI project with the Vercel CLI init command:
vc initfastapi
This clones the FastAPI example repository in a directory called fastapi.
Exporting the FastAPI application
To run a FastAPI application on Vercel, define an app instance that initializes FastAPI at a supported entrypoint:
- app.py, index.py, server.py, main.py, wsgi.py, or asgi.py
- the same filenames inside src/ or app/
For example:
@app.get("/")
app =FastAPI()
from fastapi import FastAPI
[tool.vercel]
defread_root():
return{"Python":"on Vercel"}
[tool.vercel.scripts]
For example:
if__name__=="__main__":
build ="python build.py"
f.write("BUILD_COMMAND")
main()
defmain():
withopen("build.txt", "w")as f:
print("Running build command...")
The build property in [tool.vercel.scripts] defines the Build Command for FastAPI deployments. It runs after dependencies are installed and before your application is deployed.
Build
Command in
vercel.json or in the Project Settings dashboard, it takes precedence over a
build script in
pyproject.toml.
Use vercel dev to run your application locally.
python -mvenv.venv
source.venv/bin/activate
pip install-rrequirements.txt
vercel dev
Deploy the project by connecting your Git repository or by using the Vercel CLI:
vc deploy
Serving frontend and static assets
Vercel supports two methods for serving frontend and static assets with FastAPI.
Place files in a public/ directory at your project root. Vercel serves them from the CDN at the matching root URL paths. For example, public/logo.svg is served at /logo.svg. Default response headers apply unless you override them in vercel.json.
from fastapi import FastAPI
app =FastAPI()
asyncdeffavicon():
from fastapi.responses import RedirectResponse
returnRedirectResponse("/vercel.svg", status_code=307)
@app.get("/favicon.ico", include_in_schema=False)
# /vercel.svg is served automatically from public/vercel.svg.
Do not mount the
public/
directory with
app.mount()
. Vercel handles it at the platform level.
Built-in FastAPI frontend and static file support
When using app.frontend() or app.mount() with StaticFiles, files are promoted to the CDN at build time:
app.frontend
app =FastAPI()
defhello():
@app.get("/api/hello")
return{"message":"Hello"}
from fastapi import FastAPI
app.frontend("/", directory="dist")
Promoted source directories are kept in the function bundle by default so the app can read from them at runtime. To exclude them and serve files from the CDN only, set exclude = true:
exclude =true
[tool.vercel.fastapi.static]
Files are served from the CDN at the mount's URL prefix. Route declaration order determines which wins when a route and a CDN file share the same path:
See Configuration for all available settings.
- A route declared before the mount takes priority over CDN files. Matching requests reach the function.
- A route declared after the mount does not take priority. Matching requests are served from the CDN.
File served
from fastapi.staticfiles import StaticFiles
"auto"
@app.get("/static/protected.json")
app =FastAPI()
return{"access":"denied"}
Status
fallback value
app.mount("/static", StaticFiles(directory="static"))
defprotected():
When applied
All misses
Navigation requests only
"404.html"
# Declared before the mount, so this route wins over any CDN file at this path.
n/a
"index.html"
See notes below
index.html
An index.html fallback applies to navigation requests only: requests with an explicit text/html or application/xhtml+xml Accept header and an extension-less final URL segment (for example, /dashboard but not /dashboard/app.js). All other misses reach the function. A 404.html fallback applies to every miss regardless of the Accept header. If "auto" is set but neither file exists in the build directory, no fallback is applied.
Fallback routes apply to GET and HEAD requests only. All other methods always reach the function.
CDN-served files bypass the function entirely, so middleware handlers and Depends() guards do not run for them.
Vercel detects these cases and keeps the affected static files and frontends in the function rather than promoting them to the CDN:
- Top-level middleware: All static mounts and frontends stay in the function.
- Sub-app middleware: Only that sub-app's mounts stay in the function. Mounts elsewhere are still promoted.
- Frontend dependencies: Frontends with Depends() guards stay in the function.
Set cdn = true to promote files to the CDN even when middleware or dependency guards are present:
[tool.vercel.fastapi.static]
cdn =true
All settings go under [tool.vercel.fastapi.static] in pyproject.toml.
Our Services
Setting
cdn
CDN promotion always enabled, even when middleware or dependency guards are present.
omitted (default)
Value
CDN promotion enabled. Disabled automatically when middleware or dependency guards are present.
true
cdn
exclude
false (default)
CDN promotion disabled. All requests reach the function.
cdn
Promoted source directories are kept in the function bundle.
Software Delivery
exclude
false
Description
Promoted source directories are excluded from the function bundle.
true
Startup and shutdown
You can use FastAPI lifespan events to manage startup and shutdown logic, such as initializing and closing database connections.
@asynccontextmanager
from fastapi import FastAPI
# Startup logic
print("Starting up...")
from contextlib import asynccontextmanager
yield
# Shutdown logic
awaitstartup_tasks()
awaitcleanup_tasks()
asyncdeflifespan(app: FastAPI):
app =FastAPI(lifespan=lifespan)
Vercel Functions
SIGTERM
signal.
Logs printed during the shutdown step will not appear in the Vercel dashboard.
When you deploy a FastAPI app to Vercel, it becomes a single Vercel Function. Vercel uses Fluid compute by default, so the function scales with traffic.
To configure that function, add an entry to the functions object in vercel.json keyed by your resolved entrypoint file. For example, to let an app defined in app/main.py run for up to 60 seconds, set maxDuration:
{
}
"functions": {
"app/main.py": {
"$schema":"https://openapi.vercel.sh/vercel.json",
For more options, see Configuring functions and the functions property.
}
}
"maxDuration":60
All Vercel Functions limitations apply to FastAPI applications, including:
Application size: The FastAPI application becomes a single bundle, which has a standard bundle size limit of 500MB. Large Functions support Python bundles up to 5GB on Fluid compute when enabled (public beta).
More resources
Last updated August 27, 2026
For more about deploying FastAPI on Vercel, see:
Can you trust our partners?
Cross-link map: Deploy a FastAPI app on Vercel (/docs/frameworks/backend/fastapi)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesHow to ship a FastAPI app on Vercel — Deploy a FastAPI app to Vercel with zero configuration. Learn how the Python runtime, Vercel Functions, streaming, middlDeploy a Flask app on Vercel — Deploy a Flask app on Vercel. Learn how the Python runtime, WSGI, static assets, and Vercel Functions work together.Fastify on Vercel — Deploy Fastify applications to Vercel with zero configuration.How to ship a Fastify app on Vercel — Deploy a Fastify app to Vercel with zero configuration, then add streaming, lifecycle hooks, cron jobs, and observabilitBuild with a FastAPI starter template — Browse FastAPI starter templates for Vercel and deploy one in a few steps. Compare minimal, AI, agent, and full-stack FaThis page links to (7)Vercel CDN overview — Vercel's CDN is a globally distributed platform that handles routing, caching, security, and compression for every deplovercel deploy — Learn how to deploy your Vercel projects using the vercel deploy CLI command.vercel init — Learn how to initialize Vercel supported framework examples locally using the vercel init CLI command.Vercel Functions — Build API routes, webhooks, and agent request handlers with Vercel Functions, then test and debug them with Vercel CLI.Vercel Functions Limits — Learn about the limits and restrictions of using Vercel Functions.Build with a FastAPI starter template — Browse FastAPI starter templates for Vercel and deploy one in a few steps. Compare minimal, AI, agent, and full-stack FaHow to ship a FastAPI app on Vercel — Deploy a FastAPI app to Vercel with zero configuration. Learn how the Python runtime, Vercel Functions, streaming, middlPages that link here (13)By site: vercel-changelog (4) · vercel-kb (5) · vercel-docs (4)From vercel-changelogFastAPI frontends and static files served from the CDNFastAPI Lifespan Events are now supported on VercelVercel now supports Build Commands for FastAPI and FlaskZero-configuration FastAPI backendsFrom vercel-kbBuild with a FastAPI starter template — Browse FastAPI starter templates for Vercel and deploy one in a few steps. Compare minimal, AI, agent, and full-stack FaBuild an agentic app in FastAPI with OpenAI Agents API and Vercel Sandbox — Learn how to build a repository Q&A app using FastAPI, OpenAI Agents API, and Vercel Sandbox, with isolated code inspectBuild Figma-style multiplayer cursors with WebSockets on Vercel — Learn how to build Figma-style multiplayer cursors with Next.js and FastAPI, kept consistent across multiple Vercel FuncHow to ship a FastAPI app on Vercel — Deploy a FastAPI app to Vercel with zero configuration. Learn how the Python runtime, Vercel Functions, streaming, middlBuild a Weather API on Vercel: Express, FastAPI, and Nitro — Build a weather API on Vercel with FastAPI, Express, or Nitro. Compare the three runtimes, add caching and ObservabilityFrom vercel-docsDeploy Dramatiq workers on Vercel — Deploy Dramatiq workers on Vercel. Learn how Dramatiq actors use Vercel Queues and Vercel Functions to process backgrounUsing the Python Runtime with Vercel Functions — Learn how to use the Python runtime to run Python applications on Vercel.Python Functions in the /api Directory — Configure existing Vercel projects that use file-based Python functions in an /api directory.Projects overview — A project is where you deploy and operate frontend apps, APIs, backends, containers, and agent workloads on Vercel.
Was this helpful?