Documentation
¶
Index ¶
- type Manager
- func (m *Manager) AddModelUsage(modelName string, inputTokens, outputTokens int) bool
- func (m *Manager) GetModelCost(modelName string) float64
- func (m *Manager) GetModelUsage(modelName string) TokenUsage
- func (m *Manager) OverBudget() bool
- func (m *Manager) TotalCost() float64
- func (m *Manager) TotalTokens() int
- type ModelPricing
- type PricingTable
- func (pt *PricingTable) CalculateCost(model string, inputTokens, outputTokens int) float64
- func (pt *PricingTable) GetCachedDataAge() (time.Duration, error)
- func (pt *PricingTable) GetContextLimit(modelName string) int
- func (pt *PricingTable) GetPricingByModelName(modelName string) (ModelPricing, bool)
- func (pt *PricingTable) ListModels() map[string]ModelPricing
- func (pt *PricingTable) RefreshFromAPI() error
- func (pt *PricingTable) SetCustomPricing(model string, inputPrice, outputPrice float64)
- type TokenUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
ModelUsage map[string]TokenUsage // Model name -> token usage with input/output breakdown
BudgetTokens int
BudgetDollars float64
// contains filtered or unexported fields
}
func (*Manager) AddModelUsage ¶
AddModelUsage adds token usage for a specific model with input/output breakdown
func (*Manager) GetModelCost ¶
GetModelCost returns the cost for a specific model
func (*Manager) GetModelUsage ¶
func (m *Manager) GetModelUsage(modelName string) TokenUsage
GetModelUsage returns the token usage for a specific model
func (*Manager) OverBudget ¶
func (*Manager) TotalCost ¶
TotalCost calculates the total cost using accurate model-specific pricing
func (*Manager) TotalTokens ¶
type ModelPricing ¶
type ModelPricing struct {
InputPrice float64 // Price per 1M tokens for input
OutputPrice float64 // Price per 1M tokens for output
ContextLimit int // Maximum context window size in tokens
OutputLimit int // Maximum output tokens
}
ModelPricing holds the pricing information for a specific model
type PricingTable ¶
type PricingTable struct {
// contains filtered or unexported fields
}
PricingTable holds all model pricing information
func NewPricingTable ¶
func NewPricingTable() *PricingTable
NewPricingTable creates a new pricing table with cached prices
func (*PricingTable) CalculateCost ¶
func (pt *PricingTable) CalculateCost(model string, inputTokens, outputTokens int) float64
CalculateCost calculates the cost for input and output tokens
func (*PricingTable) GetCachedDataAge ¶
func (pt *PricingTable) GetCachedDataAge() (time.Duration, error)
GetCachedDataAge returns how old the cached data is, or an error if no cache exists
func (*PricingTable) GetContextLimit ¶
func (pt *PricingTable) GetContextLimit(modelName string) int
GetContextLimit returns the context window limit for a given model
func (*PricingTable) GetPricingByModelName ¶
func (pt *PricingTable) GetPricingByModelName(modelName string) (ModelPricing, bool)
GetPricingByModelName handles provider-model format names with fuzzy matching Examples: "openai/gpt-4", "anthropic/claude-3-7-sonnet-latest"
func (*PricingTable) ListModels ¶
func (pt *PricingTable) ListModels() map[string]ModelPricing
ListModels returns all models with pricing information
func (*PricingTable) RefreshFromAPI ¶
func (pt *PricingTable) RefreshFromAPI() error
RefreshFromAPI downloads fresh pricing data from the models.dev API and caches it
func (*PricingTable) SetCustomPricing ¶
func (pt *PricingTable) SetCustomPricing(model string, inputPrice, outputPrice float64)
SetCustomPricing allows setting custom pricing for a model
type TokenUsage ¶
TokenUsage represents token usage for a model call