Deployment
Railway, env vars, Docker basics — your AI API live on the internet in one session.
A senior developer once said: "A model that isn't deployed doesn't exist." You can have the world's best AI — if it's sitting on your laptop, it helps nobody.
Deployment used to need a DevOps team. Railway changed that: connect your GitHub repo, set env vars, deploy in 3 minutes. Used by thousands of startups in India.
📈 The Deployment Checklist (5–25 min)
Your GROQ_API_KEY must NEVER go into Git. Use .env locally + Railway's env vars panel in production. Add .env to .gitignore before your first commit.
💻 Live Demo — Deploy FastAPI to Railway (25–45 min)
># File structure for deployment ai-sentiment-api/ ├── main.py # FastAPI app ├── requirements.txt # pip freeze > requirements.txt ├── Procfile # tells Railway how to start ├── .env # local secrets (NEVER commit) └── .gitignore # must contain .env
># Procfile — one line, no file extension
web: uvicorn main:app --host 0.0.0.0 --port $PORT
># requirements.txt
fastapi==0.111.0
uvicorn==0.30.1
scikit-learn==1.5.0
groq==0.9.0
langchain==0.2.5
langchain-groq==0.1.6
># .gitignore
.env
__pycache__/
*.pyc
*.pkl
venv/
.DS_Store
># Step-by-step Railway deploy # 1. Push to GitHub git init git add . git commit -m "feat: add sentiment API" git remote add origin https://github.com/yourname/ai-sentiment-api.git git push -u origin main # 2. Go to railway.app → New Project → Deploy from GitHub # 3. Set environment variables in Railway dashboard: # GROQ_API_KEY = your_key_here # 4. Railway auto-detects Procfile and deploys! # 5. Test your live API curl -X POST https://your-app.railway.app/predict -H "Content-Type: application/json" -d "{"text": "Amazing product, very happy!"}"
A Dockerfile packages your app + Python + dependencies into a container that runs identically anywhere — dev laptop, Railway, AWS, GCP. Railway can auto-detect a Dockerfile if you provide one.
># Dockerfile FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . EXPOSE 8000 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
📋 You Code It (45–55 min)
Add a GET / root endpoint returning {"message": "AI API is running", "version": "1.0"}. Deploy to Railway. Share the live URL with your cohort.
⚡ Day 14 Cheat Sheet
Procfile--host 0.0.0.0 --port $PORTos.getenv("GROQ_API_KEY").gitignore: .envpip freeze > requirements.txtFROM python:3.12-slimdocker build -t app .docker run -p 8000:8000 app