Railway

Deploy LiteLLM Proxy — Self-Hosted AI Gateway for 100+ LLMs

Self-host an AI gateway for 100+ LLMs with spend tracking & budgets.

Deploy LiteLLM Proxy — Self-Hosted AI Gateway for 100+ LLMs

Just deployed

Just deployed

/data

/var/lib/postgresql/data

Deploy and Host LiteLLM Proxy on Railway

LiteLLM Proxy is the open-source AI gateway — ~40k GitHub stars, YC-backed, 240M+ Docker pulls — that puts one OpenAI-compatible endpoint in front of 100+ LLM providers. Point your apps at a single URL and route to OpenAI, Anthropic, Gemini, Azure, Groq, Bedrock, or a local Ollama behind the scenes — with virtual keys, per-team and per-user spend tracking, budget enforcement, load balancing, fallbacks, and an admin dashboard out of the box.

This template deploys LiteLLM with PostgreSQL (for virtual keys and spend tracking) and Redis (for caching) — the production setup. Self-host on Railway for ~$10–15/month and replace Helicone ($20/mo), OpenRouter's markup, and hand-rolled key-management scripts with infrastructure you own.


What This Template Deploys

ServicePurpose
LiteLLM ProxyThe AI gateway — unified OpenAI-compatible API for 100+ providers, virtual keys, spend tracking, and admin UI on port 4000
PostgreSQL 16Stores virtual keys, per-key/team spend, budgets, and request metadata — required for the dashboard and key management
RedisCaches responses and coordinates rate limiting and routing across requests

All services connect over Railway's private network with credentials injected automatically. The proxy is secure by default — a master key gates all requests. Point any OpenAI SDK at your Railway URL with a one-line base_url change and existing code works unchanged.


About Hosting LiteLLM Proxy

The problem LiteLLM solves: several developers, multiple providers, and no visibility into who's burning budget on which model until the invoice lands. LiteLLM exposes one OpenAI-compatible endpoint, routes each request to the provider you configured, tracks spend per virtual key, enforces budgets before the request leaves your server, and logs everything — in one service.

It needs PostgreSQL (virtual keys, spend tracking) and ideally Redis (caching). LiteLLM is CPU-only Python at ~400 MB idle — no GPU required, which makes Railway a natural home. This template wires the proxy, Postgres, and Redis over private networking with automatic HTTPS.

Typical cost: ~$10–15/month on Railway for the proxy, PostgreSQL, and Redis, plus your own LLM provider usage. That replaces Helicone's $20/month observability, OpenRouter's per-request markup, and the hand-rolled key scripts teams otherwise maintain — while keeping all keys and spend data on your own infrastructure.


Deploy in Under 5 Minutes

  1. Click Deploy on Railway — LiteLLM, PostgreSQL, and Redis build automatically (~3–4 minutes)
  2. DATABASE_URL, REDIS_URL, and a LITELLM_MASTER_KEY (starting with sk-) are wired/generated
  3. Add provider API keys as variables — OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, etc.
  4. Open [your-domain]/ui and log in with admin and your master key to reach the dashboard
  5. Point your app's OpenAI client base_url at your Railway URL and start routing requests

No per-provider SDKs. No key-management scripts. No code changes beyond the base URL.


Common Use Cases

  • One API for 100+ LLM providers — call OpenAI, Anthropic, Gemini, Groq, Bedrock, and local Ollama through a single OpenAI-compatible endpoint; switch models with a config change, no code
  • Per-team and per-user spend tracking — issue virtual keys with budgets so you see exactly which project burns which model's budget, and cap spend before the invoice surprises you
  • Self-hosted alternative to Helicone / OpenRouter — get observability and multi-provider routing without Helicone's $20/month or OpenRouter's per-request markup, on your own instance
  • Automatic fallbacks and load balancing — route a primary model with a fallback list so a provider 429 or outage transparently retries on the next provider with no app changes
  • Front your Ollama and cloud models together — expose local Ollama models and cloud APIs behind one gateway, so apps use the same interface for self-hosted and hosted inference
  • Budget guardrails for AI features — enforce hard spend limits per key; LiteLLM returns a 429 before forwarding when a budget is exceeded, so no runaway costs reach the provider

Configuration

VariableRequiredDescription
LITELLM_MASTER_KEY✅ RequiredAdmin/master key — must start with sk-; gates all requests and creates virtual keys
DATABASE_URL✅ Auto-injectedPostgreSQL connection string via Railway reference variable
REDIS_URLRecommendedRedis URI for caching and rate limiting via Railway reference variable
OPENAI_API_KEYOptionalEnables OpenAI models (add keys only for providers you use)
ANTHROPIC_API_KEYOptionalEnables Anthropic Claude models
GEMINI_API_KEYOptionalEnables Google Gemini models
STORE_MODEL_IN_DBRecommendedtrue — lets you add/manage models from the dashboard, stored in Postgres
PORTPre-set4000 — the proxy's default port

