cost

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCalculator = NewCalculator()

DefaultCalculator is the global cost calculator instance

Functions

This section is empty.

Types

type Calculator

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

Calculator provides cost calculation for LLM usage

func NewCalculator

func NewCalculator() *Calculator

NewCalculator creates a new cost calculator with default pricing

func (*Calculator) AddPricing

func (c *Calculator) AddPricing(pricing *ModelPricing)

AddPricing adds or updates pricing for a model

func (*Calculator) Calculate

func (c *Calculator) Calculate(usage *Usage) (*Cost, error)

Calculate computes the cost for the given usage

func (*Calculator) CalculateMultiple

func (c *Calculator) CalculateMultiple(usages []*Usage) (*Cost, error)

CalculateMultiple computes total cost for multiple usage records

func (*Calculator) EstimateCost

func (c *Calculator) EstimateCost(model string, inputTokens, outputTokens int) (*Cost, error)

EstimateCost estimates cost for a given number of tokens

func (*Calculator) GetPricing

func (c *Calculator) GetPricing(model string) (*ModelPricing, bool)

GetPricing retrieves pricing for a model

func (*Calculator) ListModels

func (c *Calculator) ListModels() []string

ListModels returns all models with pricing information

type Cost

type Cost struct {
	InputCost  float64
	OutputCost float64
	CachedCost float64
	TotalCost  float64
	Currency   string
}

Cost represents the calculated cost for LLM usage

type ModelPricing

type ModelPricing struct {
	Model           string
	InputPer1M      float64 // Cost per 1M input tokens in USD
	OutputPer1M     float64 // Cost per 1M output tokens in USD
	CachedPer1M     float64 // Cost per 1M cached input tokens (if supported)
	SupportsCaching bool
}

ModelPricing contains pricing information for a specific model

type Usage

type Usage struct {
	Model        string
	InputTokens  int
	OutputTokens int
	CachedTokens int // Cached input tokens (if model supports caching)
	TotalTokens  int
}

Usage represents token usage for a single LLM call

Jump to

Keyboard shortcuts

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