Skip to main content

Lens Token Flow: see what your agents' tokens are for

Lens Token Flow: see what your agents' tokens are for

Here are 100 million tokens. What were they for?

Spend dashboards answer which key, team, or model used the tokens. Leadership usually asks a different question: how much went to feature work, how much to troubleshooting, how much to incidents, and how much of that ended in an error. Answering it has meant exporting full session logs, truncating hundreds of megabytes of prompts, and writing a classifier.

Token flow is a new tab in Lens Profiles that answers it from the traces Lens already has. It follows an agent's tokens left to right: the total, the work type each request belongs to, the model that served it, and whether the request completed or errored.

Token flow ships in the next Lens release after v0.8.0. Lens releases independently of LiteLLM, so it needs no LiteLLM upgrade beyond a gateway that already runs Lens.

Token flow in Lens Profiles: the total flows into eight work types, then three models, then completed or errored outcomes

Demo data from the Lens UI preview

One click to turn it on​

Open Profiles, select an agent, and switch to Token flow. If the agent has no categories yet, choose Enable with defaults. Lens creates eight work types and starts classifying new runs: coding and feature work, troubleshooting, bug fixes, incident remediation, Slack responses, data analysis, presentations and documentation, and admin work.

The Token flow tab before setup, with Enable with defaults and Customize

The defaults are a starting point. Customize lets you rename, remove, or add work types and choose the classification model before you enable, and Customize work types edits them afterwards. Agents that already record a task_category, or that have discovered categories, use those and need no setup.

Setup needs a proxy administrator and one chat model on your gateway. It does not need an embedding model or a discovery run.

No session export to truncate​

Lens classifies a run from the first 1,500 characters of its first request. That preview is enough to tell a bug fix from a slide deck, and it keeps classification cost small and predictable no matter how long the session grows. The full prompts and responses stay where they are.

Read the diagram​

The width of each band is input plus output tokens, and hovering a node or a band highlights every path that runs through it. Measure switches the whole diagram from tokens to the spend the gateway recorded, and Harness narrows it to one harness when your traces record it. Select a work type or one of its bands to open the runs behind it, with the input preview and tool names Lens classified them from. In the screenshot, coding and feature work takes 50% of 99.9M tokens across three models, and incident remediation is 4.5% of tokens with 14% of them spent on errored requests. The table under the diagram gives each work type's share, input tokens, output tokens, requests, and errored share, so the numbers can go straight into a review.

Token flow uses the same counting rules as the rest of Profiles. Each gateway request counts once even when it was exported more than once, requests that belong to another agent are left out, and a request retried across deployments appears under multiple deployments. A request is errored when any of its calls ended with an error status. That is a trace outcome; it does not yet say whether a pull request merged or an incident closed.

What comes next​

This first version works per agent. Next are one set of work types shared across every agent, cache tokens as their own bands, and delivery outcomes such as merged pull requests. The new Export tab previews this usage as one enriched event per request in OTLP, webhook, and S3 form; delivering those events to a destination is not built yet.

Follow the Token flow walkthrough and the Token flow reference to get started.