Skip to main content

LiteLLM Lens

Early access

Agent swarms flow through the LiteLLM gateway into one trace per run, and LiteLLM Lens feeds improvements back.

Once your agents are in production, you cannot manually review every trace.

LiteLLM Lens uses AI agents to analyze your agent traces and find recurring problems. You specify the expected behavior. Lens investigates failures, groups similar problems, and links each finding to the original traces.

Use Lens > Traces to manually inspect individual runs. Use Lens > Investigations to investigate a set of runs, on demand or on a schedule.

Deployment​

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

Lens adds two things to your LiteLLM stack: ClickHouse and the Lens worker. PostgreSQL is the same database your proxy already uses.

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, deploy/lens/compose.yaml
PostgreSQLStores lenses, findings, and keysYour existing LiteLLM database

One-click Docker​

For a new deployment, the tracing Docker Compose stack starts LiteLLM, PostgreSQL, and ClickHouse together:

git clone https://github.com/BerriAI/litellm.git
cd litellm/docker
export OPENAI_API_KEY=sk-...
docker compose -f docker-compose.tracing.yml up --build

Open http://localhost:4002/ui/ and sign in with username admin and password local-tracing-master-key. Then connect the analyzer to start the Lens worker.

For an existing proxy, deploy ClickHouse where the proxy can reach it, then enable tracing on your proxy. In the examples below, replace https://<your-litellm-proxy> with your LiteLLM proxy URL.

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

1. If a LiteLLM proxy is already running, keep it and its PostgreSQL database. Otherwise clone https://github.com/BerriAI/litellm and start docker/docker-compose.tracing.yml, which runs LiteLLM, PostgreSQL, and ClickHouse.
2. For an existing proxy, run ClickHouse (clickhouse/clickhouse-server:26.9.6.6) where the proxy can reach it. Add general_settings.tracing.store: clickhouse to the proxy config, set CLICKHOUSE_URL (and optionally a SELECT-only CLICKHOUSE_READER_URL), and restart the proxy.
3. Check tracing works: POST an OTLP/HTTP trace to <proxy>/v1/traces with Authorization: Bearer <key>, then GET <proxy>/v1/traces and confirm it is listed.
4. Ask me to open the dashboard, go to Observability > Lens > Investigations > Connect worker, and paste the generated worker command. Run it, or use https://github.com/BerriAI/litellm/blob/main/deploy/lens/compose.yaml with LITELLM_URL and LENS_WORKER_TOKEN.
5. Confirm the dashboard shows "Worker connected".

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

Docker deployment​

Use these steps to add Lens to a LiteLLM proxy you already run. If you don't have one yet, follow the Docker quick start or production deployment guide first. Lens also needs the PostgreSQL database configured through DATABASE_URL.

1. Deploy ClickHouse​

Run ClickHouse where your proxy can reach port 8123:

docker run -d --name litellm-clickhouse --restart unless-stopped \
-e CLICKHOUSE_USER=default \
-e CLICKHOUSE_PASSWORD=<clickhouse-password> \
-e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
-v clickhouse_data:/var/lib/clickhouse \
-p 8123:8123 \
clickhouse/clickhouse-server:26.9.6.6

The URL your proxy needs is http://default:<clickhouse-password>@<clickhouse-host>:8123. LiteLLM creates the litellm database and tables on startup.

2. Point LiteLLM at ClickHouse​

Add this to your proxy's config.yaml:

general_settings:
tracing:
store: clickhouse

Set these environment variables on the proxy, then restart it:

VariableValue
CLICKHOUSE_URLhttp://default:<clickhouse-password>@<clickhouse-host>:8123
CLICKHOUSE_READER_URLOptional. A SELECT-only ClickHouse user, same URL format. Defaults to CLICKHOUSE_URL
CLICKHOUSE_DATABASEOptional. Defaults to litellm

Check that tracing is on: curl -H "Authorization: Bearer <your-litellm-key>" https://<your-litellm-proxy>/v1/traces returns {"data": [...]}.

3. Deploy the Lens worker​

