Deploy on Railway
Prerequisites
Section titled “Prerequisites”- A Railway account
- The Railway CLI installed and authenticated (
railway login) - A
tollbooth.config.yamlready (see Getting Started)
Option A — Deploy from Docker image (recommended)
Section titled “Option A — Deploy from Docker image (recommended)”1. Create a project
Section titled “1. Create a project”railway init2. Create a Dockerfile
Section titled “2. Create a Dockerfile”Railway builds from a Dockerfile. Create Dockerfile.railway:
FROM ghcr.io/loa212/x402-tollbooth:latestCOPY tollbooth.config.yaml /app/tollbooth.config.yaml3. Configure the service
Section titled “3. Configure the service”Create railway.toml:
[build] dockerfilePath = "Dockerfile.railway"
[deploy] healthcheckPath = "/health" healthcheckTimeout = 5 restartPolicyType = "ON_FAILURE" restartPolicyMaxRetries = 3Railway auto-detects the listening port via the PORT env var. Tollbooth defaults to port 3000, which Railway will route to automatically.
4. Set environment variables
Section titled “4. Set environment variables”Via the CLI:
railway variables set API_KEY=sk-your-keyOr in the Railway dashboard under your service’s Variables tab.
5. Deploy
Section titled “5. Deploy”railway up6. Expose the service
Section titled “6. Expose the service”Generate a public domain in the Railway dashboard under Settings > Networking > Generate Domain, or via CLI:
railway domainOption B — Deploy from source
Section titled “Option B — Deploy from source”If you’ve cloned the tollbooth repo and want to build from source:
1. Clone and configure
Section titled “1. Clone and configure”git clone https://github.com/Loa212/x402-tollbooth.gitcd x402-tollboothAdd your tollbooth.config.yaml to the project root.
2. Create railway.toml
Section titled “2. Create railway.toml”[build] dockerfilePath = "Dockerfile"
[deploy] healthcheckPath = "/health" healthcheckTimeout = 5 restartPolicyType = "ON_FAILURE" restartPolicyMaxRetries = 3The repo’s existing Dockerfile builds tollbooth from source. You’ll need to ensure your config file is copied in. Add this line at the end of the Dockerfile:
COPY tollbooth.config.yaml /app/tollbooth.config.yaml3. Set variables and deploy
Section titled “3. Set variables and deploy”railway variables set API_KEY=sk-your-keyrailway upVerify
Section titled “Verify”# Replace with your Railway domainDOMAIN="your-app.up.railway.app"
# Health checkcurl https://$DOMAIN/health# → {"status":"ok"}
# Test a paid route — should return 402curl -i https://$DOMAIN/weather# → HTTP/2 402- Railway automatically provisions HTTPS and routes traffic to your container’s listening port.
- For custom domains, add them in Settings > Networking > Custom Domain.
- Logs are available in the Railway dashboard or via
railway logs. - Railway supports auto-deploy from a linked GitHub repo — push to
mainand it redeploys automatically.