Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TokenTracker ¶
type TokenTracker struct {
// contains filtered or unexported fields
}
TokenTracker provides a unified interface for tracking token usage using OpenTelemetry metrics.
func NewTokenTracker ¶
func NewTokenTracker(meter metric.Meter) (*TokenTracker, error)
NewTokenTracker creates a new TokenTracker with the provided meter.
func (*TokenTracker) RecordUsage ¶
func (tt *TokenTracker) RecordUsage(ctx context.Context, opts UsageOptions)
RecordUsage records token usage with the provided options.
type UsageOptions ¶
type UsageOptions struct {
// Provider is the name of the LLM provider (e.g., "openai", "anthropic")
Provider string
// ProviderUUID is the unique identifier of the provider
ProviderUUID string
// Model is the actual model used (not the requested model)
Model string
// RequestModel is the original model name requested by the user
RequestModel string
// RuleUUID is the load balancer rule UUID
RuleUUID string
// Scenario is the API scenario (e.g., "openai", "anthropic", "claude_code")
Scenario string
// InputTokens is the number of input/prompt tokens consumed (excluding cache)
InputTokens int
// OutputTokens is the number of output/completion tokens consumed
OutputTokens int
// CacheInputTokens is the number of cache-related tokens consumed
CacheInputTokens int
// SystemTokens represents tokens consumed by system-level operations
SystemTokens int
// Streamed indicates whether this was a streaming request
Streamed bool
// Status is the request status - "success", "error", or "canceled"
Status string
// ErrorCode is the error code if status is not "success"
ErrorCode string
// LatencyMs is the request processing time in milliseconds
LatencyMs int
// UserTier is a low-cardinality class for enterprise observability.
UserTier string
}
UsageOptions contains the options for recording token usage.
Click to show internal directories.
Click to hide internal directories.