Documentation
¶
Index ¶
- Constants
- func PublishRecord(ctx context.Context, record Record)
- func ReasoningEffortFromContext(ctx context.Context) string
- func RegisterNamedPlugin(name string, plugin Plugin)
- func RegisterPlugin(plugin Plugin)
- func RequestedModelAliasFromContext(ctx context.Context) string
- func ResetDefaultManager()
- func ServiceTierFromContext(ctx context.Context) string
- func SetDefaultManager(manager *Manager)
- func StartDefault(ctx context.Context)
- func StopDefault()
- func WithReasoningEffort(ctx context.Context, effort string) context.Context
- func WithRequestedModelAlias(ctx context.Context, alias string) context.Context
- func WithServiceTier(ctx context.Context, tier string) context.Context
- type Detail
- type Failure
- type Manager
- type Plugin
- type Record
Constants ¶
const DefaultServiceTier = "default"
DefaultServiceTier is used when a request does not specify service_tier.
Variables ¶
This section is empty.
Functions ¶
func PublishRecord ¶
PublishRecord publishes a record using the default manager.
func ReasoningEffortFromContext ¶
ReasoningEffortFromContext returns the client-requested reasoning effort stored in ctx.
func RegisterNamedPlugin ¶
RegisterNamedPlugin registers or replaces a named plugin on the default manager. The plugin host uses this to keep the delivery list stable across plugin reloads.
func RegisterPlugin ¶
func RegisterPlugin(plugin Plugin)
RegisterPlugin registers a plugin on the default manager.
func RequestedModelAliasFromContext ¶
RequestedModelAliasFromContext returns the client-requested model name stored in ctx.
func ResetDefaultManager ¶
func ResetDefaultManager()
ResetDefaultManager resets the global usage manager to a fresh reusable instance.
func ServiceTierFromContext ¶ added in v7.2.49
ServiceTierFromContext returns the client-requested service tier stored in ctx.
func SetDefaultManager ¶
func SetDefaultManager(manager *Manager)
SetDefaultManager replaces the global usage manager instance.
func StartDefault ¶
StartDefault starts the default manager's dispatcher.
func WithReasoningEffort ¶
WithReasoningEffort stores the client-requested reasoning effort for usage sinks.
func WithRequestedModelAlias ¶
WithRequestedModelAlias stores the client-requested model name for usage sinks.
Types ¶
type Detail ¶
type Detail struct {
InputTokens int64
OutputTokens int64
ReasoningTokens int64
CachedTokens int64
CacheReadTokens int64
CacheCreationTokens int64
TotalTokens int64
}
Detail holds the token usage breakdown.
type Failure ¶
Failure holds HTTP failure metadata for an upstream request attempt. It is populated when a request fails with a structured upstream error so plugin usage sinks can report status codes and response snippets.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager maintains a queue of usage records and delivers them to registered plugins.
func DefaultManager ¶
func DefaultManager() *Manager
DefaultManager returns the global usage manager instance.
func NewManager ¶
NewManager constructs a manager with a buffered queue.
func ResetDefaultManagerForTest ¶
func ResetDefaultManagerForTest(tb interface{ Cleanup(func()) }) *Manager
ResetDefaultManagerForTest swaps the global usage manager for tests and restores it afterwards.
func (*Manager) Publish ¶
Publish enqueues a usage record for processing. If no plugin is registered the record will be discarded downstream.
func (*Manager) RegisterNamed ¶
RegisterNamed registers or replaces a plugin by name. When name already exists the previously-registered plugin is replaced in place so the delivery order is preserved; otherwise the plugin is appended. Plugins registered by name can be refreshed (e.g. by the plugin host when reloading a plugin) without producing duplicates in the dispatch list.
func (*Manager) Reset ¶
func (m *Manager) Reset()
Reset stops the dispatcher and clears pending state so the manager can be reused.
type Record ¶
type Record struct {
Provider string
// ExecutorType stores the concrete executor type that handled the request.
// Plugin sinks use this to attribute traffic to a specific executor
// implementation (e.g. "gemini-cli", "claude-cli", "codex-ws").
ExecutorType string
Model string
Alias string
APIKey string
AuthID string
AuthIndex string
// AuthType stores the credential type that backed the request (e.g.
// "oauth", "api-key"). Empty means the value was not captured.
AuthType string
Source string
// ReasoningEffort stores the translated upstream thinking level for request event logs.
ReasoningEffort string
// ServiceTier stores the client-requested service tier for request event logs.
ServiceTier string
RequestedAt time.Time
Latency time.Duration
// FirstByteLatency / APIFirstByteLatency preserve the fork's historical
// TTFB measurements for the file-backed usage logger and are kept populated
// alongside TTFT below for compatibility with both fork and upstream sinks.
FirstByteLatency time.Duration
APIFirstByteLatency time.Duration
// TTFT is the upstream-aligned time-to-first-token duration used by plugin
// usage sinks. It mirrors FirstByteLatency semantically.
TTFT time.Duration
// Failed flags a terminal failure for the request. Both Failed and Fail
// carry failure information: Failed is the boolean summary, Fail carries
// structured HTTP status/body detail when available.
Failed bool
Fail Failure
// ChunkCount tracks the number of stream chunks observed for the request.
ChunkCount int64
// ResponseBytes / APIResponseBytes preserve the fork's byte counters.
ResponseBytes int64
APIResponseBytes int64
Detail Detail
// ResponseHeaders stores a snapshot of upstream response headers for usage sinks.
ResponseHeaders http.Header
}
Record contains the usage statistics captured for a single provider request.