LiteLLM is an open-source gateway for AI models. It provides a single OpenAI-format interface and routes each request to the right provider, such as OpenAI, Anthropic, Mistral, or your own Ollama instance. Your apps only need to communicate with LiteLLM, using a URL (Base URL) and a key. Your providers’ actual API keys are stored centrally in LiteLLM. You can create a separate virtual key for each app or user, restrict it to specific models, set a budget, or revoke it at any time.
In this guide, we’ll show you two ways to set it up: the easy way, as a One-Click App, which gets LiteLLM running with a database and HTTPS in just a few minutes, and a manual installation with Docker Compose. Then you’ll add your first model, create a virtual key, and connect an app using the Base URL.
LiteLLM is useful as soon as multiple apps, scripts, or people need to use AI models. LiteLLM is a good fit on a VPS if:
- You want to use multiple providers through a single interface. Your apps always make requests using the same OpenAI format, regardless of whether the provider behind it is OpenAI, Anthropic, or a local model.
- You don’t want provider keys in every app. The actual keys are stored only in LiteLLM, while your apps get their own virtual keys, which you can revoke individually.
- You want to limit costs and usage. Set a budget and request or token limits for each key, and view usage by key.
- You want to switch models without changing your apps. Apps use a fixed model name such as
chat-default; you can change which model it points to in LiteLLM. - You want to offer local models from Ollama and cloud models together through a single interface.
LiteLLM is less suitable if a single app uses just one provider. In that case, it’s easier to enter the API key directly in the app. LiteLLM doesn’t run models itself and isn’t a chat interface for end users. For browser-based chat, you need an app such as Open WebUI; for your own models on the server, use Ollama.
These three programs are often mentioned together, but they serve different purposes. You can find all of them in the app catalog:
| LiteLLM | Ollama | Open WebUI | |
|---|---|---|---|
| Purpose | Gateway: one API for multiple providers | Runs models on your own server | Browser-based chat interface |
| Runs models itself | no | yes (on the VPS CPU) | no |
| Designed for | Apps, scripts, automations | Your own models without an external provider | People who want to chat |
| Keys and budgets per app | yes, virtual keys | no | API keys per user |
The programs work well together: Ollama provides local models, LiteLLM brings them together with cloud models, and Open WebUI or another app uses LiteLLM as its interface.
The fastest way to get LiteLLM is through your VPS’s One-Click Apps. The app includes a PostgreSQL database for models, keys, and usage data, as well as Redis for caching. With a domain, it’s accessible directly over HTTPS, and it automatically generates the master key and login credentials. You don’t need to set up a reverse proxy, certificate, or firewall rules.
- A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See How to Set Up One-Click Apps for instructions.
- At least 2 GB of RAM; 4 GB of RAM and 2 vCPU cores are recommended. Immediately after startup, LiteLLM uses just under 1 GB of RAM with two worker processes; the database and Redis add only a small amount. The LiteLLM image uses around 1.8 GB of storage.
- API keys for the providers you want to use, or your own Ollama instance. LiteLLM doesn’t include models or access to providers.
- Open your VPS in the ZapX dashboard and switch to the One-Click Apps tab.
- Search for LiteLLM in the app catalog and click Install app.
- Use a custom subdomain or zap.cloud is already selected with a randomly generated name. Leave this option enabled or enter your own name, such as
llmorai-gateway. Your apps will access LiteLLM over HTTPS at this address. - You don’t need to fill in anything under App configuration. The
OPENAI_API_KEY,ANTHROPIC_API_KEY, andVOYAGE_API_KEYfields are optional. Leave them empty and add your providers directly in LiteLLM later.STORE_MODEL_IN_DBis set toTrue; leave it as is so you can add models in the interface. - Click Queue installation.
The initial installation takes a few minutes because the LiteLLM image is large. The app card will show “Starting” while it installs. On its first startup, LiteLLM creates its tables in the database.
All login credentials are generated automatically during installation:
- Click the gear icon on the app card and switch to App environment.
- Under Automatically generated values, you’ll find
SERVICE_USER_UI(username) andSERVICE_PASSWORD_UI(password) for the admin interface. Click the eye icon to show a value or the icon next to it to copy it. - Open your app using the Access link and add
/uito the address, for example,https://llm.example.com/ui. Without/ui, LiteLLM displays its API documentation. - Sign in using the username and password from App environment. You’ll land on the admin interface’s home page.
SERVICE_PASSWORD_MASTERKEY contains only the second part of the master key. LiteLLM adds sk- in front of it. So, for API requests using the master key, add sk- immediately before the value from App environment. Without sk-, LiteLLM responds with “Authentication Error.” The master key has full admin privileges. Never share it with apps; create a virtual key for each app instead.
At the top of the admin interface, LiteLLM displays the message “Environment-credential login is enabled.” This means sign-in using the credentials stored in the environment is enabled. This is expected for the One-Click App. Keep the username and password secret and don’t share them. To give other people access, create separate accounts under Internal Users.
After installation, you’ll see some models under Models + Endpoints, such as gpt-4o and gpt-4o-mini. They come from the app’s configuration file and use the OPENAI_API_KEY and VOYAGE_API_KEY variables. Requests to these models will fail as long as those variables are empty. You don’t have to use these models: add your own in the interface as described below in “Add Your First Model.” LiteLLM stores keys entered there in its database in encrypted form.
You can update LiteLLM in the app settings (gear icon), under App update. Click Check for updates, then install a new version using Apply update. If it says the app is up to date, there isn’t a newer version in the app catalog yet.
When a new version starts, LiteLLM automatically updates the database. You can only revert to the old version if you have a database backup from before the update. So back up your VPS first, for example, using Backups in the dashboard.
Models, provider keys, virtual keys, budgets, and usage data are stored in the app’s PostgreSQL database and are retained during updates. Provider keys are encrypted using SERVICE_PASSWORD_SALTKEY. If this value changes, LiteLLM can no longer read the stored keys.
The rest of this guide covers the manual installation of LiteLLM with Docker Compose on your VPS, for example, if you don’t use One-Click Apps on the server or want to run LiteLLM behind your own reverse proxy.
- A Linux VPS running Debian or Ubuntu with SSH access; see First Access via SSH.
- Docker and Docker Compose (Compose v2); see Install Docker. Verify the installation with
docker --versionanddocker compose version. - A domain or subdomain with an A record pointing to your VPS’s IP address (e.g.,
llm.example.com).
The values below are guidelines for LiteLLM with PostgreSQL and two worker processes. During the initial startup, while the database is being created, LiteLLM temporarily needs almost 2 GB of RAM. The official documentation estimates around one vCPU core and 4 GB of RAM per worker under load.
| Hardware | Minimum | Recommended |
|---|---|---|
| CPU | 1 vCPU core | 2 vCPU cores |
| RAM | 2 GB | 4 GB |
| Storage | 10 GB | 20 GB |
LiteLLM listens on port 4000. You don’t need to open this port if you use a reverse proxy as described below. With ufw, allow only SSH and the ports required for the reverse proxy:
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Ports published by Docker using ports: are accessible from the outside, even if ufw blocks them. Docker adds its own rules before those of ufw. So, as described below, bind LiteLLM only to 127.0.0.1. For more information, see Managing the Firewall on Linux.
Create a directory for LiteLLM and generate the keys and passwords. These commands write all values directly to the .env file without displaying them:
mkdir -p /opt/litellm
cd /opt/litellm
echo "POSTGRES_PASSWORD=$(openssl rand -hex 24)" >> .env
echo "LITELLM_MASTER_KEY=sk-$(openssl rand -hex 24)" >> .env
echo "LITELLM_SALT_KEY=sk-$(openssl rand -hex 24)" >> .env
echo "UI_PASSWORD=$(openssl rand -hex 16)" >> .env
chmod 600 .env
Then create the configuration file config.yaml, for example, using nano config.yaml:
general_settings:
store_prompts_in_spend_logs: false
litellm_settings:
drop_params: true
telemetry: false
model_list: []
Leave the model_list empty because you’ll add the models in the interface. drop_params makes LiteLLM omit parameters that a provider doesn’t recognize instead of rejecting the request.
Now create the docker-compose.yml file:
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_DB: litellm
POSTGRES_USER: litellm
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- ./postgres:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U litellm -d litellm"]
interval: 10s
retries: 10
litellm:
image: ghcr.io/berriai/litellm-database:1.109.1
restart: unless-stopped
command: ["--config", "/app/config.yaml", "--port", "4000", "--num_workers", "2"]
environment:
DATABASE_URL: postgresql://litellm:${POSTGRES_PASSWORD}@postgres:5432/litellm
LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
LITELLM_SALT_KEY: ${LITELLM_SALT_KEY}
UI_USERNAME: admin
UI_PASSWORD: ${UI_PASSWORD}
STORE_MODEL_IN_DB: "True"
volumes:
- ./config.yaml:/app/config.yaml:ro
ports:
- "127.0.0.1:4000:4000"
depends_on:
postgres:
condition: service_healthy
Here’s what the important lines mean:
litellm-database:1.109.1: The database-enabled image at a fixed version. The documentation advises against usinglatest.DATABASE_URL: LiteLLM stores models, virtual keys, budgets, and usage data in PostgreSQL. Virtual keys aren’t available without a database.LITELLM_MASTER_KEY: The admin key for the API. It must start withsk-.LITELLM_SALT_KEY: Encrypts provider keys in the database. Never change it after adding models, or the stored keys will no longer be readable.UI_USERNAMEandUI_PASSWORD: The login details for the admin interface.STORE_MODEL_IN_DB: Allows you to add models in the interface.--num_workers 2: Two worker processes. For a server you manage yourself, the documentation recommends using as many workers as there are vCPU cores.127.0.0.1:4000:4000: LiteLLM is only accessible from the server itself; external access is only possible through the reverse proxy.
Download the images and start LiteLLM:
docker compose pull
docker compose up -d
docker compose logs -f litellm
LiteLLM is ready when the log shows All migrations have been successfully applied. and Uvicorn running on http://0.0.0.0:4000. Exit the log view with Ctrl+C. On the server, run curl http://127.0.0.1:4000/health/liveliness to check whether LiteLLM is responding.
First, set up the reverse proxy as described in the next section. Then open https://llm.example.com/ui and sign in as admin. To display the password on the server, run grep UI_PASSWORD /opt/litellm/.env; to display the master key, run grep LITELLM_MASTER_KEY /opt/litellm/.env.
For a quick test without a domain, you can also use an SSH tunnel: ssh -L 4000:127.0.0.1:4000 root@SERVER_IP. While the tunnel is open, you can access the interface on your computer at http://localhost:4000/ui.
To access LiteLLM externally, put a reverse proxy with a valid certificate in front of it. For the basics, see Set Up a Reverse Proxy with nginx and Create an SSL Certificate (Let's Encrypt). Here’s an nginx server block:
server {
listen 80;
server_name llm.example.com;
location / {
proxy_pass http://127.0.0.1:4000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_read_timeout 300s;
client_max_body_size 20m;
}
}
Then get the certificate using certbot --nginx -d llm.example.com. Certbot will add HTTPS and the HTTP redirect to the block. proxy_buffering off ensures that streamed responses arrive word by word instead of all at once. The longer timeout prevents interruptions during long responses.
Your apps only need the API, not the interface at /ui. In nginx, use allow and deny to allow access to /ui only from your own IP address or VPN. For more tips, see Linux Security Tips.
The most important data is in the PostgreSQL database. It contains models, encrypted provider keys, virtual keys, budgets, and usage data. Back it up with pg_dump:
cd /opt/litellm
docker compose exec -T postgres pg_dump -U litellm -d litellm > litellm-db-$(date +%F).sql
Also back up .env, config.yaml, and docker-compose.yml. Without the LITELLM_SALT_KEY from .env, a restored database can’t decrypt the provider keys. Don’t store the backup only on the VPS itself.
First, back up the database and read the release notes for the new version. Then enter the new version for the image in docker-compose.yml and restart LiteLLM:
cd /opt/litellm
docker compose pull
docker compose up -d
When it starts, LiteLLM updates the database to the new version. The documentation advises against reverting by simply switching the image back to the old version. To roll back, you need the old version and the database backup from before the update. You can see the installed version in the top-left corner of the admin interface.
After setting up LiteLLM, add your first model, create a virtual key for your app, and use LiteLLM through the Base URL. The steps are the same for the One-Click App and the manual installation. In the examples, llm.example.com represents your LiteLLM address.
As an example, you’ll connect your own Ollama model. If Ollama with Open WebUI is running as a One-Click App, the Ollama API itself isn’t accessible from the internet. In this case, LiteLLM uses Open WebUI’s OpenAI-compatible API. First, create an API key there, as described in the Ollama guide. The process is the same for a provider such as OpenAI or Anthropic, but you’ll select the provider and enter its API key instead.
- In the admin interface, click Models + Endpoints on the left, then open the Add Model tab.
- Under Provider, select OpenAI-Compatible Endpoints (Together AI, etc.).
- Under LiteLLM Model Name(s), select Custom Model Name (Enter below) and enter the model name used by Open WebUI below it, for example,
llama3.2:1b. - Under Model Mappings, set the name your apps will use to call the model in Public Model Name, for example,
local-llama. - Enter
https://ai.example.com/apiunder API Base (your Open WebUI address with/api) and the key from Open WebUI under API Key. - Check the connection using Test Connect, then click Add Model.
The model now appears under Deployed Models. LiteLLM stores the key in the database in encrypted form, so it won’t appear in any app. If you want to switch to another model later, change the entry in LiteLLM. Your apps will continue calling local-llama.
Create a separate virtual key for each app. This lets you see usage by app and revoke a key without affecting the others:
- Click Virtual Keys on the left, then click Create New Key.
- Enter a name under Key Name, for example,
my-app. - Under Models, select the models this key can use, such as
local-llama. If you leave the field empty, the key can use all models. - Open Optional Settings. Under Max Budget (USD), set how much the key can spend in total. Use Reset Budget to reset the budget, for example, every month. Limit usage under Requests per minute Limit (RPM) and Tokens per minute Limit (TPM).
- Click Create Key. LiteLLM displays the key only once, along with the Gateway URL. Copy both and store the key securely.
A key that is authorized for local-llama only will see only that model in its model list. If an app using this key requests another model, LiteLLM will reject the request.
Any app that supports the OpenAI API can use LiteLLM. Instead of OpenAI’s address, enter your LiteLLM address as the Base URL, use the virtual key as the API key, and enter the public name from LiteLLM as the model. Many apps expect /v1 at the end of the Base URL; in that case, use https://llm.example.com/v1.
Test with curl:
curl https://llm.example.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_VIRTUAL_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "local-llama", "messages": [{"role": "user", "content": "Hello!"}]}'
With the official OpenAI library for Python, you only need to change the Base URL and key:
from openai import OpenAI
client = OpenAI(base_url="https://llm.example.com/v1", api_key="YOUR_VIRTUAL_KEY")
reply = client.chat.completions.create(
model="local-llama",
messages=[{"role": "user", "content": "Hello!"}],
)
print(reply.choices[0].message.content)
For automations such as n8n, create OpenAI-type credentials and enter the LiteLLM Base URL and virtual key. You can retrieve the list of models available to a key at https://llm.example.com/v1/models. Use the Playground in the admin interface to test models directly in your browser.
Under Usage and Logs, you can see how many requests and tokens each key has used. LiteLLM calculates costs using its own provider price list. For models whose prices LiteLLM doesn’t know, such as custom models through Ollama, it generally doesn’t calculate costs. In that case, a budget won’t take effect. It’s better to limit these keys using request and token limits. Always check the actual costs in your account with the relevant provider as well.
- No built-in models: LiteLLM only routes requests. To get responses, you need a provider with its own API key or your own Ollama instance.
- An additional service: If LiteLLM goes down, all connected apps lose access to their models. Schedule updates for quieter periods.
- Provider features: Not every provider-specific feature can be represented in the OpenAI format. For special features, check the LiteLLM documentation.
- Some features are paid: Some settings in the interface are marked “Premium feature” and require a LiteLLM license, for example, budgets per model within a key.
You’ve set up LiteLLM on your VPS, added your first model, created a virtual key with a budget, and connected an app using the Base URL. From now on, you can manage providers, models, keys, and limits in one place, while your apps communicate only with LiteLLM.
Prefer not to work through the Docker setup yourself? Use the easy One-Click App option described above under “The Easy Way: LiteLLM as a One-Click App.”