Skip to main content

Add Lens to LiteLLM

Traffic you send through the gateway shows up in Lens as traces with cost when your app or agent has the OpenTelemetry (OTel) environment variables set. Follow the app tracing or coding-agent setup. Lens also opens from the LiteLLM sidebar with your LiteLLM login.

You need LiteLLM v1.108.0 or later, a running Lens, and access to the environment settings of both. Gateway admins become Lens admins, so connect only a gateway you trust.

1. Get the Lens address​

If Lens already runs, use its existing URL and continue to step 2. For example, a Render service uses its public HTTPS URL. Use the application URL, not the Render dashboard URL.

If you have not installed Lens, complete the standalone quickstart, server setup, or Helm setup first. Then return here.

Check that Lens is ready. Replace the example URL with yours:

curl --fail https://lens.example.com/health/ready

Expect HTTP 200. The gateway must also be able to reach this service. A gateway container cannot use localhost to reach Lens in another container or on another host.

2. Create the two connection secrets​

If Lens already connects to a gateway, reuse its existing LITELLM_LENS_SERVICE_TOKEN and LENS_GATEWAY_SECRET. Do not rotate them as part of adding this connection.

For a new connection, generate two different secrets in a private terminal:

openssl rand -hex 32
openssl rand -hex 32

Save the first as LITELLM_LENS_SERVICE_TOKEN and the second as LENS_GATEWAY_SECRET in your secret manager. You will give both services the same pair of values.

ValuePurpose
LITELLM_LENS_SERVICE_TOKENAuthenticates internal requests from LiteLLM to Lens
LENS_GATEWAY_SECRETLets Lens verify the user identity sent by LiteLLM

These are separate from the Lens admin token, agent tracing keys, and LiteLLM model keys. Do not put their values in Git, browser code, or shared logs.

3. Add the secrets to Lens​

Add these environment variables to the existing Lens service:

LITELLM_LENS_SERVICE_TOKEN=YOUR_SERVICE_SECRET
LENS_GATEWAY_SECRET=YOUR_SIGNING_SECRET

Replace each placeholder with its value from step 2. Keep the other Lens settings unchanged.

Open your Lens service in the Render dashboard. Select Environment, add the two variables, then save and redeploy the service. Wait for the deployment to become Live.

Repeat the readiness check from step 1 after the deployment finishes.

4. Configure LiteLLM​

Add these variables to the LiteLLM service. In a split gateway/backend deployment, supply them to both services:

LITELLM_LENS_URL=https://lens.example.com
LITELLM_LENS_PUBLIC_URL=https://lens.example.com
LITELLM_LENS_SERVICE_TOKEN=YOUR_SERVICE_SECRET
LENS_GATEWAY_SECRET=YOUR_SIGNING_SECRET

Use your Lens URL and the same two secrets from step 2. Neither URL ends in /ui/ or /v1/traces.

LITELLM_LENS_URL is the address the gateway calls. LITELLM_LENS_PUBLIC_URL is the address shown to agent exporters. They can be the same HTTPS URL. If you use a private address for the first value, the second must still be reachable by your agents.

For Kubernetes, use the private Lens Service address for the gateway connection and a reachable HTTPS origin for exporters

Setting LITELLM_LENS_URL turns on the Lens connection, so a gateway without a config.yaml, such as the Docker quickstart, needs no other change. If your gateway has a config.yaml, you can also state the store there. Preserve its model list and other settings:

general_settings:
tracing:
store:
type: lens

Apply the change through your normal gateway deployment

Helm​

The LiteLLM chart sets the four variables from its values. Add these to the gateway's values.yaml, keep its other settings, and upgrade the release. The chart does not install Lens:

values.yaml
lens:
enabled: true
url: http://lens.lens.svc.cluster.local:4318
publicUrl: https://lens.example.com
gatewaySecret:
name: lens-connection
serviceTokenSecret:
name: lens-connection
gateway:
config:
proxy_config:
general_settings:
tracing:
store:
type: lens

lens.url is the private Service address, http://<release>.<namespace>.svc.cluster.local:4318. lens.publicUrl is the Lens ingress address

Docker Compose​

Lens publishes port 4318 on the host's 127.0.0.1 only, which a gateway container cannot reach. When both run on the same Docker host, attach the gateway to the network Lens already created, lens_default. Lens then answers at http://lens:4318 from the gateway container, and the Lens Compose file stays unchanged. Check that the network exists:

docker network inspect lens_default --format '{{.Name}}'

In your gateway's Compose directory, save the four variables above in lens-gateway.env with LITELLM_LENS_URL=http://lens:4318. Keep the public URL reachable by agents. Keep the file out of Git and restrict access with chmod 600 lens-gateway.env.

Add the file and the network to the existing gateway service in its Compose file, such as docker-compose.quickstart.yml from the Docker quickstart. Preserve its other env_file and networks entries, and keep default so the gateway still reaches its database:

services:
litellm:
env_file:
- lens-gateway.env
networks: [default, lens]

networks:
lens:
name: lens_default
external: true

For a gateway on another host or a different network layout, see Docker networking.

Explicit environment entries override env_file; update any existing definitions of the four variables so they agree. For a split deployment, add the file to both gateway and backend/API services. Keep your existing database, volumes and model configuration.

Recreate the gateway to load the settings. Replace litellm with your service name (docker compose config --services lists them), and include the backend service if separate:

docker compose up -d --no-deps litellm

Keep your usual Compose file and project flags. This restarts the selected services and can interrupt requests. Continue with the connection check below.

5. Open Lens in the gateway​

Sign in to your LiteLLM dashboard as a gateway administrator and select Lens in the sidebar. The connected Lens workspace opens on Traces. You should not be asked for the standalone Lens admin token.

If the service is connected but has no traces, select Home in Lens and follow Send your first trace from there. Creating the tracing key here applies the gateway user's access scope. Existing standalone traces are not reassigned to a different user or team when you connect the gateway.

Make one normal model request through your gateway to check that its existing model connection still works. Lens setup does not require changing the model endpoint or model keys used by your agents.

If the connection does not work​

What you seeWhat to check
Lens still shows installation instructionsConfirm that all four gateway variables reached the running service, then check its version.
Lens is configured but unavailableCheck /health/ready, gateway-to-Lens network access, and that both secrets match.
You can open Lens but cannot send tracesCheck the public ingestion URL and use an agent tracing key, not either connection secret.
An existing trace is absent for one userCheck the tracing key's user/team scope. Use an administrator account to inspect the workspace.

For an API connection check, call GET /lens/service on the gateway with a LiteLLM administrator credential. A ready connection reports connected: true, status.storage_ready: true, status.credentials_ready: true, and status.public_contract: 1. Keep that credential private. On the LiteLLM Helm chart, send this request through the ingress or to the backend Service; the gateway Service returns 404 for this path.

Optional: For help adapting these steps to your deployment, copy the existing LiteLLM setup prompt into your coding agent. Tell it that Lens already runs and give it the service URL. Share secrets through your secret manager.