usage

package
v0.31.45 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCallMeta

func WithCallMeta(ctx context.Context, meta CallMeta) context.Context

Types

type CallMeta

type CallMeta struct {
	Source    string
	SessionID string
	RunID     string
}

func CallMetaFromContext

func CallMetaFromContext(ctx context.Context) CallMeta

type Entry

type Entry struct {
	Timestamp        time.Time `json:"timestamp"`
	Provider         string    `json:"provider"`
	Model            string    `json:"model"`
	InputTokens      int       `json:"input_tokens"`
	OutputTokens     int       `json:"output_tokens"`
	CachedTokens     int       `json:"cached_tokens,omitempty"`
	CacheReadTokens  int       `json:"cache_read_tokens,omitempty"`
	CacheWriteTokens int       `json:"cache_write_tokens,omitempty"`
	EstimatedCostUSD float64   `json:"estimated_cost_usd"`
	Source           string    `json:"source"`
	SessionID        string    `json:"session_id,omitempty"`
	RunID            string    `json:"run_id,omitempty"`
	PricingKnown     bool      `json:"pricing_known"`
}

type LimitStatus

type LimitStatus struct {
	Exceeded bool
	Mode     string
	Period   string
	SpentUSD float64
	LimitUSD float64
}

type Limits

type Limits struct {
	DailyUSD   float64 `json:"daily_usd"`
	WeeklyUSD  float64 `json:"weekly_usd"`
	MonthlyUSD float64 `json:"monthly_usd"`
	Mode       string  `json:"mode"`
}

type ModelPrice

type ModelPrice struct {
	InputPer1MUSD      float64 `json:"input_per_1m_usd"`
	OutputPer1MUSD     float64 `json:"output_per_1m_usd"`
	CacheReadPer1MUSD  float64 `json:"cache_read_per_1m_usd,omitempty"`
	CacheWritePer1MUSD float64 `json:"cache_write_per_1m_usd,omitempty"`
}

type SignalEntry added in v0.31.6

type SignalEntry struct {
	Timestamp  time.Time         `json:"timestamp"`
	Name       string            `json:"name"`
	Count      int               `json:"count"`
	Source     string            `json:"source,omitempty"`
	SessionID  string            `json:"session_id,omitempty"`
	RunID      string            `json:"run_id,omitempty"`
	Dimensions map[string]string `json:"dimensions,omitempty"`
}

type SignalSummary added in v0.31.6

type SignalSummary struct {
	Period     string             `json:"period"`
	TotalCount int                `json:"total_count"`
	Rows       []SignalSummaryRow `json:"rows"`
}

type SignalSummaryRow added in v0.31.6

type SignalSummaryRow struct {
	Name       string            `json:"name"`
	Source     string            `json:"source,omitempty"`
	Count      int               `json:"count"`
	Dimensions map[string]string `json:"dimensions,omitempty"`
	FirstAt    string            `json:"first_at,omitempty"`
	LastAt     string            `json:"last_at,omitempty"`
}

type Summary

type Summary struct {
	Period          string       `json:"period"`
	GroupBy         string       `json:"group_by"`
	TotalCalls      int          `json:"total_calls"`
	TotalCostUSD    float64      `json:"total_cost_usd"`
	TotalInput      int          `json:"total_input_tokens"`
	TotalOutput     int          `json:"total_output_tokens"`
	TotalCached     int          `json:"total_cached_tokens"`
	TotalCacheRead  int          `json:"total_cache_read_tokens"`
	TotalCacheWrite int          `json:"total_cache_write_tokens"`
	Rows            []SummaryRow `json:"rows"`
}

type SummaryRow

type SummaryRow struct {
	Key              string  `json:"key"`
	Calls            int     `json:"calls"`
	CostUSD          float64 `json:"cost_usd"`
	InputTokens      int     `json:"input_tokens"`
	OutputTokens     int     `json:"output_tokens"`
	CachedTokens     int     `json:"cached_tokens"`
	CacheReadTokens  int     `json:"cache_read_tokens"`
	CacheWriteTokens int     `json:"cache_write_tokens"`
}

type TrackedClient

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

func NewTrackedClient

func NewTrackedClient(inner llm.Client, tracker *Tracker, provider string, model string, tier llm.Tier) *TrackedClient

func (*TrackedClient) Ask

func (c *TrackedClient) Ask(ctx context.Context, prompt string) (string, error)

func (*TrackedClient) Chat

func (c *TrackedClient) Chat(ctx context.Context, messages []llm.ChatMessage, opts llm.ChatOptions) (llm.ChatResponse, error)

func (*TrackedClient) SetNotifier

func (c *TrackedClient) SetNotifier(notifier WarningNotifier)

type Tracker

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

func NewTracker

func NewTracker(workspaceDir string, opts TrackerOptions) (*Tracker, error)

func (*Tracker) CheckLimitStatus

func (t *Tracker) CheckLimitStatus() (LimitStatus, error)

func (*Tracker) EstimateCost

func (t *Tracker) EstimateCost(provider, model string, u llm.Usage) (float64, bool)

func (*Tracker) Limits

func (t *Tracker) Limits() Limits

func (*Tracker) Record

func (t *Tracker) Record(entry Entry) error

func (*Tracker) RecordSignal added in v0.31.6

func (t *Tracker) RecordSignal(entry SignalEntry) error

func (*Tracker) Signals added in v0.31.6

func (t *Tracker) Signals(period string) (SignalSummary, error)

func (*Tracker) Summary

func (t *Tracker) Summary(period, groupBy string) (Summary, error)

func (*Tracker) UpdateLimits

func (t *Tracker) UpdateLimits(next Limits) (Limits, error)

type TrackerOptions

type TrackerOptions struct {
	Now            func() time.Time
	InitialLimits  Limits
	PriceOverrides map[string]ModelPrice
}

type WarningNotifier

type WarningNotifier func(ctx context.Context, message string)

Jump to

Keyboard shortcuts

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