Deploy to Railway
🚂 Deploy to Railway
Deploy your ElizaOS agent to Railway with one-click deployment for 24/7 operation.
Prerequisites
- GitHub account
- Railway account (free to start)
- ElizaOS agent working locally
- API keys ready (OpenAI/Anthropic/etc.)
Step 1: Prepare Your Agent
Create a GitHub Repository
- Create a new repository on GitHub
- Push your agent code:
cd your-agent-folder
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.git
git push -u origin main
Add Required Files
Ensure your repository has:
package.json
with start script:
{
"name": "my-elizaos-agent",
"version": "1.0.0",
"scripts": {
"start": "elizaos start"
},
"dependencies": {
"@elizaos/cli": "latest"
}
}
Procfile
(optional, for custom commands):
elizaos start --character characters/my-agent.json
Step 2: Deploy to Railway
Quick Deploy
- Go to railway.app
- Click "Start a New Project"
- Select "Deploy from GitHub repo"
- Connect your GitHub account
- Select your agent repository
- Railway will automatically detect and start deployment
Configure Environment Variables
- In Railway dashboard, click on your project
- Go to "Variables" tab
- Add your environment variables:
# Required - AI Provider (choose one)
OPENAI_API_KEY=sk-your-openai-key
# OR
ANTHROPIC_API_KEY=your-anthropic-key
# Optional - Platform Integrations
DISCORD_APPLICATION_ID=your-discord-app-id
DISCORD_API_TOKEN=your-discord-bot-token
TELEGRAM_BOT_TOKEN=your-telegram-token
TWITTER_API_KEY=your-twitter-api-key
TWITTER_API_SECRET=your-twitter-secret
TWITTER_ACCESS_TOKEN=your-access-token
TWITTER_ACCESS_SECRET=your-access-secret
# Database (Railway provides this automatically)
DATABASE_URL=${{Postgres.DATABASE_URL}}
Step 3: Database Setup
Option 1: Railway PostgreSQL (Recommended)
- In your Railway project, click "New"
- Select "Database" → "Add PostgreSQL"
- Railway automatically sets
DATABASE_URL
- Your agent will use this for persistence
Option 2: Use PGLite (Default)
If you don't add a database, ElizaOS uses PGLite (local file storage).
Note: PGLite data may be lost on redeploy. Use PostgreSQL for persistence.
Step 4: Domain & Networking
Custom Domain (Optional)
- Go to Settings → Domains
- Add your custom domain
- Update DNS records as instructed
Public URL
Railway provides a free subdomain:
- Format:
your-app.up.railway.app
- HTTPS enabled by default
- Use this URL for webhooks and APIs
Step 5: Monitoring & Management
View Logs
- Click on your deployment
- Select "View Logs"
- Monitor for errors or issues
Restart Your Agent
- Go to Deployments tab
- Click "Restart" on current deployment
- Or trigger new deploy by pushing to GitHub
Resource Usage
Monitor in Railway dashboard:
- Memory usage
- CPU usage
- Request count
- Estimated monthly cost
Configuration Tips
Character File Location
Ensure your character file path is correct:
{
"scripts": {
"start": "elizaos start --character characters/agent.json"
}
}
Port Configuration
Railway automatically sets PORT
environment variable. ElizaOS handles this automatically.
Health Checks
Add health endpoint for monitoring:
// In your agent configuration
{
"settings": {
"healthCheckPath": "/health"
}
}
Cost Management
Railway Pricing
- Starter: $5/month credit (usually enough for one agent)
- Pay as you go: ~$5-20/month typical usage
- Free tier: Limited hours available
Cost Optimization
- Use webhooks instead of polling when possible
- Set reasonable intervals for scheduled tasks
- Monitor API usage to control costs
- Use caching for repeated operations
Troubleshooting
Agent Won't Start
Check logs for errors:
"Cannot find module" → Missing dependency
"API key not found" → Check environment variables
"Port already in use" → Railway handles this automatically
Solutions:
- Verify all dependencies in package.json
- Double-check environment variables
- Ensure character file path is correct
Database Connection Issues
If using PostgreSQL:
- Verify
DATABASE_URL
is set - Check if database service is running
- Try restarting both services
Memory Issues
If agent crashes with memory errors:
- Check for memory leaks in plugins
- Reduce conversation history limit
- Upgrade to higher Railway plan
Deployment Fails
Common fixes:
- Ensure
package.json
has start script - Check for syntax errors in character file
- Verify all required files are committed
- Check build logs for specific errors
Advanced Configuration
Multi-Agent Deployment
Deploy multiple agents in one project:
{
"scripts": {
"start": "elizaos start --character characters/agent1.json & elizaos start --character characters/agent2.json --port 3001"
}
}
Scheduled Tasks
Use Railway cron jobs for scheduled tasks:
- Go to Settings → Cron
- Add cron expression
- Set command to run
Environment-Specific Configs
Use Railway environments for staging/production:
const config = {
production: {
logLevel: 'info',
},
staging: {
logLevel: 'debug',
},
};
Backup Strategy
- Use PostgreSQL for data persistence
- Set up regular database backups
- Export conversation logs periodically
Security Best Practices
Environment Variables
- Never commit secrets to GitHub
- Use Railway's variable management
- Rotate API keys regularly
- Use read-only tokens where possible
Network Security
- Railway provides HTTPS by default
- Use environment-specific URLs
- Implement rate limiting
- Add authentication for admin endpoints
Access Control
- Limit GitHub repo access
- Use Railway team features
- Enable 2FA on all accounts
- Monitor access logs
Next Steps
After Deployment
- Test your live agent at your Railway URL
- Monitor logs for the first 24 hours
- Set up alerts for errors or downtime
- Join community for deployment tips
Scaling Up
When ready to scale:
- Add more dynos for higher traffic
- Implement caching layers
- Use CDN for static assets
- Consider microservices architecture
Support Resources
- Railway Documentation: docs.railway.app
- Railway Community: discord.gg/railway
- ElizaOS Discord: discord.gg/elizaos
- Status Page: status.railway.app
🚀 Pro Tip: Start with minimal configuration and add features gradually. Monitor costs and performance before scaling up.
⚡ Quick Deploy: Fork our example repository for fastest setup!