Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReasoningTiming ¶
type ReasoningTiming struct {
Start int64 `json:"start"` // start → first reasoning frame
End int64 `json:"end"` // start → last reasoning frame
}
ReasoningTiming is the reasoning span. Microseconds elapsed from the request start, anchored not chained, same as UpstreamTiming:
reasoning span = End - Start
type Tokens ¶
Tokens is the universal token-count shape across providers. Keys are convention-driven, not enforced. Common values:
input prompt tokens (all providers) output completion tokens (all providers) cache_creation Anthropic prompt-cache write cache_read Anthropic prompt-cache hit reasoning OpenAI o-series + Anthropic extended thinking server_tool_use Anthropic server-side tool calls
Per-shape parsers fill whatever keys their provider returned. Sum over the map gives a backward-compatible "total tokens" for legacy consumers.
func (Tokens) Add ¶
Add adds other into t in place. Useful for streaming chunks where each chunk emits a partial usage block.
func (Tokens) Sum ¶
Sum returns the arithmetic total of all values. Used by legacy single-meter rate-limit callers that haven't migrated to typed meters.
NOT a token total for billing/usage reporting: some keys are sub-breakdowns of a coarser one (e.g. reasoning ⊂ output), so Sum double-counts them. A provider total_tokens is input + output.
type UpstreamTiming ¶
type UpstreamTiming struct {
Start int64 `json:"start"` // start → handed to upstream
ResponseStart int64 `json:"response_start"` // start → first byte (TTFT)
ResponseEnd int64 `json:"response_end"` // start → upstream done
}
UpstreamTiming is the upstream-leg breakdown. All values are microseconds elapsed from the request start (Event.Timestamp) — the unit lives here, not in the field names. Every mark is anchored to the start, never chained, so derive intervals at query time:
upstream TTFT = ResponseStart - Start stream body time = ResponseEnd - ResponseStart
It is a pure wire shape: the public client reports it as StreamTiming and pkg/usage.Event embeds it. Lives in sdk/usage so both the vendorable client and the server-side event record can name it without a cross-module edge.