One API key and spend limits for LLMs on Railway
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 RailwayWhen you need a gateway
Apps built with AI tools often hard-code one provider’s key. A gateway helps when:
- several apps or teams share model access and each needs its own key, budget and limits,
- you want to switch between OpenAI, Anthropic, Gemini or self-hosted models without changing application code,
- you want to see spend per key, user or team in one place,
- coding assistants and automation tools need a single internal endpoint.
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
- Deploy the template. It creates the LiteLLM proxy, Postgres and Redis. The master key, salt key and Admin UI password are generated.
- Wait for the healthcheck. The proxy reports ready at
/health/readiness. - Sign in. Open
https://{your-domain}/uiwithUI_USERNAME(admin) andUI_PASSWORDfrom the service’s Variables tab. - Add a model. Under Models, paste your provider key. Or set the optional
OPENAI_API_KEY,ANTHROPIC_API_KEY,GEMINI_API_KEYorOPENROUTER_API_KEYvariables. - Create a virtual key. Set its budget, model allow-list and limits, then call
https://{your-domain}/v1/chat/completionswith it. KeepLITELLM_MASTER_KEYfor administration only. - Optional: turn on caching. The Redis cache is opt-in per request. Send
"cache": {"use-cache": true}or setLITELLM_CACHE_MODEtodefault_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
- LiteLLM: the enterprise licence covers its
enterprise/directory, and the template does not enable those features. Do not changeLITELLM_SALT_KEYafter adding models. - New API: AGPL-3.0. Modified versions must keep the upstream attribution and a visible link to the repository, and network-served modifications must offer source. The template runs the image unmodified.
- 9Router: keep one replica, because the SQLite volume cannot be shared. Its upstream dashboard page loads Google Analytics, and its optional cloud sync to 9router.com is off by default.
- Acceptable use: connect only accounts and keys you are entitled to use. Do not use a gateway to share accounts, resell access or get around provider limits. Railway’s Fair Use Policy forbids evading usage limits and operating proxy or anonymization services.
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.