Documentation
¶
Overview ¶
Package costs provides token cost tracking and pricing for LLM models.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ModelPricing = map[string]ModelCost{
"gpt-4o": {Input: 2.50, Output: 10.00},
"gpt-4o-mini": {Input: 0.15, Output: 0.60},
"grok-4-1-fast": {Input: 3.00, Output: 15.00},
"gemini-2.0-flash": {Input: 0.10, Output: 0.40},
"claude-sonnet-4": {Input: 3.00, Output: 15.00},
"claude-opus-4": {Input: 15.00, Output: 75.00},
}
ModelPricing maps model identifiers to their costs.
Functions ¶
Types ¶
type CostSummary ¶
type CostSummary struct {
Model string `json:"model"`
TotalInput int `json:"total_input_tokens"`
TotalOutput int `json:"total_output_tokens"`
TotalCostUSD float64 `json:"total_cost_usd"`
Turns int `json:"turns"`
}
CostSummary is a snapshot of cumulative session costs.
type ModelCost ¶
type ModelCost struct {
Input float64 // USD per 1M input tokens
Output float64 // USD per 1M output tokens
}
ModelCost holds the per-1M-token pricing for a model.
type SessionTracker ¶
type SessionTracker struct {
Model string `json:"model"`
TotalInput int `json:"total_input"`
TotalOutput int `json:"total_output"`
TotalCostUSD float64 `json:"total_cost_usd"`
Turns int `json:"turns"`
// contains filtered or unexported fields
}
SessionTracker accumulates token usage and cost across a session.
func NewSessionTracker ¶
func NewSessionTracker() *SessionTracker
NewSessionTracker creates a new empty tracker.
func (*SessionTracker) GetSummary ¶
func (t *SessionTracker) GetSummary() CostSummary
GetSummary returns a snapshot of the current session cost state.
func (*SessionTracker) Load ¶
func (t *SessionTracker) Load(path string) error
Load deserialises tracker state from a JSON file.
func (*SessionTracker) RecordUsage ¶
func (t *SessionTracker) RecordUsage(model string, inputTokens, outputTokens int)
RecordUsage adds a turn's token usage and computes the incremental cost.
func (*SessionTracker) Save ¶
func (t *SessionTracker) Save(path string) error
Save serialises the tracker state to a JSON file.
Click to show internal directories.
Click to hide internal directories.