Skip to main content

Deployment

Set up Lens​

Lens runs alongside LiteLLM. The worker investigates recorded activity, ClickHouse stores traces, and PostgreSQL stores findings and settings. The worker only needs access to LiteLLM, with no provider keys or database credentials

LiteLLM Lens architecture: your agent sends LLM calls and traces to LiteLLM, which stores traces in ClickHouse; the Lens worker polls LiteLLM for investigations.

ComponentWhat it doesWhat we use
LiteLLM proxyReceives traces, serves the Lens UI and APIghcr.io/berriai/litellm with tracing enabled
ClickHouse (new)Stores traces and request logsclickhouse/clickhouse-server:26.9.6.6
Lens worker (new)Runs investigations on your infrastructure. It polls LiteLLM over HTTPS and needs no database access or provider keysghcr.io/berriai/litellm-lens-worker-dev, deploy/lens/compose.yaml
PostgreSQLStores lenses, findings, and keysYour existing LiteLLM database, or PostgreSQL from the local tracing stack

Choose your starting point below. New installations can start all four services with Docker Compose. Existing users can keep their deployment and add only the services they need. If Lens is already installed, go to upgrading

Build LiteLLM and its worker from the same source commit and use the same release identity

The existing tracing stack starts LiteLLM, PostgreSQL, and ClickHouse. Build its standalone Lens worker from the same checkout, then connect it through the dashboard

1. Build and start LiteLLM​

Install Docker with Compose and Git. Run:

git clone https://github.com/BerriAI/litellm.git
cd litellm
export LITELLM_RELEASE_TAG="sha-$(git rev-parse HEAD)"
export LENS_WORKER_IMAGE="litellm-lens-worker:${LITELLM_RELEASE_TAG}"
export OPENAI_API_KEY='sk-...'
docker build --build-arg LITELLM_RELEASE_TAG="$LITELLM_RELEASE_TAG" \
-f deploy/lens/Dockerfile -t "$LENS_WORKER_IMAGE" .
export LITELLM_MASTER_KEY="${LITELLM_MASTER_KEY:-sk-$(openssl rand -hex 16)}"
docker compose -f docker/docker-compose.tracing.yml up -d --build

Replace sk-... with your OpenAI key, or configure another provider in docker/tracing-config.yaml before starting. The first build takes several minutes. Both images are built locally from the same checkout

Open http://localhost:4002/ui/ and sign in as admin with your LITELLM_MASTER_KEY

2. Connect the worker​

Go to Lens > Investigations > Connect worker, choose the analysis model and monthly budget, then Get install command. Expand Using Docker Compose or Helm? and copy the worker token

Copy the private worker token for Docker Compose or Helm

In the same terminal, start the worker on the gateway's Docker network:

export LITELLM_URL=http://litellm:4000
export LENS_WORKER_TOKEN='<paste-your-worker-token>'
docker compose -f docker/docker-compose.tracing.yml -f deploy/lens/compose.yaml up -d

When the dashboard shows Worker connected, send your first trace. Keep the token private and save it for restarts and upgrades

This stack is for local evaluation. It binds to localhost and uses development database credentials. For a hosted installation, use your normal ingress, private credentials, and database backups. Preserve both database volumes; do not use docker compose down -v when upgrading

Upgrade LiteLLM and the worker​

You choose when to upgrade. Publishing a new release does not update existing containers. Build LiteLLM and the worker from the same source commit and release identity; PostgreSQL and ClickHouse have their own versions and do not need upgrading with every LiteLLM release

Review the changes, back up your databases, pause scheduled investigations, and let active investigations finish before upgrading. Preserve your configuration, database volumes, master key, salt key, and worker token. Worker setup is performed once; you do not need a new token for each release

For the local tracing stack, stop the worker before changing your source checkout:

docker compose -f docker/docker-compose.tracing.yml -f deploy/lens/compose.yaml stop lens-worker

Select the new source revision and repeat the build commands in New local installation. Keep the same Compose project, database volumes, and saved worker token. Start the worker with both Compose files once the gateway is ready:

docker compose -f docker/docker-compose.tracing.yml -f deploy/lens/compose.yaml up -d

This updates LiteLLM and the worker while retaining the databases. Do not regenerate keys or run down -v

If you added the worker to your own Compose project, update its explicit image together with your gateway image. If Compose manages only the worker, upgrade LiteLLM separately first, update LENS_WORKER_IMAGE, then run docker compose pull and docker compose up -d

After any upgrade, check for Worker connected in the dashboard, run an investigation, and restore any schedules you paused. The gateway checks compatibility before handing out work. An outdated worker waits with an upgrade message, leaving queued investigations untouched; update its image to resume work

Hourly development deployments build the gateway and worker from the same selected commit

For development from source, use make lens-dev. Custom container builds must use the same checkout and release identity for both components; follow the source build instructions. A build without that identity refuses worker setup instead of suggesting an unrelated image

Deploy with a coding agent​

Claude CodeCodex

Paste this into Claude Code or Codex on the machine you want to deploy to.

Show prompt
Deploy LiteLLM Lens on this machine by following https://docs.litellm.ai/docs/proxy/lens/deployment

1. If a LiteLLM proxy is already running, keep it and its PostgreSQL database. Otherwise follow New local installation, building the gateway and worker from the same checkout and release identity.
2. For an existing proxy, configure ClickHouse tracing using the Existing LiteLLM tab. Check POST /v1/traces and GET /v1/traces with a LiteLLM key.
3. Ask me to open Lens > Investigations > Connect worker, select a model and budget, and get a worker token. For the local stack, start the worker with both Compose files. For an existing proxy, confirm its generated command names an available matching image, then run it.
4. Confirm the dashboard shows "Worker connected". Keep LiteLLM and the worker on the same source commit and release identity for future upgrades.

Never print or commit keys, worker tokens, or passwords. Ask me before replacing an existing container, database, or config.

Configure an existing proxy​

Add this to config.yaml:

general_settings:
tracing:
store:
type: clickhouse

Set CLICKHOUSE_URL to the ClickHouse HTTP address your proxy can reach. CLICKHOUSE_DATABASE defaults to litellm. You can set CLICKHOUSE_READER_URL to use a separate read-only account; otherwise reads use CLICKHOUSE_URL.

Investigations also need PostgreSQL, a configured analysis model, and a connected Lens worker. Keep the proxy and worker versions compatible. See the tracing config and worker setup guide for deployment details.

LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →