domain

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	MaxStringLength = 256
	MaxVendorLength = 64
	MaxModelLength  = 128
	MaxBatchSize    = 500
	MaxMetaBytes    = 16 << 10
	// MaxRequestBytes bounds one request: a full batch of events at their limits.
	MaxRequestBytes = 16 << 20
)

Variables

View Source
var (
	ErrInvalidEventID    = errors.New("invalid event_id: must be a valid UUID")
	ErrEmptyUserID       = errors.New("user_id is required")
	ErrEmptyProjectID    = errors.New("project_id is required")
	ErrEmptyActionID     = errors.New("action_id is required")
	ErrEmptyVendor       = errors.New("vendor is required")
	ErrEmptyModel        = errors.New("model is required")
	ErrInvalidStatus     = errors.New("status must be one of: success, error, cancelled, timeout")
	ErrUserIDTooLong     = errors.New("user_id exceeds 256 characters")
	ErrProjectIDTooLong  = errors.New("project_id exceeds 256 characters")
	ErrActionIDTooLong   = errors.New("action_id exceeds 256 characters")
	ErrVendorTooLong     = errors.New("vendor exceeds 64 characters")
	ErrModelTooLong      = errors.New("model exceeds 128 characters")
	ErrTokensMismatch    = errors.New("tokens_total must equal tokens_input + tokens_output")
	ErrCacheTokens       = errors.New("cache_read_tokens and cache_write_tokens must be >= 0 and together not exceed tokens_input")
	ErrNegativeCost      = errors.New("cost_nanousd must not be negative")
	ErrOccurredAtRange   = errors.New("occurred_at must be between 1900-01-01 and 2262-04-10")
	ErrErrorClassTooLong = errors.New("error_class exceeds 256 characters")
	ErrMetaTooLarge      = errors.New("meta exceeds 16384 bytes of keys and values")
	ErrMetaEmptyKey      = errors.New("meta keys must not be empty")
	ErrBatchTooLarge     = errors.New("batch size exceeds maximum of 500 events")
)

Validation errors

Functions

This section is empty.

Types

type MetaUsageParams

type MetaUsageParams struct {
	// MetaKey/MetaValue select the events (required).
	MetaKey   string
	MetaValue string

	// GroupByMetaKey optionally splits rows by a second meta key
	// (e.g. "gentask_id"); empty groups everything under GroupValue "".
	GroupByMetaKey string

	// ProjectID optionally narrows to one project.
	ProjectID string
}

MetaUsageParams holds the parameters for aggregating usage over events carrying a given meta key/value (e.g. one batch job's events).

type MetaUsageRow

type MetaUsageRow struct {
	GroupValue   string
	Vendor       string
	Model        string
	TokensInput  int64
	TokensOutput int64
	TokensTotal  int64
	RequestCount int64
	CostNanoUSD  int64
	// Parts of TokensInput served from and written to the prompt cache.
	CacheReadTokens  int64
	CacheWriteTokens int64
}

MetaUsageRow is one aggregate bucket: (GroupValue, Vendor, Model).

type Status

type Status int

Status represents the outcome of an LLM request

const (
	StatusUnspecified Status = 0
	StatusSuccess     Status = 1
	StatusError       Status = 2
	StatusCancelled   Status = 3
	StatusTimeout     Status = 4
)

func StatusFromString

func StatusFromString(s string) Status

StatusFromString converts a string to Status

func (Status) String

func (s Status) String() string

type SummaryParams

type SummaryParams struct {
	From time.Time
	To   time.Time

	// Filters
	ProjectID string
	UserID    string
	Vendor    string
	Model     string
	ActionID  string
	Status    Status

	// Group by dimensions (day is always included)
	GroupByProjectID bool
	GroupByUserID    bool
	GroupByVendor    bool
	GroupByModel     bool
	GroupByActionID  bool
	GroupByStatus    bool
}

SummaryParams holds the parameters for querying usage summary

type SummaryRow

type SummaryRow struct {
	Bucket time.Time

	// Dimension values (only populated if grouped by)
	ProjectID string
	UserID    string
	Vendor    string
	Model     string
	ActionID  string
	Status    Status

	// Aggregated values
	TokensInput   int64
	TokensOutput  int64
	TokensTotal   int64
	RequestCount  int64
	SumDurationMs int64
	CostNanoUSD   int64
	// Parts of TokensInput served from and written to the prompt cache.
	CacheReadTokens  int64
	CacheWriteTokens int64
}

SummaryRow represents a single row in the usage summary

type UsageEvent

type UsageEvent struct {
	EventID          uuid.UUID
	CreatedAt        time.Time
	OccurredAt       *time.Time
	UserID           string
	ProjectID        string
	ActionID         string
	Vendor           string
	Model            string
	Status           Status
	DurationMs       int64
	TokensInput      int64
	TokensOutput     int64
	TokensTotal      int64
	ErrorClass       string
	VendorHTTPStatus int32
	Meta             map[string]string
	CostNanoUSD      int64
	// Prompt-cache tokens, both part of TokensInput: read from the vendor's
	// cache, and written to it, each priced differently from plain input.
	CacheReadTokens  int64
	CacheWriteTokens int64
}

UsageEvent represents a single LLM usage event

func (*UsageEvent) MetaJSON

func (e *UsageEvent) MetaJSON() ([]byte, error)

MetaJSON returns the meta as JSON bytes

func (*UsageEvent) Validate

func (e *UsageEvent) Validate() error

Validate validates the usage event

Jump to

Keyboard shortcuts

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