Open https://<your-litellm-proxy>/ui/, go to Observability > Lens > Investigations, click Connect worker, choose the analysis model and monthly limit, then Get install command. Run the generated command on any server that can reach your proxy over HTTPS. It looks like this:

docker run -d --restart unless-stopped --read-only --cap-drop ALL \
--tmpfs /tmp:rw,noexec,nosuid,size=1g \
--security-opt no-new-privileges --platform linux/amd64 --add-host host.docker.internal:host-gateway \
-e LITELLM_URL=https://<your-litellm-proxy> \
-e LENS_WORKER_TOKEN=<worker-token-from-the-dashboard> \
ghcr.io/berriai/litellm-lens-worker@sha256:a8e8731d954916594eea462969946b9292fb771681ff515a9fd296b53f856c77
VariableValue
LITELLM_URLYour proxy's base URL, without /v1, for example https://litellm.example.com. Use http://host.docker.internal:4000 if the proxy runs on the same machine
LENS_WORKER_TOKENThe worker token from Get install command. Keep it private

The worker needs outbound access to LITELLM_URL only. It needs no inbound ports, provider keys, or database access. Use deploy/lens/compose.yaml instead if you manage containers with Compose. The dashboard shows Worker connected once the worker checks in.

Connect your agent​

Point your agent's OpenTelemetry OTLP/HTTP exporter to LiteLLM:

SettingValue
Trace endpointhttps://<your-litellm-proxy>/v1/traces
HTTP headerAuthorization: Bearer <your-litellm-key>

Use a LiteLLM key to authenticate. Record the agent's task, steps, tool calls, inputs, and final answer. Lens uses this content to check what happened.

For a working example, use DeepLite. Set LITELLM_DEV_BASE=https://<your-litellm-proxy>/v1/traces and LITELLM_DEV_KEY=<your-litellm-key> in its .env file, then run the agent.

Send your first trace​

Use your existing model and tracing setup. Choose your framework below; replace research_agent with your agent's name.

from deepagents import create_deep_agent

agent = create_deep_agent(name="research_agent", model=model, tools=[])
result = agent.invoke({"messages": [{"role": "user", "content": "What is an agent trace?"}]})
print(result["messages"][-1].content)

View your first trace​

Open Lens > Traces. Select a time range that includes your run, then open it. For the examples above, look for research_agent. Select a step to read its input, output, and attributes.

A research_agent trace with its question, model call, and final answer.

Check that you can see the task, tool results, and final answer. If these are missing, update your agent's instrumentation before running an investigation.

Run your first investigation​

Connect the analyzer​

Sign in as a proxy administrator and open Lens > Investigations under Observability. Once activity is available, click Connect worker. Choose an Analysis model and a Monthly limit, then click Get install command. The default limit is $100 per month. This creates a virtual key restricted to your chosen model; analysis spend appears under that key in Virtual Keys. To use an existing virtual key or change the proxy URL, open Advanced options. Existing workers can change their virtual key through the worker's Settings without replacing their worker token.

Run the Docker command on a server that can reach your LiteLLM deployment. Keep the command private because it contains the worker token. Wait for Worker connected. Investigation creation unlocks when the worker is ready.

Lens worker setup with an analysis model and a monthly limit.

This worker runs on your infrastructure. It checks LiteLLM for scheduled or requested investigations and sends the results back. It calls your chosen model through LiteLLM and keeps running when you close the dashboard.

Choose the traces​

Click New investigation. In Activity, name the investigation and choose an Agent. The dropdown lists recorded agent names; leave it blank to include all accessible activity. Open Advanced filters to choose agent traces, LLM requests, or both, restrict the selection to a team, or add metadata conditions. Request analysis uses the request logs stored in ClickHouse. Metadata conditions match recorded keys and values exactly.

Describe what to check​

Click Continue to open Expectations. Describe what your agent should do in What should the agent be doing?.

For example:

The research agent answers the user's question with sources. It checks the sources before writing the final answer and states when it cannot verify a claim.

Under What should we look out for?, use Add check to add questions you want Lens to answer. Expected behavior is checked even when you leave these blank. You can edit the suggested questions or write your own:

