Railway Deployment Guide
Deploy AIProxyGuard on Railway as an LLM security proxy. Railway is popular with startups for its developer-friendly experience.
| Option | Best For |
|---|---|
| 1. Dashboard (Recommended) | Simple setup, visual interface |
| 2. Railway CLI | Automation, CI/CD |
Option 1: Dashboard (Recommended)
Deploy using the Railway web dashboard.
Step 1: Create Project
- Go to railway.app and sign in
- Click New Project
Step 2: Add Docker Image
- Click Add a Service on the Project Canvas
- Select Docker Image
- Enter the image URL:
ghcr.io/ainvirion/aiproxyguard:latest
Docker Hub alternative: Use
ainvirion/aiproxyguard:latest
- Press Enter and click Deploy
Step 3: Configure Port
- Click on your service to open settings
- Go to Settings tab
- Under Networking, click Generate Domain
- Set Port:
8080
Step 4: Environment Variables (Optional)
- Go to Variables tab
- Click New Variable and add:
| Name | Value |
|---|---|
PORT |
8080 |
AIPROXYGUARD_LOG_LEVEL |
info |
Want fleet management? Add the control plane environment variables to get automatic signature updates, analytics, and fleet management. See Connect to Control Plane for details.
Step 5: Deploy
Railway automatically deploys when you add variables. Wait ~1-2 minutes.
Step 6: Get Your URL
Find your URL in Settings → Networking:
https://aiproxyguard-production-xxxx.up.railway.app
Test it:
curl https://aiproxyguard-production-xxxx.up.railway.app/healthz
# {"status": "healthy"}
Option 2: Railway CLI
Best for automation and CI/CD pipelines.
Prerequisites
Install Railway CLI:
# macOS
brew install railway
# npm
npm install -g @railway/cli
# Login
railway login
Step 1: Create Project
railway init
Select Empty Project when prompted.
Step 2: Deploy Image
railway up --image ghcr.io/ainvirion/aiproxyguard:latest
Docker Hub: Use
ainvirion/aiproxyguard:latest
Step 3: Configure Variables
railway variables set PORT=8080
railway variables set AIPROXYGUARD_LOG_LEVEL=info
Step 4: Generate Domain
railway domain
Step 5: Get URL
railway status
Want fleet management? Add environment variables via CLI. See Connect to Control Plane for the configuration.
Test Your Deployment
# Health check
curl https://aiproxyguard-production-xxxx.up.railway.app/healthz
# {"status": "healthy"}
# Test with OpenAI
curl -X POST https://aiproxyguard-production-xxxx.up.railway.app/openai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello!"}]}'
Connect to Control Plane (Recommended)
Register your proxy with aiproxyguard.com to enable:
- Automatic signature updates (new threat patterns)
- Fleet management dashboard
- Telemetry and analytics
Step 1: Get Your API Key
- Sign up at aiproxyguard.com
- Create a new proxy instance in the dashboard
- Copy your API key
Step 2: Add Environment Variables
Via Dashboard:
- Go to your service → Variables tab
- Click New Variable and add:
| Name | Value |
|---|---|
AIPROXYGUARD_CONTROL_PLANE_ENABLED |
true |
AIPROXYGUARD_CONTROL_PLANE_URL |
https://aiproxyguard.com |
AIPROXYGUARD_CONTROL_PLANE_API_KEY |
your-api-key-here |
- Railway automatically redeploys
Via CLI:
railway variables set AIPROXYGUARD_CONTROL_PLANE_ENABLED=true
railway variables set AIPROXYGUARD_CONTROL_PLANE_URL=https://aiproxyguard.com
railway variables set AIPROXYGUARD_CONTROL_PLANE_API_KEY=your-api-key-here
railway redeploy
Step 3: Verify Registration
View logs in Dashboard:
- Go to your service → Deployments
- Click on latest deployment → View Logs
- Look for:
Connected to control plane
Or via CLI:
railway logs
Update Your Apps
Point your applications to use the proxy:
Environment variable:
OPENAI_BASE_URL=https://aiproxyguard-production-xxxx.up.railway.app/openai/v1
In code:
from openai import OpenAI
client = OpenAI(
base_url="https://aiproxyguard-production-xxxx.up.railway.app/openai/v1",
api_key=os.environ["OPENAI_API_KEY"]
)
Advanced Configuration
Health Checks
- Go to service Settings
- Under Deploy, set Health Check Path:
/healthz - Railway checks this endpoint and waits for HTTP 200 before routing traffic
Default timeout is 300 seconds (5 minutes).
Custom Domain
- Go to service Settings → Networking
- Click + Custom Domain
- Enter your domain:
proxy.yourdomain.com - Railway provides a CNAME value
- Add CNAME record in your DNS provider:
proxy.yourdomain.com → xxx.up.railway.app - Wait for DNS propagation and verification
Railway automatically provisions SSL certificates via Let’s Encrypt.
Scaling
Railway scales based on your plan limits:
| Plan | RAM | CPU | Best For |
|---|---|---|---|
| Hobby | 512MB | 0.5 vCPU | Development, small prod |
| Pro | 8GB | 8 vCPU | Production, scaling |
To increase resources beyond defaults, upgrade to Pro plan in Project Settings.
Monitoring
View logs (Dashboard):
- Go to your service → Deployments
- Click on deployment → View Logs
View logs (CLI):
railway logs --follow
Metrics:
- Go to your service → Metrics
- View CPU, Memory, Network usage
Troubleshooting
Deployment Failed
Check build logs:
- Go to service → Deployments
- Click failed deployment → View Logs
Common issues:
- Image pull failed → Verify image URL is correct
- Health check failing → Ensure
/healthzreturns 200 on port 8080
Container Not Starting
- Ensure
PORTenvironment variable is set to8080 - Check container listens on
0.0.0.0:$PORT - Review deployment logs for errors
Health Check Timeout
- Default timeout is 300 seconds
- Increase via
RAILWAY_HEALTHCHECK_TIMEOUT_SECenv var - Ensure your app starts within the timeout
Domain Not Working
- Wait up to 72 hours for DNS propagation
- Verify CNAME record is correct
- Remove any AAAA (IPv6) records that might conflict
Cleanup
Delete the project:
- Go to Project Settings → Danger Zone
- Click Delete Project
Or via CLI:
railway down