Documentation
¶
Index ¶
- Variables
- func CalculateCost(usage providers.Usage, model providers.Model) float64
- func FormatTokens(n int64) string
- func FormatUSD(n float64) string
- type BudgetStatus
- type CostBreakdown
- type CostSummary
- type Entry
- type PostgresTracker
- func (t *PostgresTracker) CheckBudget(ctx context.Context, sessionID string) (BudgetStatus, error)
- func (t *PostgresTracker) Close() error
- func (t *PostgresTracker) DailyCost(ctx context.Context) (CostSummary, error)
- func (t *PostgresTracker) Record(ctx context.Context, entry Entry) error
- func (t *PostgresTracker) RegisterModel(m providers.Model)
- func (t *PostgresTracker) RollingCost(ctx context.Context, window time.Duration) (CostSummary, error)
- func (t *PostgresTracker) SessionCost(ctx context.Context, sessionID string) (CostSummary, error)
- func (t *PostgresTracker) Usage(ctx context.Context, opts UsageOptions) (*UsageReport, error)
- type Tracker
- type UsageOptions
- type UsageReport
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func FormatTokens ¶
FormatTokens formats a token count into a human-readable abbreviated form:
<1000 → raw number (e.g. "234") 1k-999k → k suffix with 1 decimal (e.g. "45.2k") 1M-999M → M suffix with 1 decimal (e.g. "1.5M") 1B-999B → B suffix with 1 decimal (e.g. "2.1B") 1T+ → T suffix with 1 decimal
Types ¶
type BudgetStatus ¶
type BudgetStatus struct {
DailyUsed float64 `json:"daily_used"`
DailyLimit float64 `json:"daily_limit"`
DailyPercent float64 `json:"daily_percent"`
TaskUsed float64 `json:"task_used"`
TaskLimit float64 `json:"task_limit"`
TaskPercent float64 `json:"task_percent"`
RollingUsed float64 `json:"rolling_used"`
Window time.Duration `json:"window_seconds"`
ShouldWarn bool `json:"should_warn"`
ShouldAbort bool `json:"should_abort"`
}
type CostBreakdown ¶
func CalculateCostDetailed ¶
func CalculateCostDetailed(usage providers.Usage, model providers.Model) CostBreakdown
type CostSummary ¶
type Entry ¶
type Entry struct {
ID string `json:"id,omitempty"`
SessionID string `json:"session_id,omitempty"`
Model string `json:"model,omitempty"`
Provider string `json:"provider,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CachedTokens int `json:"cached_tokens"`
CostUSD float64 `json:"cost_usd"`
TaskID string `json:"task_id,omitempty"`
}
type PostgresTracker ¶
type PostgresTracker struct {
// contains filtered or unexported fields
}
func NewPostgresTracker ¶
func NewPostgresTracker(db *sql.DB, cfg config.CostConfig) (*PostgresTracker, error)
func (*PostgresTracker) CheckBudget ¶
func (t *PostgresTracker) CheckBudget(ctx context.Context, sessionID string) (BudgetStatus, error)
func (*PostgresTracker) Close ¶
func (t *PostgresTracker) Close() error
func (*PostgresTracker) DailyCost ¶
func (t *PostgresTracker) DailyCost(ctx context.Context) (CostSummary, error)
func (*PostgresTracker) Record ¶
func (t *PostgresTracker) Record(ctx context.Context, entry Entry) error
func (*PostgresTracker) RegisterModel ¶
func (t *PostgresTracker) RegisterModel(m providers.Model)
func (*PostgresTracker) RollingCost ¶
func (t *PostgresTracker) RollingCost(ctx context.Context, window time.Duration) (CostSummary, error)
func (*PostgresTracker) SessionCost ¶
func (t *PostgresTracker) SessionCost(ctx context.Context, sessionID string) (CostSummary, error)
func (*PostgresTracker) Usage ¶
func (t *PostgresTracker) Usage(ctx context.Context, opts UsageOptions) (*UsageReport, error)
type Tracker ¶
type Tracker interface {
Record(ctx context.Context, entry Entry) error
SessionCost(ctx context.Context, sessionID string) (CostSummary, error)
DailyCost(ctx context.Context) (CostSummary, error)
RollingCost(ctx context.Context, window time.Duration) (CostSummary, error)
CheckBudget(ctx context.Context, sessionID string) (BudgetStatus, error)
Usage(ctx context.Context, opts UsageOptions) (*UsageReport, error)
Close() error
}
type UsageOptions ¶
type UsageReport ¶
type UsageReport struct {
Summary CostSummary `json:"summary"`
ByModel map[string]CostSummary `json:"by_model"`
ByProvider map[string]CostSummary `json:"by_provider"`
Entries []Entry `json:"entries,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.