cost

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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 New

func New(budgetTokens int, budgetDollars float64) *Manager

func (*Manager) AddModelUsage

func (m *Manager) AddModelUsage(modelName string, inputTokens, outputTokens int) bool

AddModelUsage adds token usage for a specific model with input/output breakdown

func (*Manager) GetModelCost

func (m *Manager) GetModelCost(modelName string) float64

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 (m *Manager) OverBudget() bool

func (*Manager) TotalCost

func (m *Manager) TotalCost() float64

TotalCost calculates the total cost using accurate model-specific pricing

func (*Manager) TotalTokens

func (m *Manager) TotalTokens() int

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

type TokenUsage struct {
	InputTokens  int
	OutputTokens int
}

TokenUsage represents token usage for a model call

Jump to

Keyboard shortcuts

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