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 can deploy from your code and provide a public URL. In this tutorial, we’ll deploy a Python FastAPI chatbot that calls the DeepSeek API. Railway’s time-limited trial can help evaluate hosting, but external API usage is billed separately and an unverified limited trial can restrict outbound network access.
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
- One-time $5 trial grant with 30-day expiry; not a recurring monthly allowance
- 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 official trial documentation, checked October 8, 2026, describes a one-time $5 grant expiring in 30 days. Full network access depends on account verification; confirm outbound API access before following this tutorial:
The available runtime depends on actual compute, memory and other resource usage. We have not measured how long this chatbot lasts on the trial grant.
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 trial grant is $5 once, not $5 each month. The official trial documentation lists these constraints:
| Constraint | Trial reference |
|---|---|
| Credit | $5 one-time grant, expires in 30 days |
| Memory | Up to 1 GB |
| CPU | Shared cores |
| Services | Up to 5 per project |
| Outbound network | Restricted on Limited Trial; Full Trial requires verification |
Model-provider API charges are separate from hosting. Check the selected model’s current token rates and Railway’s usage meter; neither a zero bill nor a fixed number of runtime hours is guaranteed here.
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?
Railway offers a one-time $5 trial grant that expires after 30 days. Runtime depends on resources consumed, and a limited trial can restrict outbound access to the model API. Check current account eligibility, network access and paid-plan billing before deploying; we have not independently measured this chatbot’s bill.
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.