cost

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cost provides token tracking, budget management, and cost attribution.

Index

Constants

This section is empty.

Variables

View Source
var ErrBudgetExceeded = errors.New("budget exceeded")

ErrBudgetExceeded is returned when the rolling window spend meets or exceeds the budget.

Functions

This section is empty.

Types

type Tracker

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

Tracker wraps cost recording with pre-execution budget checking.

func NewTracker

func NewTracker(st store.Store, budgetUSD float64, windowHours int) *Tracker

NewTracker creates a cost tracker. budgetUSD of 0 means unlimited. windowHours defaults to 24 if <= 0.

func (*Tracker) CheckBudget

func (t *Tracker) CheckBudget(ctx context.Context) error

CheckBudget returns ErrBudgetExceeded if the rolling window spend meets or exceeds the budget. Returns nil if budget is unlimited (0) or spend is under budget.

func (*Tracker) CheckOutlier added in v0.1.13

func (t *Tracker) CheckOutlier(ctx context.Context, issueNumber, estimatedTokens int) string

CheckOutlier compares actual token usage for an issue against its estimate. Returns a warning message if actual exceeds 2x the estimate, empty string otherwise.

func (*Tracker) GetIssueCostSummary added in v0.1.13

func (t *Tracker) GetIssueCostSummary(ctx context.Context, issueNumber int) (*models.CostSummary, error)

GetIssueCostSummary returns the aggregated cost for all sessions of the given issue.

func (*Tracker) RecordUsage

func (t *Tracker) RecordUsage(ctx context.Context, sessionID, providerName, model string, resp *provider.ChatResponse) error

RecordUsage records token usage and estimated cost for a chat response.

Jump to

Keyboard shortcuts

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