Documentation
¶
Overview ¶
Package toolusage extracts metering evidence from one upstream response.
Index ¶
Constants ¶
const ( SourceVendorReported = "vendor_reported" SourceResponseDerived = "response_derived" )
const MaxCount int64 = 1 << 50
MaxCount bounds upstream counters before they can become price multipliers.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheUsage ¶
type CacheUsage struct {
CacheReadTokens int64
CacheCreationTokens int64
CacheCreation5mTokens int64
CacheCreation1hTokens int64
CacheCreation12hTokens int64
}
CacheCreationTokens includes all TTLs. The unclassified remainder uses the ordinary write price (30m for OpenAI). Gemini reads are a subset of input.
func ExtractCacheUsage ¶
func ExtractCacheUsage(raw []byte) CacheUsage
ExtractCacheUsage reads one JSON/SSE frame or a standalone usage object. Malformed counters are ignored individually, preserving valid sibling fields.
func ExtractCacheUsageObject ¶
func ExtractCacheUsageObject(r map[string]any) CacheUsage
ExtractCacheUsageObject accepts an already decoded response or usage container (UseNumber).
type ToolUsageItem ¶
type ToolUsageItem struct {
Tool string `json:"tool"`
Unit string `json:"unit"`
Quantity int64 `json:"quantity"`
Source string `json:"source,omitempty"`
}
ToolUsageItem contains only normalized labels and a quantity, never vendor text.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker's zero value is ready for a single response, including its stream.
func (*Tracker) Observe ¶
Observe consumes one response object or SSE event. Tool declarations and client functions supply no evidence of a hosted invocation.
func (*Tracker) ObserveObject ¶
ObserveObject accepts an already decoded upstream event (UseNumber).
func (*Tracker) Snapshot ¶
func (t *Tracker) Snapshot() []ToolUsageItem
Snapshot returns detached quantities in a stable order. A vendor-reported zero stays visible and takes precedence over all observed response items.