Usage normalization across providers.
Honesty rule: cache / reasoning / citation / search counters are present in the normalized map ONLY when the provider reported them. Absent != 0. Callers (and the response-stamping layer) use absence to distinguish 'provider was silent' from 'provider explicitly said 0', which matters for :cache/status surfaced on the canonical response.
Usage normalization across providers. Honesty rule: cache / reasoning / citation / search counters are present in the normalized map ONLY when the provider reported them. Absent != 0. Callers (and the response-stamping layer) use absence to distinguish 'provider was silent' from 'provider explicitly said 0', which matters for :cache/status surfaced on the canonical response.
(->int x)Coerce a non-negative integer-like provider counter, returning nil when the value is absent or malformed. Explicit zero remains zero.
Coerce a non-negative integer-like provider counter, returning nil when the value is absent or malformed. Explicit zero remains zero.
(merge-usage current update)Merge cumulative usage snapshots without summing them.
Provider raw maps are merged deeply. A provider-reported total is authoritative and survives later sparse updates. A derived total is refreshed only while both input and output counts are known. Malformed counters in an update are treated as absent.
Merge cumulative usage snapshots without summing them. Provider raw maps are merged deeply. A provider-reported total is authoritative and survives later sparse updates. A derived total is refreshed only while both input and output counts are known. Malformed counters in an update are treated as absent.
(normalize-anthropic-usage u)Normalize Anthropic Messages usage shape. Anthropic reports uncached, cache-read, and cache-creation input tokens as disjoint counts.
Normalize Anthropic Messages usage shape. Anthropic reports uncached, cache-read, and cache-creation input tokens as disjoint counts.
(normalize-codex-usage u)Normalize OpenAI Responses/Codex usage shape.
Normalize OpenAI Responses/Codex usage shape.
(normalize-embedding-usage u)Normalize an embedding-endpoint usage map. Embedding endpoints only meter input tokens, so output is a known zero even when omitted by the provider.
Normalize an embedding-endpoint usage map. Embedding endpoints only meter input tokens, so output is a known zero even when omitted by the provider.
(normalize-gemini-usage u)Normalize Gemini native usage shape.
Normalize Gemini native usage shape.
(normalize-openai-usage u)Normalize OpenAI Chat Completions and compatible usage shapes.
Cache counters have several official locations: OpenAI-style token details, Together's flat cached_tokens, and Anthropic-style top-level fields exposed by proxies. Locations are alternatives rather than additive counters, so each logical counter is selected once before uncached input is calculated.
OpenRouter adds cache_write_tokens to prompt_tokens_details. OpenAI image and audio responses use input/output or prompt/completion token-detail envelopes. Raw usage is retained so text/modality and provider billing details without canonical fields remain available.
Normalize OpenAI Chat Completions and compatible usage shapes. Cache counters have several official locations: OpenAI-style token details, Together's flat cached_tokens, and Anthropic-style top-level fields exposed by proxies. Locations are alternatives rather than additive counters, so each logical counter is selected once before uncached input is calculated. OpenRouter adds cache_write_tokens to prompt_tokens_details. OpenAI image and audio responses use input/output or prompt/completion token-detail envelopes. Raw usage is retained so text/modality and provider billing details without canonical fields remain available.
(normalize-usage provider raw-usage)Dispatch to the correct normalizer based on provider keyword.
Dispatch to the correct normalizer based on provider keyword.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |