token_count

Extracts token usage from AI inference responses and writes unified counts to [filter_metadata].
On this page

Extracts token usage from AI inference responses and writes unified counts to [filter_metadata].

Configuration Notes

Supports both streaming (SSE) and non-streaming (JSON) responses across five providers (OpenAI, Anthropic, Google, Bedrock Converse, Azure), plus a header-only extraction path for Bedrock InvokeModel.

Configuration

FieldTypeRequiredDescription
provideropenai | anthropic | google | bedrock | bedrock_invoke_model | azureyesAI provider whose response format to parse.
max_body_bytesintegernoMaximum bytes to buffer for a non-streaming JSON response before giving up on locating its usage field. Must be greater than 0 and at most 64 MiB.
max_scratch_bytesintegernoMaximum scratch bytes (buffered line + in-progress event data) for the SSE scanner before an event is discarded as oversized. Must be greater than 0 and at most 64 MiB.

Example

filter: token_count
provider: openai   # openai | anthropic | google | bedrock | bedrock_invoke_model | azure
max_body_bytes: 1048576    # optional, JSON capture limit
max_scratch_bytes: 1048576 # optional, SSE per-event capture limit; must fit
                           # the largest usage event (Responses-API
                           # response.completed embeds the full response)