cost

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityRecord

type ActivityRecord struct {
	Timestamp    time.Time `json:"timestamp"`
	Command      string    `json:"command"`
	Provider     string    `json:"provider"`
	Model        string    `json:"model"`
	TokensInput  int       `json:"tokens_input"`
	TokensOutput int       `json:"tokens_output"`
	CostUSD      float64   `json:"cost_usd"`
	DurationMs   int64     `json:"duration_ms"`
	CacheHit     bool      `json:"cache_hit"`
	Hash         string    `json:"hash"`
}

type BudgetStatus

type BudgetStatus struct {
	IsExceeded   bool
	PercentUsed  float64
	TodayTotal   float64
	Estimated    float64
	Limit        float64
	IsWarning    bool
	WarningLevel int // 50, 75, 90
}

type Calculator

type Calculator struct{}

func NewCalculator

func NewCalculator() *Calculator

func (*Calculator) AddPricing

func (c *Calculator) AddPricing(provider, model string, table PricingTable)

AddPricing allows adding pricing dynamically (useful for testing or new models)

func (*Calculator) EstimateCost

func (c *Calculator) EstimateCost(provider, model string, inputTokens, outputTokens int) float64

EstimateCost calculates the estimated cost based on provider, model, and tokens

func (*Calculator) GetPricing

func (c *Calculator) GetPricing(provider, model string) (PricingTable, error)

GetPricing returns the pricing table for a provider and model

type CommandStats added in v1.6.0

type CommandStats struct {
	Command      string
	CallCount    int
	TotalCost    float64
	TotalTokens  int
	AvgCost      float64
	CacheHitRate float64
}

type ForecastStats added in v1.6.0

type ForecastStats struct {
	MonthToDate       float64
	DaysInMonth       int
	DaysElapsed       int
	DailyAverage      float64
	ProjectedMonthEnd float64
}

type Manager

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

func NewManager

func NewManager(budgetDaily float64) (*Manager, error)

func (*Manager) CheckBudget

func (m *Manager) CheckBudget(estimatedCost float64) (*BudgetStatus, error)

CheckBudget checks if the estimated cost exceeds the daily budget

func (*Manager) GetBreakdownByCommand added in v1.6.0

func (m *Manager) GetBreakdownByCommand() (*StatsBreakdown, error)

GetBreakdownByCommand returns usage statistics grouped by command

func (*Manager) GetCacheStats added in v1.6.0

func (m *Manager) GetCacheStats() (hitRate float64, totalSaved float64, err error)

GetCacheStats returns cache hit statistics

func (*Manager) GetDailyTotal

func (m *Manager) GetDailyTotal() (float64, error)

GetDailyTotal gets the total spent today

func (*Manager) GetForecast added in v1.6.0

func (m *Manager) GetForecast() (*ForecastStats, error)

GetForecast calculates projected monthly spending

func (*Manager) GetHistory

func (m *Manager) GetHistory() ([]ActivityRecord, error)

GetHistory gets all records

func (*Manager) GetMonthlyTotal

func (m *Manager) GetMonthlyTotal() (float64, error)

GetMonthlyTotal gets the total spent this month

func (*Manager) SaveActivity

func (m *Manager) SaveActivity(record ActivityRecord) error

SaveActivity saves an activity record

type PricingTable

type PricingTable struct {
	InputPricePerMillion  float64
	OutputPricePerMillion float64
}

type ProviderPricing

type ProviderPricing map[string]map[string]PricingTable

type StatsBreakdown added in v1.6.0

type StatsBreakdown struct {
	ByCommand  []CommandStats
	TotalCalls int
	TotalCost  float64
}

Jump to

Keyboard shortcuts

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