Your FastAPI app running live on the internet: deployed to Railway or Render (both free tiers), accessible via a public URL, with environment variables set securely and basic health monitoring.
Deployment Options Compared
You have multiple options for deploying a FastAPI app. Here are the three most common for small AI projects:
Railway (recommended for this lesson)
+ Free tier: $5/month credit
+ Deploy from GitHub in 3 minutes
+ Auto-deploys on git push
+ Built-in PostgreSQL add-on
+ Simple environment variable management
Render
+ Free tier: spins down after 15 min idle
+ Simple setup, good free tier
+ Good for demos, not always-on apps
AWS / GCP / Azure
+ Full control, scales to any size
+ More setup required
+ Better for production workloads
+ Start here after outgrowing RailwayPrepare for Production
Before deploying, make your app production-ready with three changes:
1. requirements.txt
$ pip freeze > requirements.txt2. Update main.py for production host
import uvicorn
import os
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8000))
uvicorn.run(
"main:app",
host="0.0.0.0",
port=port
)3. Never commit secrets. Create a .env file locally for development, add it to .gitignore, and set production secrets as environment variables in Railway's dashboard — never in code.
Deploy to Railway
With your app committed to a GitHub repository:
Go to railway.app, sign in with GitHub.
Click New Project → Deploy from GitHub repo. Select your API repository.
Railway detects Python and runs pip install -r requirements.txt automatically. Set your start command: python main.py
Go to Variables and add your ANTHROPIC_API_KEY and any other environment variables.
Click Generate Domain to get a public URL. Your API is live.
Auto-deploy: Every time you push to your main branch, Railway automatically redeploys. This is the professional workflow: push code → tests run → deploy. No manual steps.
What You Learned Today
- The three deployment options for FastAPI apps and when to use each
- How to prepare an app for production: requirements.txt, port from environment, secrets management
- The Railway deploy process: GitHub integration, environment variables, domain generation
- Why .env files never go to GitHub — and how environment variables in hosting platforms replace them
Go Further on Your Own
- Add a /health endpoint that returns not just status but also the current timestamp and API version — useful for monitoring systems
- Set up a simple uptime monitor: use a free service like UptimeRobot or Better Uptime to ping your /health endpoint every 5 minutes and alert you if it goes down
- Deploy a second version of your app to Render (also free) and compare the deployment experience — what's better and worse about each platform?
Course Complete!
You finished all 5 days. Ready to go deeper?
Reserve Your Bootcamp SeatWant live instruction and hands-on projects? Join the AI bootcamp — 3 days, 5 cities.