Some links in this article are affiliate links. We earn a commission at no extra cost to you when you purchase through them. Full disclosure.
You’ve built an AI chatbot locally. It works great on localhost. Now what? You need it live on the internet with a real URL — and you don’t want to deal with Docker, nginx, SSL certificates, or a $20/month VPS just to demo something.
Railway solves this. Push your code, get a URL. That’s it. In this tutorial, we’ll deploy a Python FastAPI chatbot that calls the DeepSeek API, and we’ll do it entirely on Railway’s free tier.
Why Railway for AI Apps?
Railway is a platform-as-a-service that actually understands modern dev workflows:
- GitHub integration — push to deploy, automatic builds
- Free $5/month credit — enough for a low-traffic chatbot
- Zero config — detects Python, installs deps, runs your app
- Built-in environment variables — no
.envfiles on servers - Instant public URLs — HTTPS included
For a deeper comparison with other platforms, check our best hosting for AI side projects guide.
Getting Started
You’ll need a Railway account to follow along. The free tier gives you $5 in monthly credits — no credit card needed:
$5 covers roughly 500 hours of a small service (more than enough for a side project or demo).
Step 1: Build the Chatbot Locally
Create a new project folder:
mkdir ai-chatbot && cd ai-chatbot
Create main.py:
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
import httpx
import os
app = FastAPI()
DEEPSEEK_API_KEY = os.environ.get("DEEPSEEK_API_KEY")
DEEPSEEK_URL = "https://api.deepseek.com/chat/completions"
@app.get("/")
async def root():
return {"status": "online", "service": "ai-chatbot"}
@app.post("/chat")
async def chat(request: Request):
body = await request.json()
user_message = body.get("message", "")
async with httpx.AsyncClient() as client:
response = await client.post(
DEEPSEEK_URL,
headers={
"Authorization": f"Bearer {DEEPSEEK_API_KEY}",
"Content-Type": "application/json",
},
json={
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": user_message},
],
},
timeout=30.0,
)
data = response.json()
reply = data["choices"][0]["message"]["content"]
return JSONResponse({"reply": reply})
@app.get("/health")
async def health():
return {"status": "healthy"}
Create requirements.txt:
fastapi==0.115.0
uvicorn==0.30.0
httpx==0.27.0
Create Procfile:
web: uvicorn main:app --host 0.0.0.0 --port $PORT
Test locally:
pip install -r requirements.txt
DEEPSEEK_API_KEY=your_key uvicorn main:app --reload
Hit http://localhost:8000/chat with a POST request to verify it works.
Step 2: Push to GitHub
Initialize a repo and push:
git init
git add .
git commit -m "Initial chatbot"
gh repo create ai-chatbot --public --push
(Or create the repo manually on GitHub and push.)
Step 3: Deploy on Railway
- Log into Railway
- Click New Project → Deploy from GitHub Repo
- Select your
ai-chatbotrepository - Railway auto-detects Python and starts building
The first deploy takes about 30 seconds. You’ll see build logs in real-time.
Step 4: Set Environment Variables
Your chatbot needs the DeepSeek API key. In Railway:
- Click on your service
- Go to Variables tab
- Add:
DEEPSEEK_API_KEY= your actual key
Railway automatically redeploys when you add or change variables.
Step 5: Get Your Public URL
- Go to Settings → Networking
- Click Generate Domain
- Railway gives you a URL like
ai-chatbot-production-abc123.up.railway.app
That’s it. Your chatbot is live. HTTPS included.
Step 6: Test the Live Endpoint
curl -X POST https://your-app.up.railway.app/chat \
-H "Content-Type: application/json" \
-d '{"message": "What is the meaning of life?"}'
You should get a JSON response with the AI’s reply in 1-2 seconds.
Step 7: Set Up Auto-Deploy
By default, Railway deploys on every push to your main branch. Push a code change:
# Edit main.py, then:
git add . && git commit -m "Update system prompt" && git push
Railway rebuilds and redeploys automatically. Zero-downtime deployments included.
Cost Breakdown
Railway’s free tier gives you $5/month. Here’s what that covers:
| Resource | Free Allowance | Chatbot Usage |
|---|---|---|
| RAM | 512MB included | ~100MB for FastAPI |
| CPU | Shared | Minimal (API proxying) |
| Execution hours | ~500 hrs | Enough for low traffic |
| Bandwidth | 100GB | More than enough |
The DeepSeek API itself costs about $0.14 per million input tokens — extremely cheap. Your Railway bill will be $0 for a demo/side project.
For a full breakdown of Railway pricing and features, read our Railway review for AI apps.
Going Further
Once your basic chatbot is deployed, you can:
- Add conversation history (store in Railway’s built-in Postgres or Redis)
- Build a frontend and deploy it as a separate Railway service
- Add rate limiting to protect your API key
- Set up a custom domain
If you’re designing something more complex, check out our system design guide for AI chatbots.
For more deployment patterns and options, see our deploy AI apps on Railway deep dive.
FAQ
Is Railway actually free?
Yes, you get $5/month in credits without a credit card. A low-traffic chatbot (few hundred requests/day) stays well within this. If you exceed it, you just add a payment method — no surprise bills.
Why DeepSeek instead of OpenAI?
DeepSeek is 10-50x cheaper than GPT-4 for similar quality. For a chatbot tutorial, it keeps your API costs near zero. You can swap in any OpenAI-compatible API by changing the URL and model name.
Can I deploy a chatbot with a frontend?
Absolutely. Add a React/Next.js frontend as a separate service in the same Railway project. Railway handles routing between services. Or serve static HTML directly from FastAPI.
What happens if my app crashes?
Railway automatically restarts crashed services. You can also set up health checks — Railway pings your /health endpoint and restarts if it fails. Check your deploy logs for error details.