New API v1 LLM Gateway (Postgres + Redis)

Deploys New API v1.0.0-rc.51, an open-source LLM gateway that puts OpenAI, Claude, Gemini and other providers behind compatible APIs with users, tokens, quotas and usage logs. Runs with Postgres and Redis and a protected first start.

What you get

  • The official New API image, pinned by digest, serving the API (/v1, /v1/messages, /v1beta) and the web console
  • Postgres 18 for users, tokens, channels, quotas and usage logs, and Redis 8.2 for caches, rate limits and replica sync, each on a volume
  • Root account created on 127.0.0.1 with a generated password before the port opens, so the setup page is never exposed
  • Generated session and crypto keys; self-registration starts closed
  • Trusted-proxy setting covering Railway's edge, so rate limits and logs see real client IPs

Good for

  • One internal endpoint for several model providers, with a separate token, quota and model list per team or app
  • Load balancing and failover across several provider keys or channels
  • Usage and cost tracking per user, token, model and channel
  • Serving OpenAI-, Claude- and Gemini-format clients from one gateway

Cost

Measured on Railway: the stack idles at about 0.2 GB RAM in total (New API 0.04 to 0.07 GB, Postgres 0.07 to 0.10 GB, Redis 0.03 GB), and New API peaked at 0.13 GB under a burst of 3,000 authenticated requests. Relay memory with real provider streams was not measured.

Services in this template

  • Postgres · image ghcr.io/railwayapp-templates/postgres-ssl:18
  • Redis · image redis:8.2
  • New API · from baranberkay96/new-api-railway

Questions people ask

How do I log in?

Wait for the deployment to be active, open your domain and sign in as root (NEW_API_ROOT_USERNAME) with NEW_API_ROOT_PASSWORD from the New API service Variables tab. Then add a channel with your provider key and create an API token. If you lose the password, set a new NEW_API_ROOT_PASSWORD, set NEW_API_RESET_ROOT_PASSWORD to true, redeploy, log in, then set it back to false.

What drives the cost?

Three services run: New API, Postgres and Redis. Memory is small at rest, but busy gateways with many concurrent streaming responses need more, and the Postgres volume grows with usage logs. Model usage itself is billed by your providers.

Is data kept across redeploys, and how do I upgrade?

Yes, all data is in Postgres on a volume. The version is the FROM line (tag plus digest) in services/new-api/Dockerfile. Read the release notes, change both and redeploy; tables migrate on start. Back up Postgres first.

Are there licence or usage restrictions?

New API is AGPL-3.0, with extra attribution terms if you modify it. Redis 8 is RSALv2, SSPLv1 or AGPLv3. Connect only provider accounts you are entitled to use and follow each provider's terms; Railway's Fair Use Policy forbids reselling compute and running proxy or anonymization services. Seek professional advice for commercial resale of model access.

What if I use a custom domain?

Add https://your-domain to SESSION_COOKIE_TRUSTED_URL, otherwise logins from that domain are signed out when their session refreshes.

Full template README

Deploy and Host New API with Railway

New API is an open-source, self-hosted LLM gateway. It puts OpenAI, Claude, Gemini and many other model providers behind OpenAI-, Claude- and Gemini-compatible APIs, with users, API tokens, quotas and usage logs. This community template runs the official New API image with Postgres and Redis, a pinned version and a protected first start.

About Hosting New API

New API is a single Go service with a web console. Without configuration it falls back to SQLite on the container disk, signs sessions with a key that changes on every restart, and leaves a fresh instance uninitialized: whoever opens the setup page first becomes the root admin. This template fixes all three. Data lives in Postgres, Redis handles caching and multi-replica sync, and session and crypto keys are generated at deploy. Before the public port opens, a start script completes the setup on 127.0.0.1 with a generated root password, so the setup page is never exposed. The upstream image runs unmodified.

Common Use Cases

  • One internal endpoint for OpenAI, Claude and Gemini models, with a separate API token, quota and model list per team or application
  • Load balancing and failover across several provider keys or channels of the same model, with automatic channel tests
  • Usage and cost tracking per user, token, model and channel
  • Serving OpenAI-, Claude- and Gemini-format clients (SDKs, coding assistants, chat UIs) from the same gateway