Find claims that conflict with the retrieved sources.
Find tool failures that the agent does not recover from.
Find repeated searches that add no new information.

After setup, you can review these under Criteria and change them through Edit investigation in the actions menu.

Expected behavior and individual checks for an investigation.

Start the run​

Click Continue to open Run. Set the time window and percentage of matching runs to analyze. By default, Lens reviews 100% of matching activity from the last day, with no count limit. The preview shows how many runs match and how many will be analyzed. Click Open run to inspect an example. Newly received traces need a two-minute settling period before they appear here.

Lens uses the worker's analysis model by default. To change the model, set a maximum number of runs, or change the monthly limit, open Advanced options. Trace content goes to the selected model through LiteLLM.

Click Run investigation to run once. For monitoring, enable Repeat this investigation in Advanced options, set Repeat every to the interval you want, then click Run and monitor.

Lens reviews the selected runs in parallel, groups similar observations, and checks the original evidence before saving findings.

Use Run now to start another investigation with the saved settings. Scheduled investigations use those same settings. Use Duplicate in the actions menu to ask a one-off question or investigate a different selection without changing the original lens. Use Pause monitoring to stop scheduled investigations.

Read the findings​

Open Findings when the investigation finishes. Needs attention shows problems, ordered by priority. Patterns shows other observations, including successful recovery and useful behavior.

Open a finding to read what happened and the suggested next step. Expand Evidence by run to read the quotes. Click Open original step to see the cited step in its trace.

An example finding with a suggested next step and supporting evidence.

Use History to return to a previous run and its findings, settings, progress, total duration, and cost. Duration includes any wait for a worker. Traces shows the activity selected for that run; this tab is called Requests or Traces & requests when those activity types are selected.

Findings describe the reviewed sample. Linked runs counts cited supporting runs; it is not a count of all failures. Evidence can also include labeled counterexamples.

Give feedback​

If Lens flags expected behavior, explain why in Feedback and click This is expected. Lens uses that feedback in later investigations for the same lens.

After you fix an issue, click Mark resolved. Lens can reopen it if the same issue appears in new runs.

Configure an existing proxy​

Add this to config.yaml:

general_settings:
tracing:
store: 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.

Agent tracing API​

All four endpoints require proxy authentication. Send a proxy key in the Authorization: Bearer <key> header.

EndpointPurpose
POST /v1/tracesIngest OTLP/HTTP traces as protobuf (application/x-protobuf) or JSON (application/json). Supports gzip with Content-Encoding: gzip.
GET /v1/tracesList trace summaries. Optional start_ms and end_ms are Unix milliseconds. The default window is the last 24 hours.
GET /v1/traces/{trace_id}Read the trace's summary, agents, and spans. Accepts optional trace_ref.
GET /v1/traces/{trace_id}/spans/{span_id}Read a span's input, output, and attributes. Accepts optional trace_ref.

List responses contain data and next_cursor, with 50 summaries per page by default. Pass next_cursor back as cursor to read the next page. Use a summary's trace_ref when reading the trace or its spans.

curl -H "Authorization: Bearer <key>" \
"https://<your-litellm-proxy>/v1/traces"

Proxy administrators can read all traces. Team keys can read their team's traces. Keys without a team can read traces sent with that key. Read-only proxy administrators cannot ingest traces.

Lens API​

Start investigations and read findings on your LiteLLM proxy. Send a proxy administrator key in the Authorization: Bearer <key> header.

EndpointPurpose
GET /lensList investigations under lenses, plus workers and tracing_enabled.
POST /lensCreate an investigation and queue its first run. Send name, model, and context or checks; returns the investigation id and jobs.
GET /lens/{id}Read saved settings, recent jobs, and findings. Each job includes status, stage, coverage, and cost.
POST /lens/{id}/runsQueue another run. Send {} to reuse saved settings, or a settings object for a one-time override.
curl -H "Authorization: Bearer <key>" \
"https://<your-litellm-proxy>/lens"

Read-only proxy administrators can preview activity and read investigations, findings, and history. Team and ordinary virtual keys cannot use this API.