ledger

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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateRecord

func ValidateRecord(record Record) error

Types

type MemoryLedger

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

MemoryLedger is a minimal in-memory recorder for tests and off-by-default use.

func NewMemoryLedger

func NewMemoryLedger(opts Options) *MemoryLedger

func (*MemoryLedger) ListByAttempt

func (l *MemoryLedger) ListByAttempt(ctx context.Context, requestID, attemptID string) ([]Record, error)

func (*MemoryLedger) ListByRequest

func (l *MemoryLedger) ListByRequest(ctx context.Context, requestID string) ([]Record, error)

func (*MemoryLedger) Record

func (l *MemoryLedger) Record(ctx context.Context, record Record) error

type Options

type Options struct {
	Now func() time.Time
}

Options configures MemoryLedger.

type Record

type Record struct {
	RequestID         string
	AttemptID         string
	Backend           string
	Model             string
	Plane             lipapi.UsagePlane
	InputTokens       int
	OutputTokens      int
	CacheReadTokens   int
	CacheWriteTokens  int
	ReasoningTokens   int
	TotalTokens       int
	Metadata          lipapi.UsageAccountingMetadata
	CreatedAt         time.Time
	UnavailableReason string
	FailureReason     string
}

Record is the core-owned billing ledger fact for one request attempt and usage plane.

type Recorder

type Recorder interface {
	Record(context.Context, Record) error
}

Recorder captures usage records without prescribing a persistence backend.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError reports a field-specific invalid ledger record.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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