
Deploy New API: AI gateway, OpenRouter alternative
Self-hosted LLM gateway: one OpenAI-compatible API for Claude, Gemini, more
Just deployed
Redis
Just deployed
/data
Just deployed
/var/lib/postgresql/data
Deploy and Host New API on Railway
New API is an open-source, self-hosted AI gateway. It gives you one OpenAI-compatible endpoint in front of OpenAI, Claude, Gemini, DeepSeek, Qwen and dozens more providers, with API keys, per-key quotas, usage logs and cost accounting for every call. It is a self-hosted alternative to OpenRouter and LiteLLM, so your provider keys and request logs stay on your own infrastructure. This template deploys it with PostgreSQL and Redis already wired up and your administrator account created, so nobody else can claim a fresh instance before you sign in.
About Hosting New API
The gateway runs as a single container. PostgreSQL holds users, channels (your connections to upstream providers), keys and logs; Redis handles caching and rate limits. Every connection string, session secret and password is generated at deploy time, and your administrator login is ready the moment the deploy goes green. Logins stay valid across redeploys, logs and rate limits see each caller's real IP address, and session cookies are HTTPS-only on the domain Railway issues you. There is nothing to fill in before you deploy.
Common Use Cases
- One API for every model. Point any OpenAI-compatible client, SDK or tool at one URL and switch between GPT, Claude, Gemini and open models by changing the model name.
- Keys and budgets for a team. Give each person, app or customer their own API key with a quota, an expiry, allowed models and an IP allowlist, without ever sharing a provider key.
- See what every call costs. Usage logs and the dashboard break down calls, tokens and spend by key, user, model and channel.
- Failover and load spreading. Add several channels for the same model and New API shares traffic between them by weight and priority. With Retry Settings turned up, a failed call is retried on another channel.
How to Use New API After Deployment
- Wait for all three services to go green.
- Open the New API service, then Settings, then Networking. The generated domain there is your gateway URL. Add a custom domain on the same screen if you have one (see the FAQ).
- On that service's Variables tab, copy
NEW_API_ADMIN_USERNAMEand the generatedNEW_API_ADMIN_PASSWORD. - Visit your gateway URL and sign in with them. Change the password under Profile if you like; the variable is only read on first boot.
- Go to Channels and add a channel: pick the provider, paste your provider API key and choose its models.
- Go to API Keys and create a key. In any OpenAI SDK, set the base URL to
https://YOUR_DOMAIN/v1and the API key to the key you just created.
Is New API Free?
The software is free and open source under AGPL-3.0, and this template adds no licence cost. You pay Railway for the infrastructure it runs on, and your model providers for the tokens you use through your own keys.
New API vs OpenRouter and LiteLLM
| New API | OpenRouter | LiteLLM | |
|---|---|---|---|
| Hosting | Your Railway project | Vendor's cloud | Self-hosted |
| Provider keys | Yours, stored in your database | Vendor's account and credits | Yours |
| Admin web console | Full console for keys, users, channels and logs | Vendor dashboard | Admin UI |
| Per-key quotas and model limits | Yes | Per-key credit limits | Yes |
| Users and groups for reselling access | Yes, with top-ups and redemption codes | No | Teams |
| Runs inside your private network | Yes | No | Yes |
FAQ
I added a custom domain and logins fail on it. What do I change? Add the new address to SESSION_COOKIE_TRUSTED_URL on the New API service, comma-separated after the Railway domain (for example https://${{RAILWAY_PUBLIC_DOMAIN}},https://YOUR_DOMAIN), then redeploy. Login cookies are only refreshed for addresses on that list.
Can anyone sign up to my gateway? Sign-up is on by default (that is New API's own setting), but a new account starts with zero quota, so it cannot spend anything until you grant some. To close it, go to System Settings, then Basic Authentication, and turn off Registration Enabled.
Why does the Model Square page show no models? Models appear once you add a channel. Each channel lists the models it serves, and you set their prices under Models if you bill users.
Where is my data, and how do I back it up? Everything lives in the bundled PostgreSQL: users, channels, provider keys, API keys and usage logs. It has a persistent volume and survives redeploys. The Postgres service's DATABASE_PUBLIC_URL variable connects pg_dump or any Postgres client from outside for backups.
Do I need to set the Server Address setting? Only for OAuth sign-in (GitHub, OIDC and others) and payment webhooks. Set it under System Settings to your gateway URL before enabling either.
Dependencies for New API Hosting
- PostgreSQL 18: stores users, channels, provider keys, API keys and usage logs.
- Redis 8: caching and rate limits.
Deployment Dependencies
Implementation Details
The administrator account is created by the start command on first boot, from NEW_API_ADMIN_USERNAME and NEW_API_ADMIN_PASSWORD, so the public setup wizard is never shown. Later boots skip that step. SESSION_SECRET keeps logins valid across restarts and CRYPTO_SECRET encrypts stored data; changing CRYPTO_SECRET later makes existing encrypted data unreadable. Every other setting is in the environment variable reference and can be added as a variable on the New API service.
How to Upgrade: change the image tag on the New API service and redeploy; the database schema updates on boot. You can also let Railway do it: open each service's Settings, find Source, and use Configure Auto Updates with a maintenance window. Turn it on for all three services or for none; this template ships versions that were tested together. The pre-update volume backup is a Pro plan feature, so take your own backup first on Hobby, and detection can lag a new release by a few hours.
Why Deploy New API on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying New API on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
