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.
| Value | Purpose |
|---|---|
LITELLM_LENS_SERVICE_TOKEN | Authenticates internal requests from LiteLLM to Lens |
LENS_GATEWAY_SECRET | Lets 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.
- Render
- Docker Compose
- Helm or another platform
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.
Add the two variables to deploy/lens/.env in your extracted Lens bundle. From the lens-0.1.0 directory, apply them:
docker compose -f deploy/lens/compose.yaml up -d --wait
Helm. Create one Secret with both values in the Lens namespace and in the gateway namespace. A Secret reference cannot cross namespaces:
SERVICE_TOKEN=$(openssl rand -hex 32)
GATEWAY_SECRET=$(openssl rand -hex 32)
for namespace in lens litellm; do
kubectl --namespace "$namespace" create secret generic lens-connection \
--from-literal=service-token="$SERVICE_TOKEN" \
--from-literal=gateway-secret="$GATEWAY_SECRET"
done
Add these values to the Lens values.yaml and run its install command again:
gateway:
enabled: true
secretName: lens-connection
serviceTokenSecret:
name: lens-connection
Another platform. Add the two variables through the Lens service's environment settings, then redeploy it
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
Merge this block into the gateway's existing config.yaml. 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:
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
In your gateway's Compose directory, save the four variables above in lens-gateway.env. Keep it out of Git and restrict access with chmod 600 lens-gateway.env. On a shared Docker network, the private LITELLM_LENS_URL can be http://lens:4318; keep the public URL reachable by agents. See Docker networking.
Add the file to the existing gateway service, preserving its other env_file entries:
services:
litellm:
env_file:
- lens-gateway.env
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. You should see the connected Lens workspace or its first-trace setup page. You should not be asked for the standalone Lens admin token.
If the service is connected but has no traces, follow Send your first trace from this embedded page. 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 see | What to check |
|---|---|
| Lens still shows installation instructions | Confirm that all four gateway variables reached the running service, then check its version. |
| Lens is configured but unavailable | Check /health/ready, gateway-to-Lens network access, and that both secrets match. |
| You can open Lens but cannot send traces | Check the public ingestion URL and use an agent tracing key, not either connection secret. |
| An existing trace is absent for one user | Check 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.
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.