# Lens (AI) Lens (BerriAI calls it **LiteLLM Lens**) is an [[Open Source]] tracing and investigation platform for [[AI Agents]]. It comes from BerriAI, the company behind [[LiteLLM]]. Lens records every run of your agents, has AI agents review those runs, and reports what went wrong, with a link to the exact step of the trace that shows it. You can run it on its own or open it inside the LiteLLM gateway. The tagline on the README: "Self-improving agents, on your infrastructure." ## Why it exists The launch post (October 1, 2026) starts from agent swarms: hundreds of agents working in parallel, each making model and tool calls, together producing more than 200,000 traces. Nobody reads that many traces by hand. The second argument is about access to the data. Hosted tracing platforms keep your traces in their system, behind rate limits, so you can't point [[Claude Code]] or [[Codex CLI]] at them and let the agent dig in. Lens handles the volume with automated analysis. For access, traces land in a ClickHouse database that you run, next to your gateway, and you query them with plain SQL or through an API. For me, the ownership part matters more. It follows the same logic as LiteLLM itself (see why I like it in [[LiteLLM]]): the data stays on infrastructure you control, and your own coding agents can work with it. ## How it works The launch post describes three steps: 1. **Tell Lens what to look for.** For each agent, you describe what a good run and a bad run look like, and you can add specific questions, one per line. Their example: "Find tool failures the agent does not recover from" 2. **Lens analyzes your traces.** AI agents investigate the runs, group similar problems and show findings per agent: what happened, what to do next, and the runs that support it 3. **Read the findings, then open the trace.** Every finding links back to the exact step, with its input, output and attributes Around that core, the docs list more: - **Investigations**: the analysis runs on a model you configure, and each investigation has its own monthly spending limit - **Alerts**: plain rules (a run takes longer than N minutes, a model call fails) that need no model, plus "signals", where a judge model answers your questions about each trace. Both can notify Slack - **Datasets and evals**: turn traces into datasets, then run evals from a Python SDK, a CLI or a GitHub Action - **Model optimizations**: compare a candidate model with your current one on a share of live traffic, in shadow mode (Lens replays the final model call of sampled traces) or offline on a saved dataset - **Lens CLI**: ranks model and harness combinations (Codex, Claude Code, OpenCode, Pi, Deep Agents or your own agent) by pass rate and estimated cost on your own tasks. It's a private preview; there's no public package yet - **MCP server**: a read-only [[Model Context Protocol (MCP)]] endpoint at `/lens/mcp` with five tools (`list_agents`, `list_traces`, `get_trace`, `get_trace_conversation`, `get_span`). A coding agent can use it to look up its own runs, the tool call that failed and what the run cost Traces arrive over OpenTelemetry (OTLP), authenticated with a tracing key. For Claude Code, the recommended setup is a [[Claude Code Plugins|Claude Code plugin]] from `BerriAI/litellm-lens-plugins`. It turns each session into one trace: every prompt is a turn, every tool call a step, and subagent steps sit under the turn that started them. The plugin needs `python3` and macOS or Linux. Claude Code's own telemetry (off by default) is the fallback, for Windows for example. [[OpenCode]] and Codex have their own guides. ## How it relates to LiteLLM Lens started inside LiteLLM. The launch post told people to deploy it on their LiteLLM gateway, and those early installations kept Lens data in LiteLLM's PostgreSQL database (a `lens-migrate` tool moves it to ClickHouse). On October 8, 2026, BerriAI extracted Lens into its own repository and kept the source history from LiteLLM's main branch. Today the gateway is optional. Standalone Lens needs no gateway, no PostgreSQL and no provider keys to record and browse traces. Connecting an [[AI Gateway]] (the proxy between your code and the model providers) takes environment variables only: `LITELLM_LENS_URL` plus two shared secrets, and no change to LiteLLM's `config.yaml`. What the connection adds: - Lens opens from the LiteLLM sidebar, with your LiteLLM login - Each model call in a trace shows the cost LiteLLM recorded for it. Lens doesn't recalculate prices, so calls that didn't go through the gateway stay unpriced - The gateway stamps traces with the user and team of the key, and the MCP endpoint then returns only the traces that user and their teams may see - Lens can create a dedicated LiteLLM virtual key and use the gateway's models for its own analysis The reasoning is the one BerriAI gives for the gateway: every model call already passes through it, so it's the obvious place to capture what agents do. The [[LiteLLM Agent Control Plane]] from LiteLLM Labs pushed the gateway idea toward agent runtimes; Lens pushes it toward [[AI Observability]] and [[AI Evaluation]]. ## Stack and deployment - **Code**: backend in [[Rust]] (the Rust server now handles every route, and the original Python server is gone), UI in TypeScript, eval SDK in Python - **Storage**: ClickHouse only, for traces and for Lens's own state - **Run it**: with [[Docker]] Compose 2.24 or newer, `docker compose up --wait` pulls `ghcr.io/berriai/lens` and starts Lens plus ClickHouse in under a minute. Lens listens on port 4318, bound to localhost. A [[Helm]] chart covers [[Kubernetes]] - **Limits**: one ClickHouse server, with no distributed tables and no automatic failover. Investigation calculations run in a sandbox that needs a native Linux kernel with Landlock ABI 3 and seccomp ## License and maturity As of November 24, 2026: - **License**: [[MIT License|MIT]], except anything under an `enterprise/` directory, which would fall under its own license. The repository has no such directory today. That header is why the GitHub API doesn't recognize the license - **Repository**: created October 8, 2026. 914 commits, 72 stars, 12 forks, 16 open issues, last push on November 24 - **Releases**: v0.1.0 on November 19, then v0.2.0, v0.3.0 and v0.4.0 by November 23. Four releases in five days - **Contributors**: almost all commits come from accounts with a `-berri` suffix. The two most active have 258 and 195 commits; the Devin AI bot has 100 - **Community**: very little so far. The Hacker News submission of November 23 got 1 point and one comment, from maintainer Moe Khalil asking which tracing products people use. The launch post names one launch partner, MindFort, a company building an autonomous security agent swarm ## My take What I like is the [[Self-hosting|self-hosted]] ownership model: traces in a database you run, readable with SQL, plus an MCP endpoint your coding agent can query. If you already run LiteLLM, adding Lens costs a few environment variables, and you get the gateway's recorded cost on each model call. Before adopting it, keep in mind: - It's v0.x and moves fast (four releases in one week). Pin a release - The analysis calls models, and that costs money. Set the monthly spending limit on each investigation - The Claude Code plugin stores what you type, the replies, and the arguments and output of tools, which can include file contents and secrets. The docs say so explicitly. Only point it at a Lens deployment you control - The CLI that compares models and harnesses isn't public yet For plain self-hosted LLM tracing, [[Langfuse]] has been around much longer. Lens is worth a look when you run LiteLLM already, or when you want the analysis and the MCP access on top of the traces. ## References - GitHub repository and README: https://github.com/BerriAI/lens - Repository metadata via the GitHub API (license, dates, stars, forks, issues, languages, commits, contributors, releases), retrieved 2026-11-24 - License: https://github.com/BerriAI/lens/blob/main/LICENSE - Releases (v0.1.0 to v0.4.0): https://github.com/BerriAI/lens/releases - Pull request #2, "extract Lens into an independent product": https://github.com/BerriAI/lens/pull/2 - Run Lens (deployment guide): https://github.com/BerriAI/lens/blob/main/deploy/lens/README.md - Claude Code setup: https://github.com/BerriAI/lens/blob/main/docs/claude-code.md - MCP server: https://github.com/BerriAI/lens/blob/main/docs/mcp.md - Analysis models: https://github.com/BerriAI/lens/blob/main/docs/analysis.md - Alerts and signals: https://github.com/BerriAI/lens/blob/main/docs/signals.md - Migration from LiteLLM's PostgreSQL: https://github.com/BerriAI/lens/blob/main/docs/migration.md - Historical Rust migration plan: https://github.com/BerriAI/lens/blob/main/docs/rust-migration.md - Launch post "LiteLLM Lens" (October 1, 2026): https://docs.litellm.ai/blog/litellm-lens-launch - Lens CLI walkthrough (preview): https://docs.litellm.ai/docs/proxy/lens/cli - Model optimizations: https://docs.litellm.ai/docs/proxy/lens/model-optimizations - Hacker News submission (November 23, 2026): https://news.ycombinator.com/item?id=50619283 ## Related - [[LiteLLM]] - [[AI Observability]] - [[AI Evaluation]] - [[AI Gateway]] - [[LiteLLM Agent Control Plane]] - [[Langfuse]] - [[Helicone]] - [[LangSmith]] - [[Claude Code]] - [[Self-hosting]]