Black Friday: Save 10% for life on all of our VPS plans, now through Cyber Monday

10% off on selected plans for as long as you keep the service · new orders · up to 10 uses per customer · ends Dec 1, 2026, 12:00 AM EST.

See plans
Guideschevron_rightServers

Servers · 8 min read · Updated

How to Self-Host the LiteLLM Proxy as Your AI Gateway

To self-host the LiteLLM proxy, download its official quickstart Docker Compose file (the proxy plus PostgreSQL), generate a master key and a salt key into .env, bind it to the server itself and put Caddy in front for HTTPS. Then add your providers' models in the admin UI at /ui and hand out virtual keys with budgets. Every app talks to one OpenAI-compatible endpoint, whether the model is OpenAI, Anthropic or your own GPU server. The gateway itself needs little: a small VPS such as our smallest (6 GB, $37.50 a month) is enough to start.

Why Run an AI Gateway

  • One endpoint: apps use the OpenAI SDK and only change the model name to switch provider.
  • Your keys stay private: provider keys live on the gateway, encrypted; apps get virtual keys you can revoke.
  • Budgets and spend: a limit per key, team or user, and a record of what each one used.
  • Your own models too: a model on your own GPU server sits next to the hosted ones behind the same keys.

1. Prepare the Server

On Ubuntu 24.04, secure the server and install Docker. Point an A record such as ai.example.com at it and allow ports 80 and 443.

2. Download the Compose File and Make Keys

mkdir ~/litellm && cd ~/litellm
curl -sSLO https://github.com/BerriAI/litellm/raw/main/litellm/deploy/docker/docker-compose.quickstart.yml
printf 'LITELLM_MASTER_KEY=sk-%s\nLITELLM_SALT_KEY=sk-%s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 32)" > .env
echo "POSTGRES_PASSWORD=$(openssl rand -hex 16)" >> .env
echo "LITELLM_BIND=127.0.0.1:" >> .env
chmod 600 .env
  • The master key authorises every management call and is the admin UI's password.
  • The salt key encrypts the provider keys you add. It cannot be rotated in place: change it and every stored key becomes unreadable until you enter it again. Back up .env.
  • LITELLM_BIND=127.0.0.1: publishes port 4000 on the server itself only, so it is reached through Caddy. Docker would otherwise open it past ufw, as explained in why ufw does not block Docker ports.

The file uses the latest image; for production, LiteLLM advises pinning a tested release tag. Add restart: unless-stopped to both services so they come back after a reboot, then start it:

docker compose -f docker-compose.quickstart.yml up -d
docker compose -f docker-compose.quickstart.yml ps

3. Add HTTPS With Caddy

sudo apt install -y caddy
sudo tee /etc/caddy/Caddyfile >/dev/null <<'EOF'
ai.example.com {
    reverse_proxy 127.0.0.1:4000
}
EOF
sudo systemctl reload caddy

4. Add Models

Open https://ai.example.com/ui, sign in as admin with the master key, and add your providers and models; the Compose file stores them in the database. To keep models in a file instead, LiteLLM reads a config.yaml in this form (LiteLLM config docs):

model_list:
  - model_name: claude-sonnet          # the name your apps send
    litellm_params:
      model: anthropic/claude-sonnet-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: local-gpt-oss          # your own vLLM or llama-server
    litellm_params:
      model: openai/openai/gpt-oss-120b
      api_base: http://10.0.0.5:8000/v1
      api_key: os.environ/LOCAL_LLM_KEY

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

For your own model server, the openai/ prefix tells LiteLLM it speaks the OpenAI API; the rest is the model name that server expects. Keep that server on a private network or behind its own key.

5. Hand Out Virtual Keys

Create a key for each app or person, limited to certain models:

curl https://ai.example.com/key/generate \
  -H "Authorization: Bearer YOUR_MASTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"models": ["claude-sonnet", "local-gpt-oss"], "metadata": {"user": "support-bot"}}'

A spending limit per key (max_budget) and other limits are set in the admin UI or the same API (virtual keys docs). Then any OpenAI client works with the new key:

curl https://ai.example.com/v1/chat/completions \
  -H "Authorization: Bearer sk-THE-VIRTUAL-KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet", "messages": [{"role": "user", "content": "Hello"}]}'

Backups and Updates

Keys, models and spend records live in PostgreSQL; the provider keys inside are encrypted with the salt key, so back up both the database and .env:

cd ~/litellm
docker compose -f docker-compose.quickstart.yml exec -T db pg_dump -U litellm litellm | gzip > ~/litellm-$(date +%F).sql.gz

Copy the dump off the server, as in backing up a database to S3. To update, change the image tag, then docker compose -f docker-compose.quickstart.yml pull and up -d. For production, LiteLLM also suggests adding NO_DOCS="True" and NO_OPENAPI="True" to the proxy's environment to hide its API docs pages.

Common Questions

  • What is the LiteLLM proxy?

    An open-source AI gateway: one OpenAI-compatible endpoint in front of many model providers and your own model servers. It hands out its own API keys, tracks spending per key and enforces budgets, so apps and people never see your provider keys.

  • Does LiteLLM need a database?

    For virtual keys, budgets and spend tracking, yes: PostgreSQL. Without one, requests with virtual keys fail and budgets are not enforced. The official quickstart Compose file runs PostgreSQL next to the proxy.

  • Can LiteLLM route to my own vLLM or Ollama server?

    Yes. Add a model with the openai/ prefix and the api_base of any OpenAI-compatible server, such as vLLM or llama.cpp's llama-server, and clients reach it through the same endpoint and keys as the hosted models.

  • Is LiteLLM free?

    The proxy's core is open source under the MIT licence. Some enterprise features are under LiteLLM's commercial licence, so check the licence of any feature you plan to rely on.

Plans and prices

VPS Plans

KVM servers with full root access for your AI gateway, built in minutes.

See all plans
  • Bronze

    3 vCPU · 6 GB RAM · 75 GB NVMe

    2 TB transfer

    $37.50/mo

    Configure inAshburnDallas
  • Silver

    4 vCPU · 8 GB RAM · 100 GB NVMe

    4 TB transfer

    $46.50/mo

    Configure inAshburnDallas
  • Gold

    6 vCPU · 12 GB RAM · 150 GB NVMe

    6 TB transfer

    $60.00/mo

    Configure inAshburnDallas
  • Diamond

    8 vCPU · 16 GB RAM · 200 GB NVMe

    8 TB transfer

    $73.50/mo

    Configure inAshburnDallas

Network port: 10 Gbps in Ashburn, VA, 50 Gbps in Dallas, TX. Pick the location when you configure.

Keep Reading

All guides
Self-Host the LiteLLM Proxy AI Gateway | Virteche Cloud