Deploy Krab on Railway for easy cloud deployment with automatic scaling, persistent storage, and built-in monitoring.
- Railway account (https://railway.app)
- GitHub repository
- API keys for your LLM providers
-
Connect GitHub Repository:
- Go to Railway Dashboard
- Click "New Project" → "Deploy from GitHub repo"
- Select your Krab repository
-
Configure Environment Variables:
# Required: LLM Provider GEMINI_API_KEY=your_gemini_api_key OPENAI_API_KEY=your_openai_api_key ANTHROPIC_API_KEY=your_anthropic_api_key # Optional: Messaging Channels TELEGRAM_BOT_TOKEN=your_telegram_bot_token DISCORD_BOT_TOKEN=your_discord_bot_token LINE_CHANNEL_ACCESS_TOKEN=your_line_access_token LINE_CHANNEL_SECRET=your_line_secret # Railway-specific NODE_ENV=production KRAB_RAILWAY=true KRAB_DEFAULT_MODEL=anthropic/claude-sonnet-4-5
-
Deploy:
- Railway will automatically detect and build your app
- Wait for deployment to complete (usually 2-5 minutes)
-
Access Your App:
- Gateway:
https://your-project.railway.app(port 18789) - Control Panel:
https://your-project.railway.app/control - Health Check:
https://your-project.railway.app/health
- Gateway:
# Google Gemini (Free tier available)
GEMINI_API_KEY=your_api_key_here
# OpenAI
OPENAI_API_KEY=your_api_key_here
# Anthropic Claude
ANTHROPIC_API_KEY=your_api_key_here
# DeepSeek (Budget-friendly)
DEEPSEEK_API_KEY=your_api_key_here# Telegram Bot
TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
# Discord Bot
DISCORD_BOT_TOKEN=your_discord_bot_token
# LINE Bot
LINE_CHANNEL_ACCESS_TOKEN=your_line_access_token
LINE_CHANNEL_SECRET=your_line_secret
# WhatsApp (requires QR pairing)
# Note: WhatsApp works best on VPS, not serverless# Model selection
KRAB_DEFAULT_MODEL=anthropic/claude-sonnet-4-5
KRAB_DEFAULT_MODEL_FALLBACK=openai/gpt-4o-mini
# Debug mode (set to 'false' for production)
KRAB_DEBUG=false
# Railway-specific flags
NODE_ENV=production
KRAB_RAILWAY=true- Go to your Railway project settings
- Add custom domain
- Railway will provide SSL certificate automatically
Railway supports PostgreSQL for production data:
-
Add PostgreSQL Plugin:
- In Railway dashboard, click "Add Plugin"
- Select "PostgreSQL"
- Choose plan (Starter is free)
-
Configure Database URL:
DATABASE_URL=${{Postgres.DATABASE_URL}} -
Environment Variables: Railway automatically provides these variables:
Postgres.DATABASE_URLPostgres.DATABASE_PRIVATE_URLPostgres.USERPostgres.PASSWORDPostgres.DATABASEPostgres.HOSTPostgres.PORT
# In Railway dashboard
1. Go to your project
2. Click on the "Deployments" tab
3. Click on the active deployment
4. View real-time logsRailway automatically monitors your app using the /health endpoint defined in railway.json.
- CPU/Memory Usage: Available in Railway dashboard
- Request Count: Built into Railway monitoring
- Response Times: Automatic performance tracking
Railway supports horizontal scaling:
- Go to project settings
- Adjust "Instances" count
- Railway will automatically load balance
Upgrade your plan for more resources:
- Starter: 512MB RAM, 1 CPU
- Hobby: 1GB RAM, 2 CPUs
- Pro: 4GB RAM, 4 CPUs (and more)
Railway provides automatic backups for PostgreSQL databases.
# Connect to database
railway connect
# Create backup
pg_dump $DATABASE_URL > backup.sql# Restore from backup
psql $DATABASE_URL < backup.sql# Check build logs in Railway dashboard
# Common issues:
- Missing environment variables
- Node.js version mismatch
- Dependencies not found# Check application logs
# Common issues:
- Invalid API keys
- Database connection failures
- Port binding issues# Increase Railway plan
# Or optimize your code:
- Reduce concurrent operations
- Use streaming for large responses
- Implement cachingEnable debug logging:
# Set in Railway environment variables
KRAB_DEBUG=trueRestart deployment to apply changes.
Railway offers generous free tier:
- 512MB RAM
- 1GB storage
- 100 hours/month
- PostgreSQL included
-
Use Free LLM Providers:
KRAB_DEFAULT_MODEL=gemini/gemini-2.0-flash
-
Optimize Resource Usage:
- Set appropriate timeouts
- Use caching for repeated requests
- Implement rate limiting
-
Monitor Usage:
- Check Railway dashboard regularly
- Set up alerts for cost thresholds
Edit railway.json for custom builds:
{
"build": {
"builder": "NIXPACKS",
"buildCommand": "npm run build:custom"
}
}{
"environments": {
"production": {
"buildCommand": "npm run build:prod",
"startCommand": "npm run start:prod"
},
"staging": {
"buildCommand": "npm run build:staging",
"startCommand": "npm run start:staging"
}
}
}For connecting to private services:
# Use Railway private networking
DATABASE_URL=${{Postgres.DATABASE_PRIVATE_URL}}- Never commit API keys to GitHub
- Use Railway's environment variable management
- Rotate keys regularly
- Railway provides automatic SSL/TLS
- Use private networking for databases
- Implement rate limiting in your app
- Configure channel access policies
- Use Railway's team features for collaboration
- Enable 2FA on your Railway account
Railway automatically deploys when you push to your main branch.
# Trigger manual deployment
# In Railway dashboard:
1. Go to project
2. Click "Deploy" button# Rollback to previous deployment
# In Railway dashboard:
1. Go to "Deployments" tab
2. Click on previous deployment
3. Click "Promote" or "Rollback"- Create Railway account
- Connect GitHub repository
- Add environment variables
- Deploy application
- Configure custom domain (optional)
- Set up database (optional)
- Test all features
- Monitor logs and metrics
Happy deploying! 🎉