{"id":"pg_cxzclerjkj5k","property_id":"prp_pklgwresh6hp","domain_id":"dom_zrkwapcbulfb","root_domain":"vercel.com","locale":"en","url":"https://vercel.com/docs/frameworks/backend/fastapi","url_hash":"1859e83f425d14cda623be13c03b0106664c16325e54a0b32b05ea3f75c8d5ff","path":"/docs/frameworks/backend/fastapi","depth":1,"canonical_url":"https://vercel.com/docs/frameworks/backend/fastapi","canonical_page_id":null,"page_type":"docs","page_type_guess":"docs","state":"indexed","skip_reason":"budget","priority":"1.4","discovered_via":"sitemap","first_seen_at":"2026-08-27T09:05:09.822Z","last_seen_at":"2026-09-26T09:10:02.787Z","http_status":200,"content_hash":"0344743fca47d87beda2598e61c47a3236f7a4e5a0f44c77ce69d1bd103ba693","title":"Deploy a FastAPI app on Vercel","description":"Deploy a FastAPI app on Vercel. Learn how the Python runtime, ASGI, static assets, and Vercel Functions work together.","author":"Vercel","published_at":null,"modified_at":"2026-08-27T00:20:45.000Z","word_count":907,"reading_time_sec":247,"lang_detected":"en","images":[],"links_out":null,"markdown_source":"readability","refresh_interval":"monthly","last_fetched_at":"2026-09-26T09:09:28.050Z","next_refresh_at":"2026-10-26T09:09:28.050Z","runs_count":1,"changes_count":0,"last_changed_at":null,"fail_count":0,"last_error":null,"created_at":"2026-08-27T09:05:09.822Z","updated_at":"2026-08-27T09:05:09.822Z","inlinks":28,"inlinks_body":8,"outlinks":191,"outlinks_external":13,"anchor_terms":["FastAPI"],"template_score":"0.93333333333333333333","cash":"0.0219156301438378143","cash_total":"0.65060673135517546490","pagerank":"0.0336226975825662","is_orphan":false,"link_confirmed":true,"discovered_wave":0,"embedded_hash":null,"embedded_at":null,"domain_name":"Vercel Inc.","brand_color":null,"domain_rank":579,"spam_score":14,"markdown":"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.\n\nCreate a FastAPI app or use an existing one:\n\nInitialize a new FastAPI project with the [Vercel CLI `init` command](https://vercel.com/docs/cli/init):\n\nThis clones the [FastAPI example repository](https://github.com/vercel/vercel/tree/main/examples/fastapi) in a directory called `fastapi`.\n\nTo run a FastAPI application on Vercel, define an `app` instance that initializes `FastAPI` at a supported entrypoint:\n\n-   `app.py`, `index.py`, `server.py`, `main.py`, `wsgi.py`, or `asgi.py`\n-   the same filenames inside `src/` or `app/`\n\nFor example:\n\nTo point Vercel to a FastAPI app in a custom module, set `tool.vercel.entrypoint` in `pyproject.toml`:\n\nThe `tool.vercel.entrypoint` value tells Vercel to look for a `FastAPI` instance named `app` in `./backend/server.py`.\n\nThe `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.\n\nFor example:\n\nIf you define a [Build Command](https://vercel.com/docs/project-configuration/vercel-json#buildcommand) in `vercel.json` or in the Project Settings dashboard, it takes precedence over a build script in `pyproject.toml`.\n\nUse `vercel dev` to run your application locally.\n\nMinimum CLI version required: 48.1.8\n\nDeploy the project by connecting your Git repository or by using the [Vercel CLI](https://vercel.com/docs/cli/deploy):\n\nMinimum CLI version required: 48.1.8\n\nVercel supports two methods for serving frontend and static assets with FastAPI.\n\nPlace files in a `public/` directory at your project root. Vercel serves them from the [CDN](https://vercel.com/docs/cdn) at the matching root URL paths. For example, `public/logo.svg` is served at `/logo.svg`. Default [response headers](https://vercel.com/docs/headers) apply unless you override them in `vercel.json`.\n\nDo not mount the `public/` directory with `app.mount()`. Vercel handles it at the platform level.\n\nWhen using [`app.frontend()`](https://fastapi.tiangolo.com/tutorial/frontend/) or [`app.mount()`](https://fastapi.tiangolo.com/advanced/sub-applications/) with [`StaticFiles`](https://fastapi.tiangolo.com/tutorial/static-files/), files are promoted to the CDN at build time:\n\nPromoted 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`:\n\nSee [Configuration](#configuration) for all available settings.\n\nFiles 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:\n\n-   A route declared before the mount takes priority over CDN files. Matching requests reach the function.\n-   A route declared after the mount does not take priority. Matching requests are served from the CDN.\n\nThe bare mount root (for example, `/static`) always reaches the function. `StaticFiles` redirects it to the trailing-slash form.\n\n`app.frontend()` registers a low-priority frontend build. Every API route takes priority over frontend files regardless of declaration order.\n\nThe `fallback` parameter controls CDN behavior when no file matches a request under the mount:\n\n`fallback` value\n\nFile served\n\nStatus\n\nWhen applied\n\n`\"auto\"`\n\n`404.html` if present, else `index.html`\n\n`404` or `200`\n\nSee notes below\n\n`\"index.html\"`\n\n`index.html`\n\n`200`\n\nNavigation requests only\n\n`\"404.html\"`\n\n`404.html`\n\n`404`\n\nAll misses\n\n`None`\n\nn/a\n\nn/a\n\nUnmatched paths reach the function\n\nAn `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.\n\nFallback routes apply to `GET` and `HEAD` requests only. All other methods always reach the function.\n\nCDN-served files bypass the function entirely, so [middleware handlers](https://fastapi.tiangolo.com/reference/fastapi/#fastapi.FastAPI.middleware) and [`Depends()`](https://fastapi.tiangolo.com/reference/dependencies/) guards do not run for them.\n\nVercel detects these cases and keeps the affected static files and frontends in the function rather than promoting them to the CDN:\n\n-   Top-level middleware: All static mounts and frontends stay in the function.\n-   Sub-app middleware: Only that sub-app's mounts stay in the function. Mounts elsewhere are still promoted.\n-   Frontend dependencies: Frontends with [`Depends()`](https://fastapi.tiangolo.com/reference/dependencies/) guards stay in the function.\n\nSet `cdn = true` to promote files to the CDN even when middleware or dependency guards are present:\n\nAll settings go under `[tool.vercel.fastapi.static]` in `pyproject.toml`.\n\nSetting\n\nValue\n\nDescription\n\n`cdn`\n\nomitted _(default)_\n\nCDN promotion enabled. Disabled automatically when middleware or dependency guards are present.\n\n`cdn`\n\n`true`\n\nCDN promotion always enabled, even when middleware or dependency guards are present.\n\n`cdn`\n\n`false`\n\nCDN promotion disabled. All requests reach the function.\n\n`exclude`\n\n`false` _(default)_\n\nPromoted source directories are kept in the function bundle.\n\n`exclude`\n\n`true`\n\nPromoted source directories are excluded from the function bundle.\n\nYou can use [FastAPI lifespan events](https://fastapi.tiangolo.com/advanced/events/) to manage startup and shutdown logic, such as initializing and closing database connections.\n\nCleanup logic during shutdown is limited to a maximum of 500ms after receiving the [SIGTERM signal](https://vercel.com/docs/functions/functions-api-reference#sigterm-signal). Logs printed during the shutdown step will not appear in the Vercel dashboard.\n\nWhen you deploy a FastAPI app to Vercel, it becomes a single [Vercel Function](https://vercel.com/docs/functions). Vercel uses [Fluid compute](https://vercel.com/docs/fluid-compute) by default, so the function scales with traffic.\n\nTo configure that function, add an entry to the [`functions` object](https://vercel.com/docs/project-configuration/vercel-json#functions) 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`:\n\nFor more options, see [Configuring functions](https://vercel.com/docs/functions/configuring-functions) and the [`functions` property](https://vercel.com/docs/project-configuration/vercel-json#functions).\n\nAll [Vercel Functions limitations](https://vercel.com/docs/functions/limitations) apply to FastAPI applications, including:\n\n-   Application size: The FastAPI application becomes a single bundle, which has a standard bundle size limit of 500MB. [Large Functions](https://vercel.com/docs/functions/limitations#large-functions-beta) support Python bundles up to 5GB on Fluid compute when enabled (public beta).\n\nFor more about deploying FastAPI on Vercel, see:","storage":{"htmlKey":"stealpage/html/vercel.com/pg_cxzclerjkj5k/run_qkyu4icrdbn3.html.gz","markdownKey":"stealpage/md/vercel.com/pg_cxzclerjkj5k/run_qkyu4icrdbn3.md.gz"},"facets":null,"assets":[{"kind":"image","src_url":"https://vercel-docs.vercel.sh/vc-ap-0cca3e/_next/static/immutable/media/vercel-light.3_gxxexgi1nmy.svg","r2_key":null,"alt":"Vercel","caption":null,"width":16,"height":14,"is_hero":false,"zone":"footer"},{"kind":"image","src_url":"https://vercel-docs.vercel.sh/vc-ap-0cca3e/_next/static/immutable/media/vercel-dark.1f3cgy23m5_jy.svg","r2_key":null,"alt":"Vercel","caption":null,"width":16,"height":14,"is_hero":false,"zone":"footer"}],"shots":[{"viewport":"mobile","width":390,"height":844,"r2_key":"stealpage/shots/vercel.com/pg_cxzclerjkj5k/run_qkyu4icrdbn3-mobile.png","phash":"42a0d4a0c9c520b0","visual_delta":null,"captured_at":"2026-09-26T09:09:34.473Z"},{"viewport":"desktop","width":1440,"height":900,"r2_key":"stealpage/shots/vercel.com/pg_cxzclerjkj5k/run_qkyu4icrdbn3-desktop.png","phash":"0763634742424060","visual_delta":null,"captured_at":"2026-09-26T09:09:34.275Z"}],"history":[{"id":"run_qkyu4icrdbn3","started_at":"2026-09-26T09:09:28.046Z","http_status":200,"fetcher":"direct","changed":false,"diff":null,"word_count":907}],"citedBy":[{"id":"pg_i-l_8qzl_azq","url":"https://vercel.com/docs/frameworks/full-stack/sveltekit","title":"SvelteKit on Vercel","anchors":["FastAPI"],"zone":"main"},{"id":"pg_sh-yy95u68le","url":"https://vercel.com/docs/frameworks/full-stack/tanstack-start","title":"TanStack Start on Vercel","anchors":["FastAPI"],"zone":"main"},{"id":"pg_a4gkqthxdgur","url":"https://vercel.com/docs/frameworks/full-stack/nuxt","title":"Nuxt on Vercel","anchors":["FastAPI"],"zone":"main"},{"id":"pg_shocgxz1klct","url":"https://vercel.com/templates","title":"Templates - Vercel","anchors":["FastAPI"],"zone":"main"},{"id":"pg_4ljdb7zfqzvh","url":"https://vercel.com/docs/frameworks","title":"Frameworks on Vercel","anchors":["FastAPI"],"zone":"main"},{"id":"pg_maex0vniv8we","url":"https://vercel.com/docs/frameworks/backend","title":"Backends on Vercel","anchors":["FastAPI"],"zone":"main"},{"id":"pg_a7l560pdh1d8","url":"https://vercel.com/docs/frameworks/backend/nitro","title":"Nitro on Vercel","anchors":["FastAPI"],"zone":"main"}]}