Dependencies for New API Hosting

  • New API v1.0.0-rc.51, official image calciumion/new-api, pinned by digest (AGPL-3.0)
  • PostgreSQL 18 (Railway Postgres)
  • Redis 8.2 (Railway Redis)
  • API keys or accounts for the model providers you connect, added in the console

Deployment Dependencies

Implementation Details

Service Role Public Storage
New API API (/v1, /v1/messages, /v1beta), web console, health /api/status Yes, port 3000 none (all data in Postgres)
Postgres Users, tokens, channels, quotas, usage logs No Volume
Redis Caches, rate limits, sync between replicas No Volume

First login

  1. Wait until the New API deployment is active (healthcheck /api/status).
  2. Open https://{your-domain} and sign in as root (NEW_API_ROOT_USERNAME) with NEW_API_ROOT_PASSWORD from the New API service's Variables tab. The default upstream password 123456 does not exist here.
  3. Add a channel (a provider and your key), then create an API token and call https://{your-domain}/v1/chat/completions with Authorization: Bearer {token}. Requests without a valid token get HTTP 401.

Self-registration starts closed (NEW_API_REGISTER_ENABLED=false): the root user creates accounts. Open it under Settings if you run a shared gateway.

Lost root password: set NEW_API_ROOT_PASSWORD to a new value (8-72 characters), set NEW_API_RESET_ROOT_PASSWORD=true, redeploy, log in, then set the reset variable back to false.

Client IPs: TRUSTED_PROXIES includes Railway's edge (100.64.0.0/10), so rate limits and logs see real client IPs.

Custom domain: add https://{your-custom-domain} to SESSION_COOKIE_TRUSTED_URL (comma-separated), otherwise logins from that domain are signed out when their session refreshes.

Resources and plans: measured on Railway, the stack idles at about 0.2 GB RAM in total (New API 0.04-0.07 GB, Postgres 0.07-0.10 GB, Redis 0.03 GB) and New API peaked at 0.13 GB under a burst of 3,000 authenticated requests. It fits the Free and Trial plans for evaluation; use Hobby or Pro for production, where the Postgres volume holds the growing usage logs. Busy gateways with many concurrent streams need more memory.

Scaling: raise replicas on the New API service. Redis and the shared SESSION_SECRET keep sessions, caches and settings consistent across replicas. Long streaming responses finish during redeploys (RAILWAY_DEPLOYMENT_DRAINING_SECONDS).

Pinning and upgrades: the version is the FROM line in services/new-api/Dockerfile (tag plus digest). Upstream publishes its stable channel as v1.0.0-rc.N releases; read the release notes, change tag and digest, and redeploy. Tables migrate on start. Back up Postgres first.

Use it lawfully: connect only provider accounts and API keys you are entitled to use, and follow each provider's terms. Railway's Fair Use Policy forbids reselling Railway compute, evading usage limits and running proxy or anonymization services; a gateway for your own teams and applications is the intended use. Commercial or resale use of model access is your responsibility under your providers' terms and applicable law; get professional advice if unsure.

Why Deploy New API on Railway?

Railway gives New API a public HTTPS domain, private networking to its Postgres and Redis, generated secrets and usage-based billing. Other services in the project can call the gateway privately at http://${{New API.RAILWAY_PRIVATE_DOMAIN}}:3000, replicas are one setting, and upgrades are a one-line tag change.

Guides for this template

View New API v1 LLM Gateway (Postgres + Redis) on railway.com

Similar templates

TemplateCategoryDeploymentsDeploys
9Router
Self-hosted AI router for Claude, Gemini, Cursor & OpenAI tools.
AI/ML9,734
flowise-railway
Flowise - low-code LLM apps builder
AI/ML8,512
LibreChat
Open-source ChatGPT clone: multi-model, agents, search, multi-user auth
AI/ML6,762
Hermes Agent by Nous Research
Template for Hermes Agent by Nous Research
AI/ML6,413
OpenClaw
[Homebrew support] The AI that actually does things
AI/ML5,167
Hermes Agent
Self Host Hermes Agent. Autonomous AI agent w/ self-improving, tools & more
AI/ML4,092