FastAPI is a high-performance Python web framework for building APIs. It uses standard Python type hints to give you request validation, serialization, and automatic interactive API docs, and it runs on the ASGI standard, so your endpoints can handle requests asynchronously.
On Edgenivo, you can deploy a FastAPI app with zero configuration: your app becomes a Edgenivo Function running on Fluid compute, and you get response streaming, preview deployments, and observability without extra setup.
This guide walks you through deploying a FastAPI app to Edgenivo from a template, the Edgenivo CLI, or a Git repository, then configuring features such as streaming, middleware, cron jobs, the Python version, and observability.
Copy link to headingPrerequisites
Before you begin, make sure you have:
- A Edgenivo account
- Python 3.12 or later and a package manager (e.g.,
piporuv) - An existing FastAPI project, or a new one created from a FastAPI template
- A Git repository on GitHub, GitLab, or Bitbucket (if you want Git-based deployments)
- Edgenivo CLI installed (
npm i -g vercel)
Copy link to headingHow it works
When you deploy a FastAPI app, Edgenivo detects the framework from your dependencies and builds it for the Python runtime. Edgenivo looks for a FastAPI instance named app at a supported entrypoint and serves your whole app as a single Edgenivo Function, which runs on Fluid compute by default. Your app scales with traffic, and you pay only for the compute your function uses, not for idle time.
Because Edgenivo ships zero-configuration detection for FastAPI, you don't set a build command or output directory. Edgenivo reads your project, finds the file that exports your FastAPI app, and applies the correct build settings.
Copy link to headingDeploy your FastAPI app
You can ship a FastAPI app to Edgenivo in three ways. Choose the one that fits where your code lives today.
Copy link to headingOption 1: Deploy from a template
The fastest way to ship a FastAPI app is to start from a template. Pick a starter, then deploy it. Edgenivo clones the template to your Git provider, creates a project, and deploys it with zero configuration.
Templates to start from include:
- FastAPI Boilerplate: A minimal FastAPI app that runs on the Python runtime and deploys with zero configuration. Start here if you're new to FastAPI on Edgenivo.
- AI SDK Python Streaming: Streams chat completions from a FastAPI function and renders them with the AI SDK
useChathook in a Next.js frontend. - Next.js FastAPI Starter: An AI chatbot with a Next.js frontend and a FastAPI backend.
- OpenAI Agents SDK with FastAPI: A FastAPI app that runs the OpenAI Agents SDK with Edgenivo Sandbox, spinning up an isolated microVM per request to give the agent shell access.
- Full-stack FastAPI template with Next.js: A full-stack starter that pairs a FastAPI backend with a Next.js frontend, with cookie-based auth and a Postgres database.
Copy link to headingOption 2: Start a new project with the Edgenivo CLI
To scaffold a new FastAPI project locally, use the Edgenivo CLI init command. It clones Edgenivo's FastAPI example into a folder named fastapi.
- Create the project:
- Set up a virtual environment and install dependencies:
- Develop locally at
http://localhost:3000. Use the Edgenivo CLI, so your app runs with the sameappinstance it uses in production: - Create the initial production deployment. The first run creates a Edgenivo project link:
Copy link to headingOption 3: Deploy an existing FastAPI app
If you already have a FastAPI app, deploy it from Git or from the command line.
- From Git: Push your project to GitHub, GitLab, or Bitbucket, then import it at edgenivo.com/new. Edgenivo detects FastAPI automatically and deploys it with zero configuration.
- From the CLI: From your project's root directory, run
vercel. For a new project, this creates the project link and its initial production deployment. Latervercelcommands create preview deployments, andvercel --prodcreates production deployments.
To pull project settings and environment variables for local development, run:
For Edgenivo to detect your app, export a FastAPI instance named app from one of the recognized entry files, such as app.py, index.py, server.py, main.py, wsgi.py, or asgi.py at your project root or under src/, app/, or api/:
To point Edgenivo to a FastAPI app in a custom module, set tool.vercel.entrypoint in pyproject.toml:
This tells Edgenivo to load the app variable from ./backend/server.py.
Copy link to headingUse Edgenivo features with FastAPI
After your app is deployed, you can layer Edgenivo features onto it. Some work automatically, and others take a few lines of configuration in vercel.json.
Copy link to headingYour app runs as a single Edgenivo Function
Edgenivo serves your FastAPI app as a single Edgenivo Function. This function uses Fluid compute by default, which runs multiple requests concurrently within a single instance to reduce cold starts and the cost of I/O-bound work such as API calls and database queries. You don't configure anything to get this behavior.
Because FastAPI exports a single app, Edgenivo sends every incoming request to that app and lets FastAPI's router match the path. Your route handlers, dependencies, middleware, and error handling all run inside the function.
Copy link to headingStream responses
Edgenivo Functions on the Python runtime support streaming, so you can send data to the client as you produce it instead of waiting for the full response. Use FastAPI's StreamingResponse to stream text, server-sent events, or AI model output:
Streaming pairs well with Fluid compute: while your function waits between chunks, the same instance can serve other requests. To stream model output to a frontend, pair your FastAPI endpoint with AI SDK, as the AI SDK Python Streaming template shows.
Copy link to headingCombine FastAPI middleware with Edgenivo Routing Middleware
FastAPI and Edgenivo each have a middleware layer, and they solve different problems. FastAPI middleware runs inside your function, after the request reaches it. Use it for app-level concerns such as logging, CORS, and authentication:
Edgenivo Routing Middleware runs at the edge, before the request reaches your FastAPI app, and works with any framework. Use it for rewrites, redirects, and header changes that should happen before any function runs. Add a middleware.ts file at your project root:
The two layers work together, with Routing Middleware shaping the request at the edge and FastAPI middleware handling it inside your app.
Copy link to headingServe static assets from the CDN
To serve static files such as images, fonts, or a favicon, place them in the public/** directory. Edgenivo serves them through its CDN using default headers, which you can override in vercel.json. FastAPI's own app.mount("/public", ...) is not needed on Edgenivo, so rely on the public directory instead.
You can still define routes that point at those files. For example, redirect /favicon.ico to an asset in public:
Copy link to headingRun scheduled tasks with cron jobs
Edgenivo Cron Jobs trigger a route on a schedule by sending an HTTP GET request to it. Define a route in your FastAPI app for the task, then register the schedule in vercel.json.
Define the route:
Register the schedule:
Edgenivo runs cron jobs only on production deployments. To stop anyone else from calling the route, set a CRON_SECRET environment variable in your project settings. Edgenivo sends it as a Bearer token in the Authorization header on every cron invocation, and your handler compares it before running the task.
Copy link to headingSet the Python version
FastAPI runs on Edgenivo's Python runtime, which defaults to Python 3.12. The available versions are 3.12 (default), 3.13, and 3.14. To pin a version, add a .python-version file at your project root:
You can also set the version in pyproject.toml or Pipfile.lock. If you don't define a supported version, Edgenivo uses the default.
Copy link to headingManage startup and shutdown with lifespan events
Use FastAPI lifespan events to run setup and teardown logic, such as opening and closing database connections. Edgenivo runs the startup logic when your function starts and the shutdown logic when it stops:
Cleanup during shutdown is limited to 500 ms after your function receives the SIGTERM signal, and logs printed during shutdown don't appear in the Edgenivo dashboard. Keep teardown work short, and move anything longer to a cron job or Edgenivo Workflow.
Copy link to headingMonitor performance with Observability
Edgenivo Observability tracks your deployed function automatically, with no setup. Open the Observability page in your project to see invocation counts, error rates, and duration for your FastAPI app, along with the requests your function makes to external APIs. On Observability Plus, you also get longer retention and a latency breakdown by path.
Copy link to headingBest practices
Copy link to headingDefine your app at a recognized entrypoint
Edgenivo finds your FastAPI app by looking for an app instance at a fixed set of locations: app, index, server, main, wsgi, or asgi (with a .py extension) at your project root or under src/, app/, or api/. Put your app at one of these paths so Edgenivo detects and deploys it correctly, or set tool.vercel.entrypoint in pyproject.toml to point at a custom module:
Copy link to headingDevelop with the Edgenivo CLI
Run vercel dev for local development instead of running Uvicorn directly. It serves your app the same way production does, using your app instance, so the behavior you test locally matches what you deploy. This also lets you exercise features such as cron routes before shipping.
Copy link to headingKeep your function bundle small
Python functions are not tree-shaken, so Edgenivo bundles every file reachable at build time, up to a 500 MB limit. List only the packages you need at runtime in pyproject.toml or requirements.txt, and exclude tests, fixtures, and other development files with excludeFiles in vercel.json:
The pattern is a glob relative to your project root, so adjust it to match where your Python files live.
Copy link to headingResources and next steps
- Read the full FastAPI on Edgenivo documentation
- Browse backend templates you can deploy in one step
- Learn how the Python runtime runs your code
- Learn how Edgenivo Functions run your server code
- Understand pricing and scaling with Fluid compute
- Run code before requests with Routing Middleware
- Defer background work from your routes with Edgenivo Queues, or orchestrate multi-step tasks with Edgenivo Workflows