Courses Curriculum Cities Blog Enroll Now
API Development for AI · Day 5 of 5 ~45 minutes

Day 5: Deploy Your API to Production

A local API is a prototype. A deployed API is a product. Deploy your FastAPI app to the cloud with a real domain, environment variables, and monitoring.

1
Day 1
2
Day 2
3
Day 3
4
Day 4
5
Day 5
What You'll Build

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.

1
Section 1 · 10 min

Deployment Options Compared

You have multiple options for deploying a FastAPI app. Here are the three most common for small AI projects:

textDeployment Options
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 Railway
2
Section 2 · 15 min

Prepare for Production

Before deploying, make your app production-ready with three changes:

1. requirements.txt

bash
$ pip freeze > requirements.txt

2. Update main.py for production host

pythonmain.py
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.

3
Section 3 · 20 min

Deploy to Railway

With your app committed to a GitHub repository:

1

Go to railway.app, sign in with GitHub.

2

Click New Project → Deploy from GitHub repo. Select your API repository.

3

Railway detects Python and runs pip install -r requirements.txt automatically. Set your start command: python main.py

4

Go to Variables and add your ANTHROPIC_API_KEY and any other environment variables.

5

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
Your Challenge

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?
Day 5 Complete

Course Complete!

You finished all 5 days. Ready to go deeper?

Reserve Your Bootcamp Seat
Course Progress
100%

Want live instruction and hands-on projects? Join the AI bootcamp — 3 days, 5 cities.

Finished this lesson?