usage

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package usage defines observer seams for token and accounting events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainObserver

type ChainObserver struct {
	// contains filtered or unexported fields
}

ChainObserver fans usage events out to observers in registration order.

func ChainObservers

func ChainObservers(observers ...Observer) ChainObserver

ChainObservers returns a ChainObserver over non-nil observers (registration order preserved). An empty chain is a no-op observer.

func (ChainObserver) OnUsage

func (c ChainObserver) OnUsage(ctx context.Context, ev Event) error

type Event

type Event struct {
	TraceID     string
	ALegID      string
	BLegID      string
	PrincipalID string
	SessionID   string
	AttemptSeq  int
	BackendID   string
	FrontendID  string
	Model       string

	// Scope is the optional safe principal/scope attribution snapshot for this request. It is
	// additive metadata; existing observers may ignore it and keep reading PrincipalID
	// (requirements 6.4, 6.5, 7.3). When Scope.PrincipalID is known it must match PrincipalID.
	Scope scope.PrincipalScopeView

	InputTokens      int
	OutputTokens     int
	CacheReadTokens  int
	CacheWriteTokens int
	ReasoningTokens  int
	TotalTokens      int

	CostNanoUnits int64
	Currency      string
	CostSource    string
	RawUsageJSON  string

	RecordedAt time.Time
}

Event is a provider-neutral usage observation emitted from canonical usage deltas.

type NoopObserver

type NoopObserver struct{}

NoopObserver drops usage events.

func (NoopObserver) OnUsage

type Observer

type Observer interface {
	OnUsage(ctx context.Context, ev Event) error
}

Observer records usage without mutating request or stream execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL