Skip to content

r2r railway deployment

This guide shows how to deploy R2R (the knowledge base backend) on Railway alongside your Supen application.

┌─────────────────┐ ┌─────────────────┐
│ Supen (Next.js)│────────>│ R2R Service │
│ Railway │ HTTP │ Railway │
└─────────────────┘ └─────────────────┘
v
┌─────────────────┐
│ PostgreSQL │
│ (Railway DB) │
└─────────────────┘
  1. In Railway dashboard, click ”+ New”“Database”“PostgreSQL”
  2. Name it r2r-postgres
  3. After it’s created, click on it and go to “Settings”
  4. Note down the connection details (you’ll need these)

Option A: Using Railway Template (Easiest)

Section titled “Option A: Using Railway Template (Easiest)”
  1. Go to Railway dashboard
  2. Click ”+ New”“Empty Service”
  3. Click on the new service → “Settings”
  4. Under “Source”, select “Docker Image”
  5. Enter: ragtoriches/r2r:latest
  6. Under “Deploy”, click “Deploy”
  1. Create a new service in Railway
  2. Configure it with these settings:

Environment Variables:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=${{Postgres.POSTGRES_PASSWORD}}
POSTGRES_DBNAME=${{Postgres.PGDATABASE}}
POSTGRES_HOST=${{Postgres.PGHOST}}
POSTGRES_PORT=${{Postgres.PGPORT}}
OPENAI_API_KEY=<your-openai-key>
R2R_PROJECT_NAME=supen

Networking:

  • Railway will automatically expose port 7272
  • Note the Railway-generated URL (e.g., r2r-production.up.railway.app)

In your Supen Railway service, add these environment variables:

R2R_API_URL=https://r2r-production.up.railway.app
R2R_API_KEY= # Optional, leave empty if not using auth

Test the R2R health endpoint:

Terminal window
curl https://r2r-production.up.railway.app/v3/health

You should get:

{
"status": "ok",
"version": "3.x.x"
}

Railway Pricing:

  • PostgreSQL: ~$5-10/month (Hobby plan, shared)
  • R2R Service: ~$5-10/month (depends on usage)
  • Total: ~$10-20/month

Alternative: Use SciPhi Cloud (Hosted R2R)

Instead of deploying R2R yourself, you can use SciPhi’s hosted version:

  1. Sign up at https://app.sciphi.ai (free tier available)
  2. Get your API key
  3. Set in Supen:
R2R_API_URL=https://api.sciphi.ai
R2R_API_KEY=<your-sciphi-api-key>

Cost: $0/month (free tier) → Pay as you grow

For development and small-scale production:

  • ✅ Use SciPhi Cloud (free tier, zero infrastructure)

For larger deployments with privacy requirements:

  • ✅ Deploy R2R on Railway (full control, dedicated instance)

For local development, you can still use Docker:

Terminal window
# Option 1: Docker Compose (if you want local R2R)
docker compose up r2r r2r-postgres
# Option 2: Point to Railway/SciPhi (no local R2R)
# Just set R2R_API_URL in your .env.local
R2R_API_URL=https://r2r-production.up.railway.app
  • Check PostgreSQL is running and reachable
  • Verify POSTGRES_* environment variables are correct
  • Check Railway logs for R2R service
  • Ensure R2R service is running (check Railway dashboard)
  • Verify R2R_API_URL is correct (include https://)
  • Check if R2R health endpoint responds
  • Check R2R service has enough memory (upgrade plan if needed)
  • Consider using SciPhi Cloud which auto-scales