---
title: How to Deploy LiteLLM - Open-Source AI Gateway
url: https://docs.vultr.com/how-to-deploy-litellm-open-source-ai-gateway
description: Deploy LiteLLM on a Linux server using Docker Compose with PostgreSQL, Prometheus, and Traefik for automatic HTTPS to run an OpenAI-compatible AI gateway.
publish_date: 2026-09-09T03:29:37.730093Z
last_updated: 2026-10-21T22:06:21.620000Z
author: Ayomide olofinsawe
header_image: https://lhr1.vultrobjects.com/docs-main-doc-assets-1/2669/4383b2c2-03f4-4f20-9c44-ddd8ca02bcaf.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

[LiteLLM](https://litellm.ai) is an open-source AI gateway that provides a unified, OpenAI-compatible API for over 100 large language model (LLM) providers, removing the need to integrate with each provider's Software Development Kit (SDK) and authentication scheme. In production, teams use LiteLLM to issue virtual keys with budget limits, track token usage and spend across providers, and configure centralized access control and routing.

This article explains how to deploy LiteLLM on a Linux server using Docker Compose with PostgreSQL for persistent storage, Prometheus for metrics collection, and Traefik as the reverse proxy for HTTPS access.

## Prerequisites

Before you begin, you need to:

* Have access to a [Linux-based server](https://www.vultr.com/features/operating-systems/) with at least 4 CPU cores and 8 GB of RAM as a [non-root user with sudo privileges](https://docs.vultr.com/how-to-create-a-sudo-user-in-linux).
* [Install Docker and Docker Compose](https://docs.vultr.com/how-to-install-docker-on-ubuntu-24-04#install-docker).
* Create a [DNS A record](https://docs.vultr.com/products/network/dns/management/manage-records), such as `litellm.example.com`, pointing to your server's IP address.
* Have an API key from at least one [supported LLM provider](https://docs.litellm.ai/docs/providers).

## Set Up the Directory Structure, Configuration, and Environment Variables

LiteLLM requires a configuration file to define model providers and routing rules, a Prometheus configuration file for metrics scraping, and environment variables for secrets and database credentials. This section prepares all three before deploying the stack.

1. Create the project directory with subdirectories for persistent data.

    ```console
    $ mkdir -p ~/litellm/{letsencrypt,postgres,prometheus}
    ```

    * `letsencrypt`: Stores SSL/TLS certificates.
    * `postgres`: Persists PostgreSQL database files.
    * `prometheus`: Persists Prometheus metrics data.

1. Navigate to the project directory.

    ```console
    $ cd ~/litellm
    ```

1. Prometheus runs as UID 65534 inside the container. Set matching ownership on its host directory so the container can write to it.

    ```console
    $ sudo chown -R 65534:65534 prometheus
    ```

1. Generate a master key and salt key for LiteLLM. Run this command twice to produce two separate values.

    ```console
    $ openssl rand -hex 32
    ```

    Save both values for the `LITELLM_MASTER_KEY` and `LITELLM_SALT_KEY` fields in the next step.

1. Create the `.env` file to store credentials and secrets.

    ```console
    $ nano .env
    ```

1. Add the following values:

    ```ini
    DOMAIN=litellm.example.com
    LETSENCRYPT_EMAIL=admin@example.com
    LITELLM_MASTER_KEY=sk-YOUR_MASTER_KEY
    LITELLM_SALT_KEY=sk-YOUR_SALT_KEY
    LLM_PROVIDER_API_KEY=YOUR_LLM_PROVIDER_API_KEY
    POSTGRES_PASSWORD=STRONG_DATABASE_PASSWORD
    DATABASE_URL=postgresql://llmproxy:${POSTGRES_PASSWORD}@db:5432/litellm
    UI_USERNAME=admin
    UI_PASSWORD=YOUR_UI_PASSWORD
    ```

    Replace the placeholders with your own values:

    * `litellm.example.com`: Domain pointing to your server's IP address.
    * `admin@example.com`: Email address for Let's Encrypt certificate notifications.
    * `sk-YOUR_MASTER_KEY`: Admin key used to authenticate with the LiteLLM API. Replace `YOUR_MASTER_KEY` with the first value you generated, and keep the `sk-` prefix.
    * `sk-YOUR_SALT_KEY`: Key used to encrypt provider credentials stored in PostgreSQL. Replace `YOUR_SALT_KEY` with the second value you generated, and keep the `sk-` prefix. This value cannot be changed after the first model is added.
    * `YOUR_LLM_PROVIDER_API_KEY`: API key for the LLM provider configured in `config.yaml`.
    * `STRONG_DATABASE_PASSWORD`: PostgreSQL password used by both the database container and the connection string. Replace with a strong password of your choice.
    * `admin`: Username for the LiteLLM dashboard. Replace it with your preferred username.
    * `YOUR_UI_PASSWORD`: Password for the LiteLLM dashboard. Use a strong password distinct from your master key.

    Save and close the file.

1. Create the LiteLLM configuration file.

    ```console
    $ nano config.yaml
    ```

1. Add the following contents:

    ```yaml
    model_list:
      - model_name: my-model
        litellm_params:
          model: provider/model
          api_key: os.environ/LLM_PROVIDER_API_KEY

    litellm_settings:
      callbacks:
        - prometheus
      require_auth_for_metrics_endpoint: true

    general_settings:
      master_key: os.environ/LITELLM_MASTER_KEY
    ```

    Replace `my-model` with a name that identifies the model in LiteLLM. Replace `provider/model` with the LiteLLM provider prefix followed by the model identifier in the format `provider/model-name`. For example, to expose Anthropic's Claude Haiku, use `anthropic/claude-haiku-4-5`. The `os.environ/` prefix tells LiteLLM to read the value from an environment variable at runtime rather than hardcoding it in the file. For provider prefixes and model identifiers, see the [LiteLLM providers documentation](https://docs.litellm.ai/docs/providers).

    The `litellm_settings` block enables Prometheus metrics collection via the `callbacks` field. Setting `require_auth_for_metrics_endpoint` to `true` restricts the `/metrics` endpoint to authenticated requests only, so only Prometheus, which sends the master key as a Bearer token, can scrape metrics successfully.

    The `general_settings` block defines the master key LiteLLM uses to authenticate administrative API requests and manage virtual keys. Reading the key from an environment variable keeps its value out of the configuration file.

    Save and close the file.

1. Create the Prometheus configuration file.

    ```console
    $ nano prometheus.yml
    ```

1. Add the following contents:

    ```yaml
    global:
      scrape_interval: 15s
      evaluation_interval: 15s

    scrape_configs:
      - job_name: "litellm"
        static_configs:
          - targets: ["litellm:4000"]
        bearer_token: "sk-YOUR_MASTER_KEY"
    ```

    Replace `sk-YOUR_MASTER_KEY` with the value of `LITELLM_MASTER_KEY` from your `.env` file. Prometheus uses this token to authenticate its scrape requests against the protected `/metrics` endpoint.

    Save and close the file.

## Deploy with Docker Compose

The deployment stack runs LiteLLM behind Traefik, which handles Transport Layer Security (TLS) termination and automatic certificate provisioning through Let's Encrypt. PostgreSQL provides persistent storage for virtual keys, spend data, and usage logs. Prometheus collects gateway metrics by scraping the LiteLLM `/metrics` endpoint every 15 seconds over the internal Docker network.

1. Add your user account to the Docker group.

    ```console
    $ sudo usermod -aG docker $USER
    ```

1. Apply the new group membership.

    ```console
    $ newgrp docker
    ```

1. Create the Docker Compose manifest file.

    ```console
    $ nano docker-compose.yaml
    ```

1. Add the following contents:

    ```yaml
    services:
      traefik:
        image: traefik:v3.6
        container_name: traefik
        restart: always
        command:
          - "--providers.docker=true"
          - "--providers.docker.exposedbydefault=false"
          - "--entrypoints.web.address=:80"
          - "--entrypoints.websecure.address=:443"
          - "--entrypoints.web.http.redirections.entrypoint.to=websecure"
          - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
          - "--certificatesresolvers.le.acme.httpchallenge=true"
          - "--certificatesresolvers.le.acme.httpchallenge.entrypoint=web"
          - "--certificatesresolvers.le.acme.email=${LETSENCRYPT_EMAIL}"
          - "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock:ro
          - ./letsencrypt:/letsencrypt

      litellm:
        image: docker.litellm.ai/berriai/litellm:v1.89.1
        container_name: litellm
        restart: always
        volumes:
          - ./config.yaml:/app/config.yaml
        command:
          - "--config=/app/config.yaml"
        environment:
          DATABASE_URL: ${DATABASE_URL}
          STORE_MODEL_IN_DB: "True"
        env_file:
          - .env
        expose:
          - "4000"
        depends_on:
          db:
            condition: service_healthy
        healthcheck:
          test:
            - CMD-SHELL
            - python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:4000/health/liveliness')"
          interval: 30s
          timeout: 10s
          retries: 3
          start_period: 40s
        labels:
          - "traefik.enable=true"
          - "traefik.http.routers.litellm.rule=Host(`${DOMAIN}`)"
          - "traefik.http.routers.litellm.entrypoints=websecure"
          - "traefik.http.routers.litellm.tls=true"
          - "traefik.http.routers.litellm.tls.certresolver=le"
          - "traefik.http.services.litellm.loadbalancer.server.port=4000"

      db:
        image: postgres:16
        container_name: litellm_db
        restart: always
        environment:
          POSTGRES_DB: litellm
          POSTGRES_USER: llmproxy
          POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
        volumes:
          - ./postgres:/var/lib/postgresql/data
        expose:
          - "5432"
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -d litellm -U llmproxy"]
          interval: 1s
          timeout: 5s
          retries: 10

      prometheus:
        image: prom/prometheus
        container_name: litellm_prometheus
        restart: always
        volumes:
          - ./prometheus:/prometheus
          - ./prometheus.yml:/etc/prometheus/prometheus.yml
        expose:
          - "9090"
        command:
          - "--config.file=/etc/prometheus/prometheus.yml"
          - "--storage.tsdb.path=/prometheus"
          - "--storage.tsdb.retention.time=15d"

    ```

    Save and close the file.

    This Docker Compose configuration deploys four services behind a single HTTPS endpoint:

    * `traefik`: Acts as the reverse proxy and TLS terminator, listening on ports 80 and 443 and automatically redirecting HTTP traffic to HTTPS using Let's Encrypt.
    * `litellm`: Runs the LiteLLM proxy image pinned to a specific release tag for reproducible deployments, mounting `config.yaml` for model configuration and waiting for PostgreSQL to become healthy before starting. Traefik routes HTTPS traffic for `${DOMAIN}` to port 4000.
    * `db`: Runs PostgreSQL 16 as the persistent backend for virtual keys, spend data, and usage logs. The `./postgres` bind mount persists the database files across container restarts.
    * `prometheus`: Scrapes LiteLLM metrics from port 4000 every 15 seconds and stores time-series data in the `./prometheus` bind mount with a 15-day retention window.

    The volumes configuration mounts the `./postgres` and `./prometheus` host directories into the `db` and `prometheus` containers, allowing their data to persist across container removal or recreation.

### Verify the Docker Image with Cosign

LiteLLM Docker images published to GitHub Container Registry are signed with [Cosign](https://docs.sigstore.dev/quickstart/quickstart-cosign/). Verifying the image signature confirms that the specified image was signed with the LiteLLM signing key.

1. Download and install the Cosign binary.

    ```console
    $ curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64"
    ```

1. Move the binary into your system path.

    ```console
    $ sudo mv cosign-linux-amd64 /usr/local/bin/cosign
    ```

1. Make the binary executable.

    ```console
    $ sudo chmod +x /usr/local/bin/cosign
    ```

1. Verify the installation.

    ```console
    $ cosign version
    ```

    The output displays the installed Cosign version, confirming the binary is available in your system path.

1. Verify the LiteLLM image signature using the pinned public key. This checks the same release tag deployed in the Docker Compose file in the next step. LiteLLM publishes signatures for the `ghcr.io` registry specifically, so this confirms the `v1.89.1` release itself, not the `docker.litellm.ai` mirror byte-for-byte.

    ```console
    $ cosign verify \
        --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \
        ghcr.io/berriai/litellm:v1.89.1
    ```

    A successful verification outputs a JSON payload confirming the image was signed with the LiteLLM public key. If verification fails, confirm you copied the key URL and image tag, then run the command again.

### Start the Stack

With the configuration files and images in place, bring up the full deployment.

1. Start the services.

    ```console
    $ docker compose up -d
    ```

1. Verify all containers are running.

    ```console
    $ docker compose ps
    ```

    Verify that all four containers show an `Up` status, with `litellm` and `db` marked `(healthy)` and `traefik` listing ports 80 and 443 under `PORTS`.

    > [!NOTE]
    > For more information on managing a Docker Compose stack, see the [How to Use Docker Compose](https://docs.vultr.com/how-to-use-docker-compose) article.

## Access and Configure LiteLLM

LiteLLM exposes a web-based admin dashboard at the `/ui` path of your configured domain. The dashboard provides visibility into model configuration, virtual keys, usage, and spend tracking.

1. Open a web browser and navigate to `https://litellm.example.com/ui`. Replace `litellm.example.com` with your configured domain.

    ![LiteLLM Login Page](https://lhr1.vultrobjects.com/docs-main-doc-assets-1/2669/bf725284-afea-451e-ba0e-6d7492185224.png)

1. Log in using the credentials from your `.env` file. Enter the value of `UI_USERNAME` in the **Username** field and the value of `UI_PASSWORD` in the **Password** field, then click **Login**. Verify that the dashboard loads and displays the main navigation panels.

    ![LiteLLM Dashboard](https://lhr1.vultrobjects.com/docs-main-doc-assets-1/2669/34064d64-9aa8-44d3-b4ff-ecffd321dc7a.png)

1. Click **Models + Endpoints** in the left sidebar to verify the configured model providers. The model defined in `config.yaml` appears in the list with its alias and underlying provider model.

    ![LiteLLM Models Page](https://lhr1.vultrobjects.com/docs-main-doc-assets-1/2669/b8426009-dc3b-4018-8a0b-f0a11a7a844b.png)

    The Model Management page lists all configured model aliases and their underlying providers. The left sidebar also provides access to **Virtual Keys** for managing scoped access credentials, **Usage** for per-model and per-key request tracking, and **Logs** for spend and cost breakdowns by model, key, and team.

## Test the Gateway and Create a Virtual Key

LiteLLM exposes an OpenAI-compatible API, so any application built for the OpenAI SDK works with LiteLLM by pointing `base_url` at the gateway. Virtual keys provide scoped, credential-isolated access without exposing the master key. Each key carries its own model access list, budget limit, and rate limit.

1. Install the Python virtual environment package.

    ```console
    $ sudo apt install -y python3-venv
    ```

1. Create a Python virtual environment.

    ```console
    $ python3 -m venv litellm-env
    ```

1. Activate the virtual environment.

    ```console
    $ source litellm-env/bin/activate
    ```

1. Install the OpenAI Python SDK.

    ```console
    $ pip install openai
    ```

1. Export your master key as an environment variable. Replace `sk-YOUR_MASTER_KEY` with the `LITELLM_MASTER_KEY` value from your `.env` file.

    ```console
    $ export LITELLM_MASTER_KEY="sk-YOUR_MASTER_KEY"
    ```

1. Export your gateway domain as an environment variable. Replace `litellm.example.com` with your configured domain.

    ```console
    $ export LITELLM_DOMAIN="litellm.example.com"
    ```

1. Create the test script.

    ```console
    $ nano test_litellm.py
    ```

1. Add the following contents, replacing `my-model` with the model name you set in `config.yaml`:

    ```python
    import os
    from openai import OpenAI

    client = OpenAI(
        api_key=os.environ["LITELLM_MASTER_KEY"],
        base_url=f"https://{os.environ['LITELLM_DOMAIN']}",
    )

    response = client.chat.completions.create(
        model="my-model",
        messages=[{"role": "user", "content": "What is an AI gateway?"}],
    )

    print(response.choices[0].message.content)
    ```

    Save and close the file.

1. Run the script.

    ```console
    $ python3 test_litellm.py
    ```

    The script returns a response from the configured LLM provider, confirming that the gateway routes requests correctly.

1. Create a virtual key using the LiteLLM API. Replace `my-model` with the model name you set in `config.yaml`.

    ```console
    $ curl -X POST "https://${LITELLM_DOMAIN}/key/generate" \
        -H "Authorization: Bearer ${LITELLM_MASTER_KEY}" \
        -H "Content-Type: application/json" \
        -d '{"key_alias": "test-app-key", "models": ["my-model"], "max_budget": 5.00}' \
        | python3 -c "import sys, json; print(json.load(sys.stdin)['key'])"
    ```

    The command prints the generated virtual key, similar to `sk-M9M0_aUDLi7AuhXtOAw6uw`. Virtual keys let you issue scoped credentials to individual users or applications without exposing the master key. Each key can have its own model access list, budget limit, and rate limit.

1. Export the virtual key returned in the previous step. Replace `sk-your-virtual-key` with the full key string printed by the previous command.

    ```console
    $ export LITELLM_VIRTUAL_KEY="sk-your-virtual-key"
    ```

1. Send a request using the virtual key. Replace `my-model` with the model name you set in `config.yaml`.

    ```console
    $ curl -X POST "https://${LITELLM_DOMAIN}/v1/chat/completions" \
        -H "Authorization: Bearer ${LITELLM_VIRTUAL_KEY}" \
        -H "Content-Type: application/json" \
        -d '{
          "model": "my-model",
          "messages": [{"role": "user", "content": "Hello from a virtual key!"}]
        }'
    ```

    The gateway authenticates the virtual key, routes the request to the configured provider, and returns the model response.

1. Return to the dashboard at `https://litellm.example.com/ui` and click **Logs** in the left sidebar.

    ![LiteLLM Logs Page](https://lhr1.vultrobjects.com/docs-main-doc-assets-1/2669/a056803c-4bce-4484-85a7-f091205a5d6f.png)

    Each entry shows the model alias, key alias, token count, and estimated cost for the requests sent through both the master key and the virtual key.

## Conclusion

You have deployed LiteLLM on a Linux server using Docker Compose with PostgreSQL for persistent storage, Prometheus for authenticated metrics collection, and Traefik for automatic HTTPS through Let's Encrypt. The deployment provides a fully functional, OpenAI-compatible AI gateway accessible over a custom domain, with virtual key management, spend tracking, and provider routing configured. For more information, refer to the [official LiteLLM documentation](https://docs.litellm.ai/docs/).
