One API key and spend limits for LLMs on Railway

By Tracklayer · Updated 2026-11-20

Short answer: run an LLM gateway. It is one service that accepts OpenAI-style requests with a key you issue, forwards them to the provider accounts you connect, and records usage. On Railway you can deploy LiteLLM, New API or 9Router from a template. For per-team keys with budgets and rate limits, LiteLLM is the template that documents that most directly.

Deploy LiteLLM gateway on Railway

When you need a gateway

Apps built with AI tools often hard-code one provider’s key. A gateway helps when:

You still bring your own provider accounts or API keys. The gateway does not include model access, and provider usage is billed by the providers.

Compare the three templates

LiteLLM New API 9Router
Version pinned v1.104.2 v1.0.0-rc.51 0.5.116
API styles OpenAI-compatible OpenAI, Claude and Gemini compatible OpenAI-compatible, plus Anthropic- and Gemini-style routes
Keys and limits Virtual keys with budgets, model allow-lists, RPM/TPM limits Per-user API tokens with quotas and model lists One generated API key
Data store Postgres and Redis Postgres and Redis SQLite on a volume
Admin login /ui, UI_USERNAME and UI_PASSWORD root and NEW_API_ROOT_PASSWORD INITIAL_PASSWORD
Licence MIT (enterprise folder separate) AGPL-3.0 with extra terms MIT
Measured memory Not stated About 0.2 GB for the whole stack, idle About 0.1 GB idle

Memory figures are measurements from each README, taken on Railway. There is no matching ranking page for gateways on this site yet.

Deploy LiteLLM, step by step

  1. Deploy the template. It creates the LiteLLM proxy, Postgres and Redis. The master key, salt key and Admin UI password are generated.
  2. Wait for the healthcheck. The proxy reports ready at /health/readiness.
  3. Sign in. Open https://{your-domain}/ui with UI_USERNAME (admin) and UI_PASSWORD from the service’s Variables tab.
  4. Add a model. Under Models, paste your provider key. Or set the optional OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY or OPENROUTER_API_KEY variables.
  5. Create a virtual key. Set its budget, model allow-list and limits, then call https://{your-domain}/v1/chat/completions with it. Keep LITELLM_MASTER_KEY for administration only.
  6. Optional: turn on caching. The Redis cache is opt-in per request. Send "cache": {"use-cache": true} or set LITELLM_CACHE_MODE to default_on.

For New API, sign in as root with NEW_API_ROOT_PASSWORD, add a channel (a provider and your key), create an API token and call /v1/chat/completions with Authorization: Bearer {token}. Self-registration starts closed. For 9Router, sign in with INITIAL_PASSWORD, connect providers in the dashboard, and send the NINEROUTER_API_KEY value as a bearer key. Other services in the same Railway project can call any of them over the private network.

What persists

LiteLLM stores models, keys, teams, budgets and spend logs in Postgres on a volume. New API stores users, tokens, channels, quotas and usage logs in Postgres on a volume. 9Router stores providers, tokens, keys, combos and usage in SQLite on a volume at /app/data, with automatic backups. Treat these volumes as secrets because they hold provider credentials.

Costs

Railway bills usage, so the gateway’s cost follows its RAM and CPU. The READMEs do not state a monthly price, and this guide does not estimate one. New API and 9Router state measured idle memory (see the table), and both report running under small limits. For LiteLLM, cost depends on workers and replicas: each worker uses up to 10 Postgres connections. Gateway traffic through the public domain counts as egress, so use the private URL from other Railway services. The model spend itself is billed by your providers.

Limits and licence notes

This is not legal advice. These are community templates, not affiliated with BerriAI, QuantumNous, the 9Router authors, any AI provider or Railway.

Other options

For a chat front end on top of a gateway, see the LLM chat UI ranking. For models you host yourself, see local LLM templates. More guides are listed at /guides/.

FAQ

How do I log in to the LiteLLM Admin UI?

Open https://{your-domain}/ui and sign in with UI_USERNAME (admin) and the generated UI_PASSWORD from the LiteLLM service variables. Add a model under Models, then create a virtual key and call /v1/chat/completions with it. Keep LITELLM_MASTER_KEY for administration only, and never change LITELLM_SALT_KEY after models have been added.

Can I give each team its own key and budget?

Yes. LiteLLM supports virtual keys with a monthly budget, a model allow-list and RPM/TPM limits per team or application, and it tracks spend per key, user and team. New API gives each team or application its own API token with a quota and model list, and logs usage per user, token, model and channel. 9Router uses one API key for the whole deployment, so it suits personal or small-team use rather than per-team budgets.

What licence does each gateway use?

LiteLLM is MIT outside its enterprise/ directory, which has its own enterprise licence; the template does not enable enterprise features. New API is AGPL-3.0 with extra attribution terms: modified versions must keep the attribution and a visible link to its repository, and modified network-served versions must offer their source. 9Router is MIT. Check the terms for your use; this is not legal advice.

Is it fine to share provider accounts or resell access through a gateway?

The templates say no. Connect only provider accounts and API keys you are entitled to use, and follow each provider's terms, which may restrict consumer subscriptions in third-party tools. Railway's Fair Use Policy forbids evading usage limits, reselling compute and running proxy or anonymization services. A gateway for your own teams and applications is the intended use.

Is data kept across redeploys?

LiteLLM and New API keep their data in Postgres on a volume, with Redis for caching and rate limits. 9Router keeps a SQLite database on a volume at /app/data, so keep it to one replica. Treat the volume and its backups as secrets, since they hold provider keys.