---
title: "Token flow"
url: "/docs/proxy/lens/profiles/token-flow"
canonical_url: "https://docs.litellm.ai/docs/proxy/lens/profiles/token-flow"
type: "docs"
last_updated: "2026-12-02"
summary: "Turn on work types for an agent, then follow its tokens or cost from the total through work type and model to completed or errored requests."
related:
  - "/docs/proxy/lens/profiles"
  - "/docs/proxy/lens/slack"
---
# Token flow

> Index of all LiteLLM docs: https://docs.litellm.ai/llms.txt


Token flow answers one question for an agent: where did the tokens go. It draws usage left to right, from the total, through the work type each request belongs to and the model deployment that served it, to whether the request completed or errored. This page walks through turning it on, reading the diagram, and drilling into the runs behind it

![Token flow for the support agent, with the total flowing into eight work types, then three models, then completed or errored outcomes](/img/lens/token-flow-demo.png)

*Demo data from the Lens UI preview*

## Before you start

You need [recorded agent traces](./first-trace.md) for the agent. Turning on work types also needs a proxy administrator and one chat model on the connected LiteLLM gateway, which Lens uses to classify runs. No discovery or embedding model is required

If the agent already has recorded or discovered categories in [Profiles](./profiles.md), skip to [Read the diagram](#read-the-diagram); Token flow uses those categories as its work types

## Turn it on

Open **Profiles**, select the agent, and choose a time range. Select the **Token flow** tab, then choose **Enable with defaults**

![The Token flow tab before setup, with Enable with defaults and Customize](/img/lens/token-flow-setup.png)

**Enable with defaults** 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 line under the buttons names the model that will classify

To start from your own list instead, choose **Customize** before enabling. Rename or reword any work type, remove the ones that do not apply, use **Add work type** for new ones, pick the **Classification model**, then choose **Enable token flow**. The descriptions are what the model reads when it sorts a run, so write them as a plain statement of what belongs there

![The Customize form, with a name and description for each work type and the classification model](/img/lens/token-flow-customize.png)

Lens classifies each new run from the first 1,500 characters of its first request. That text is sent to the classification model through your gateway and incurs provider charges. Runs from before you enabled stay **Unclassified**, and runs waiting for a result are counted as pending, so the diagram fills in as new traffic arrives

## Read the diagram

Read the columns left to right: **Total**, **Work type**, **Model**, **Outcome**. Each column lists its largest entry first, and the width of a band is its share of the total. The cards above the diagram give total tokens, known spend, requests, and the completed share for the same selection

Hover a node or a band to highlight every path that runs through it. Hovering a work type shows which models served it and how much of it errored; hovering **Errored** shows which work types and models the failures came from

The table under the diagram lists each work type with its share, input tokens, output tokens, requests, and errored share. Use it when you need the numbers behind a band

## Switch between tokens and cost

**Measure** switches the diagram between **Tokens**, which is input plus output, and **Cost**, which is the spend the gateway recorded. A work type that uses a cheaper model takes a smaller share by cost than by tokens, so compare both before deciding where to optimize. Requests without a matching billing record add nothing to cost

![Token flow with Measure set to Cost, showing each work type's share of recorded spend](/img/lens/token-flow-cost.png)

## Filter by harness

**Harness** narrows the diagram to one harness, such as a single coding agent, when your traces record it. Choose **All harnesses** to return to the full view. If the selected harness has no usage in the range, the tab says so and offers **Clear harness filter**

## Open the runs behind a work type

Select a work type in the diagram or the table, or one of its bands, to open **Classified runs**. The list shows each matching run with its model, tokens, and cost. Select a run to see what Lens classified it from: the bounded preview of the first user prompt, the tool names, the classifier's confidence, and its rationale, then open its trace to follow the full run

Use this to check a surprising share. If runs land in the wrong work type, choose **Customize work types** and tighten the names and descriptions

## Preview the export

The **Export** tab shows the same usage as one enriched event per request, with its work type, model, outcome, tokens, and cost. Switch between **OTLP logs**, **Webhook**, and **S3** to see the payload for each destination, and download the events as NDJSON to load into an existing dashboard

This is a preview on demo data. Lens does not deliver these events to a destination yet

![The Export tab, with an OTLP log payload for one enriched usage event and the NDJSON download](/img/lens/token-flow-export.png)

## How requests are counted

Token flow counts each gateway request once, even when it was exported more than once, and leaves out requests that belong to another agent or are shared with one. A request is **Errored** when any of its calls ended with an error status; the outcome does not say whether the work was merged, closed, or accepted. Long ranges can be partial, and the tab says so when they are

See the [Token flow reference](https://github.com/BerriAI/lens/blob/main/docs/task-profiles.md#token-flow) for the API routes and counting rules

## Related pages

- [Profiles](https://docs.litellm.ai/docs/proxy/lens/profiles.md)
- [Slack notifications](https://docs.litellm.ai/docs/proxy/lens/slack.md)
