Documentation
¶
Overview ¶
Package providerusage reads the token tiers out of a provider's `usage` block.
One rule, one place. Four hosts need it (the proxy, the keep-alive keeper, the cheap-model clients and the transcript reader), and each used to keep its own copy. The copies handled different dialects, so a gap showed up as a silent zero, not as an error.
This package reads ONE block. It does not read a stream: the proxy merges the blocks of a server-sent-event stream itself, because that is transport.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Tiers ¶
type Tiers struct {
FreshInput int64
CacheRead int64
CacheWrite int64
CacheWrite1h int64
Output int64
}
Tiers is one response's billed token counts.
FreshInput, CacheRead and CacheWrite are disjoint. CacheWrite1h is a SUBSET of CacheWrite, never an addition to it.
func Parse ¶
Parse reads a `usage` object. ok is false when the object has no field of a known dialect.
Dialects:
Anthropic input_tokens (fresh only), cache_read_input_tokens,
cache_creation_input_tokens, cache_creation.ephemeral_1h_input_tokens
OpenAI Responses input_tokens (includes cache), input_tokens_details.{cached_tokens,
cache_write_tokens}
OpenAI chat prompt_tokens (includes cache), prompt_tokens_details.cached_tokens
Output only output_tokens alone. Anthropic's streaming message_delta carries exactly
this, and it holds the final completion count.
OpenAI counts cached tokens INSIDE its input total, so fresh is the difference. Anthropic reports the tiers apart. Reading one as the other double-counts the whole transcript.