This chapter shows how to publish your FastAPI application live using Vercel (serverless Python support). You’ll learn how to connect your GitHub repo, configure Vercel, and deploy your FastAPI project.
- Offers serverless functions for Python / FastAPI. :contentReference[oaicite:0]{index=0}
- Automatically builds on each commit (CI/CD) when linked to GitHub. :contentReference[oaicite:1]{index=1}
- Easy to configure via a
vercel.json. :contentReference[oaicite:2]{index=2}
- A GitHub account
- A Vercel account (free plan is sufficient)
- Your FastAPI application in a GitHub repository
requirements.txtlisting all Python dependenciesvercel.jsonconfiguration file (explained below)
- Ensure your project has a requirements.txt (run
pip freeze > requirements.txt) - Create a
vercel.jsonfile in the root of your project. Example configuration:
{
"builds": [
{
"src": "main.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "main.py"
}
]
}"src": "main.py"refers to your FastAPI entry file.- The
routessection ensures all requests route tomain.py. - You may need to adjust paths if your file structure is different. ([DEV Community][1])
- (Optional) Specify Python version via
pyproject.tomlorPipfile. ([Vercel][2])
-
Initialize git (if not already):
git init git add . git commit -m "Initial FastAPI commit"
-
Create a GitHub repository and push:
git remote add origin https://github.com/yourusername/yourrepo.git git push -u origin main
-
Ensure your repository is public or that Vercel has access if private. Vercel supports deployment from GitHub directly. ([Stack Overflow][3])
-
Go to vercel.com → Log in
-
On Vercel dashboard → New Project → Import Git Repository
-
Authorize Vercel to access your GitHub account
-
Select your FastAPI repo
-
Vercel should detect it's a Python project.
-
In Project Settings → Environment Variables → add any secrets (e.g.
MONGO_URI, tokens). -
Click Deploy
-
Wait for deployment to finish — your FastAPI API is live!
- Use
https://your-project.vercel.appas base URL - Your API endpoints (e.g.
/docs) should work
- Use
If you prefer local control:
npm install -g vercel
vercel login
vercel link # link your local folder to Vercel project
vercel --prod # deploy to productionThis allows you to deploy without pushing to Git every time. ([Vercel][4])
| Issue | Solution |
|---|---|
404 on your API endpoints |
Check your vercel.json routing config. ([Vercel Community][5]) |
| “Unable to find any supported Python versions” | Ensure your requirements.txt exists and the vercel.json build config is correct. ([Stack Overflow][6]) |
| Private repo not listed | Grant Vercel access in GitHub settings or make the repo public. ([Stack Overflow][3]) |
- requirements.txt present
- vercel.json configured
- GitHub repo pushed
- Vercel project created & linked
- Environment variables set
- Deployed and tested endpoints
Once done, your FastAPI app is live and accessible globally via Vercel’s infrastructure. Congratulations — you’ve deployed your API!