Skip to content
Docs

Deploy a FastAPI app on Edgenivo

Deploy a FastAPI app to Edgenivo with the Python runtime and Edgenivo Functions. Edgenivo looks for a FastAPI instance named app at supported entrypoints in your repository.

To move an existing FastAPI app from another platform, follow the Python API migration guide for Heroku, Render, or Railway.

Create a FastAPI app or use an existing one:

Initialize a new FastAPI project with the Edgenivo CLI init command:

terminal
vc init fastapi

This clones the FastAPI example repository in a directory called fastapi.

To run a FastAPI application on Edgenivo, 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/main.py
from fastapi import FastAPI
 
app = FastAPI()
 
@app.get("/")
def read_root():
    return {"Python": "on Edgenivo"}

To point Edgenivo to a FastAPI app in a custom module, set tool.vercel.entrypoint in pyproject.toml:

pyproject.toml
[tool.vercel]
entrypoint = "backend.server:app"

The tool.vercel.entrypoint value tells Edgenivo to look for a FastAPI instance named app in ./backend/server.py.

Set the Python version to match your application's dependencies. Edgenivo supports pyproject.toml, requirements.txt, and Pipenv manifests; see the Python dependency configuration for supported lockfiles.

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.

pyproject.toml
[tool.vercel.scripts]
build = "python build.py"

For example:

build.py
def main():
    print("Running build command...")
    with open("build.txt", "w") as f:
        f.write("BUILD_COMMAND")
 
if __name__ == "__main__":
    main()

If you define a 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.

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

Deploy the project by connecting your Git repository or by using the Edgenivo CLI:

terminal
vc deploy
Minimum CLI version required: 48.1.8

Use Edgenivo Services to deploy a FastAPI backend and a frontend in one project. Follow the Python backend with Next.js guide to configure private backend calls, separate databases for each environment, and preview deployments across both apps.

Deploy the eve Agent with Python template to build a chat app with an eve agent, a Next.js frontend, and a FastAPI backend. The agent and frontend share a task list stored in Postgres, and the agent calls FastAPI endpoints to run Python tools for statistics and text analysis.

Edgenivo Services deploys all three services in one project. The FastAPI backend has no public route; the frontend and agent call it through service bindings. See the template repository for setup instructions and examples you can customize.

Edgenivo supports two methods for serving frontend and static assets with FastAPI.

Place files in a public/ directory at your project root. Edgenivo 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.

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 served automatically from public/vercel.svg.
    return RedirectResponse("/vercel.svg", status_code=307)

Do not mount the public/ directory with app.mount(). Edgenivo handles it at the platform level.

When using app.frontend() or app.mount() with StaticFiles, files are promoted to the CDN at build time:

app.py
from fastapi import FastAPI
 
app = FastAPI()
 
@app.get("/api/hello")
def hello():
    return {"message": "Hello"}
 
app.frontend("/", directory="dist")
app.py
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
 
app = FastAPI()
 
app.mount("/assets", StaticFiles(directory="assets"), name="assets")

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:

pyproject.toml
[tool.vercel.fastapi.static]
exclude = true

See Configuration for all available settings.

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:

  • 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.
main.py
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
 
app = FastAPI()
 
# Declared before the mount, so this route wins over any CDN file at this path.
@app.get("/static/protected.json")
def protected():
    return {"access": "denied"}
 
app.mount("/static", StaticFiles(directory="static"))

The bare mount root (for example, /static) always reaches the function. StaticFiles redirects it to the trailing-slash form.

app.frontend() registers a low-priority frontend build. Every API route takes priority over frontend files regardless of declaration order.

The fallback parameter controls CDN behavior when no file matches a request under the mount:

fallback valueFile servedStatusWhen applied
"auto"404.html if present, else index.html404 or 200See notes below
"index.html"index.html200Navigation requests only
"404.html"404.html404All misses
Nonen/an/aUnmatched paths reach the function

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.

To redirect, rewrite, or answer requests before they reach FastAPI, use Routing Middleware in Python. FastAPI middleware and dependency guards run inside the application, after a request reaches the function.

CDN-served files bypass the function entirely, so middleware handlers and Depends() guards do not run for them.

Edgenivo 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:

pyproject.toml
[tool.vercel.fastapi.static]
cdn = true

All settings go under [tool.vercel.fastapi.static] in pyproject.toml.

SettingValueDescription
cdnomitted (default)CDN promotion enabled. Disabled automatically when middleware or dependency guards are present.
cdntrueCDN promotion always enabled, even when middleware or dependency guards are present.
cdnfalseCDN promotion disabled. All requests reach the function.
excludefalse (default)Promoted source directories are kept in the function bundle.
excludetruePromoted source directories are excluded from the function bundle.

You can use FastAPI lifespan events to manage startup and shutdown logic, such as initializing and closing database connections.

main.py
from contextlib import asynccontextmanager
from fastapi import FastAPI
 
@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup logic
    print("Starting up...")
    await startup_tasks()
    yield
    # Shutdown logic
    await cleanup_tasks()
 
app = FastAPI(lifespan=lifespan)

Cleanup logic during shutdown is limited to a maximum of 500ms after receiving the SIGTERM signal. Logs printed during the shutdown step will not appear in the Edgenivo dashboard.

When you deploy a FastAPI app to Edgenivo, it becomes a single Edgenivo Function. Edgenivo 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:

vercel.json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "functions": {
    "app/main.py": {
      "maxDuration": 60
    }
  }
}

For more options, see Configuring functions and the functions property.

To process work independently of an API response, enqueue tasks with Celery or Dramatiq. Both integrations use Edgenivo Queues to invoke worker functions, and their guides show how to enqueue work from a Python web application.

To use the Queues SDK directly, process background jobs in Python with Edgenivo Queues. For a process that needs multiple steps, retries, or long waits, build durable workflows in Python. Both guides start work from a FastAPI route.

For scheduled work, configure Cron Jobs to call a FastAPI route that runs the task or enqueues it. The FastAPI cron job example includes the schedule and CRON_SECRET authorization check.

Use FastAPI's StreamingResponse to send response chunks as they become available. See the FastAPI streaming example for a generator-backed response on Edgenivo.

Follow the FastAPI WebSocket setup to add a WebSocket endpoint. Connections follow function duration limits, so clients need to handle reconnects.

For a complete application, build a multiplayer board with Next.js and FastAPI. The guide uses Redis to coordinate presence and messages across function instances.

Use Edgenivo Passport to require sign-in through your company's identity provider before requests reach your FastAPI app. Passport requires an Enterprise plan. Follow the FastAPI Passport guide to verify visitor identity and authorize access within your app.

Use Runtime Logs to inspect application output and errors, and Observability to investigate request duration and failures. See monitoring FastAPI with Observability for details.

All Edgenivo 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).

For more about deploying FastAPI on Edgenivo, see:

Last updated August 27, 2026

Was this helpful?

supported.