> ## Documentation Index
> Fetch the complete documentation index at: https://ancplua.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AL0065 - Use gen_ai.client.token.usage histogram

> Token metrics should use the standard histogram

Source: [Al0065UseTokenUsageHistogramAnalyzer.cs](https://github.com/ANcpLua/ANcpLua.Analyzers/blob/main/src/ANcpLua.Analyzers/Analyzers/Al0065UseTokenUsageHistogramAnalyzer.cs)

## Description

Token usage metrics should use the `gen_ai.client.token.usage` histogram name defined in OpenTelemetry GenAI semantic conventions.

## Bad Code

```csharp theme={null}
var counter = meter.CreateCounter<long>("token_count");
counter.Add(response.Usage.TotalTokens);
```

## Good Code

```csharp theme={null}
var histogram = meter.CreateHistogram<long>("gen_ai.client.token.usage");
histogram.Record(response.Usage.TotalTokens,
    new("gen_ai.token.type", "total"));
```

## Properties

* **Category**: GenAI
* **Severity**: Warning
* **Enabled by default**: True
* **Code fix available**: False

## Configuration

```editorconfig theme={null}
dotnet_diagnostic.AL0065.severity = warning
```
