---
title: "Deploy New API: AI gateway, OpenRouter alternative"
description: "Self-hosted LLM gateway: one OpenAI-compatible API for Claude, Gemini, more"
category: "AI/ML"
url: https://railway.com/deploy/new-api-ai-gateway-openrouter-alternativ
---

# Deploy New API: AI gateway, OpenRouter alternative

Self-hosted LLM gateway: one OpenAI-compatible API for Claude, Gemini, more

**[Deploy New API: AI gateway, OpenRouter alternative on Railway](https://railway.com/template/new-api-ai-gateway-openrouter-alternativ)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/new-api-ai-gateway-openrouter-alternativ/manifest.json

- **Creator:** ProCode
- **Category:** AI/ML

## Template content

### New API https://github.com/QuantumNous.png

- **Image:** calciumion/new-api:v1.0.0-rc.45
- **Start command:** `sh -c '/new-api & p=$!; trap "kill -TERM $p" TERM INT; until wget -q -O /dev/null http://127.0.0.1:$PORT/api/status; do sleep 1; done; wget -q -O /dev/null --header=Content-Type:application/json --post-data="$NEW_API_SETUP_JSON" http://127.0.0.1:$PORT/api/setup; wait $p; wait $p'`
- **Health check:** /api/status
- **Public domain:** Yes

### Redis https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.2.10
- **Start command:** `/bin/sh -c "rm -rf $RAILWAY_VOLUME_MOUNT_PATH/lost+found/ && exec docker-entrypoint.sh redis-server --requirepass $REDIS_PASSWORD --save 60 1 --dir $RAILWAY_VOLUME_MOUNT_PATH"`

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18.6

## Documentation

# 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

1. Wait for all three services to go green.
2. 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).
3. On that service's **Variables** tab, copy `NEW_API_ADMIN_USERNAME` and the generated `NEW_API_ADMIN_PASSWORD`.
4. 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.
5. Go to **Channels** and add a channel: pick the provider, paste your provider API key and choose its models.
6. Go to **API Keys** and create a key. In any OpenAI SDK, set the base URL to `https://YOUR_DOMAIN/v1` and 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

- [New API website](https://www.newapi.ai)
- [New API documentation](https://docs.newapi.pro)
- [Source on GitHub (AGPL-3.0)](https://github.com/QuantumNous/new-api)
- [Container image on Docker Hub](https://hub.docker.com/r/calciumion/new-api)

### 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](https://docs.newapi.pro/en/docs/installation/config-maintenance/environment-variables) 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.

## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/new-api-ai-gateway-openrouter-alternativ
