cost

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 7 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 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) GetDailyTotal

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

GetDailyTotal gets the total spent today

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

Jump to

Keyboard shortcuts

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