The master key must start with sk- and gates everything — keep it secret and use virtual keys (generated from it) for apps and teams, never the master key directly. Add provider keys only for the providers you actually use; each one auto-registers that provider's models.


LiteLLM Proxy vs. Alternatives

LiteLLM (Railway)OpenRouterHeliconeDirect per-provider
Cost~$10–15/mo flatPer-request markup$20/mo+Provider fees only
Self-hosted / own keys✅ Yes❌ Their infra⚠️ Proxy/SaaS✅ Yes
100+ providers, one API✅ Yes✅ Yes⚠️ Observability❌ Separate SDKs
Virtual keys + budgets✅ Built-in⚠️ Limited⚠️ Tracking only❌ Build it
Spend tracking per team✅ Yes⚠️ Basic✅ Yes❌ No
Fallbacks + load balancing✅ Yes✅ Yes❌ No❌ Build it
Data ownership✅ Your instance❌ OpenRouter⚠️ Varies✅ Yes
Open source✅ MIT❌ No⚠️ PartialN/A

Dependencies for LiteLLM Hosting

  • Railway account — Hobby plan (~$10–15/month) for the proxy, PostgreSQL, and Redis
  • API keys for the LLM providers you want to route to (added as variables)
  • Any OpenAI-compatible client — no LiteLLM-specific SDK required

Deployment Dependencies

Implementation Details

This template deploys the LiteLLM proxy with PostgreSQL 16 and Redis over Railway's private network. LiteLLM requires PostgreSQL for the admin UI, virtual keys, and spend tracking — an in-memory mode exists but drops those core features, so Postgres is used here; Redis handles caching.

The proxy is secure by default: LITELLM_MASTER_KEY (must start with sk-) authenticates all requests, and you generate scoped virtual keys from it for apps and teams. Configure models via config.yaml or, with STORE_MODEL_IN_DB=true, from the dashboard. Point any OpenAI client's base_url at your Railway URL — the API shape is identical to OpenAI's, so migration is one line.


Frequently Asked Questions

What does LiteLLM Proxy actually do? It's a self-hosted AI gateway: one OpenAI-compatible endpoint in front of 100+ LLM providers. Your apps talk to LiteLLM, and it routes to whichever provider/model you configured, tracks spend per virtual key, enforces budgets, and handles fallbacks — so you stop wiring provider-specific SDKs and get central visibility and control over LLM usage.

How does it save money versus OpenRouter or Helicone? OpenRouter adds a per-request markup; Helicone's observability starts at $20/month. LiteLLM self-hosted is ~$10–15/month flat on Railway and you pay providers directly at their rates with no markup. You also prevent overspend: budgets return a 429 before a request reaches the provider, so no cost is incurred once a key is over budget.

Does it need PostgreSQL? Yes for the full feature set. Virtual keys, per-team spend tracking, and the admin dashboard all require PostgreSQL. LiteLLM can run in-memory without a database, but that drops the spend and key features that are the main reason to run the proxy — so this template includes Postgres.

Can I use it with local Ollama and cloud models together? Yes. Configure Ollama models and cloud providers in the same LiteLLM instance, and apps access both through the identical OpenAI-compatible interface. It pairs naturally with a self-hosted Ollama on Railway — LiteLLM becomes the unified front door for local and cloud inference.

Do I lose keys and spend data if Railway redeploys? No. Virtual keys, budgets, spend history, and model config (with STORE_MODEL_IN_DB=true) live in the Railway-managed PostgreSQL database. Redeploys and updates don't affect them.

Is it hard to migrate my app to LiteLLM? No — it's a one-line change. LiteLLM's API matches OpenAI's, so you point your client's base_url at your Railway proxy URL and use a LiteLLM virtual key. Everything else stays the same.


Why Deploy and Host LiteLLM Proxy 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 LiteLLM Proxy on Railway, you get a self-hosted AI gateway for 100+ LLM providers — one OpenAI-compatible API, virtual keys, per-team spend tracking, budgets, and fallbacks — backed by PostgreSQL and Redis at ~$10–15/month flat, with all your keys and usage data on infrastructure you own.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
112
View Template
stella
Self-host stella with web, API, Postgres, Redis, and object storage.

Jan Kubica
1
View Template
Hermes Agent | OpenClaw Alternative with Dashboard
Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

codestorm
51