Documentation
¶
Index ¶
- func FormatCost(usd float64) string
- func FormatSessionCost(sc SessionCost, now time.Time) string
- func FormatTokens(n int64) string
- type Manager
- func (m *Manager) AllCosts() []SessionCost
- func (m *Manager) GetOrCreateTracker(sessionID, providerName, model string) *Tracker
- func (m *Manager) Load(sessionID, providerName, model string)
- func (m *Manager) Save(sessionID string) error
- func (m *Manager) SessionCost(sessionID string) (SessionCost, bool)
- func (m *Manager) TotalCost() float64
- type ModelRate
- type PricingTable
- type SessionCost
- type TokenUsage
- type Tracker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatCost ¶
FormatCost returns a human-readable cost string.
func FormatSessionCost ¶
func FormatSessionCost(sc SessionCost, now time.Time) string
FormatSessionCost returns a formatted summary for a session.
func FormatTokens ¶
FormatTokens returns a human-readable token count.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager tracks cost across all sessions.
func NewManager ¶
func NewManager(pricing PricingTable, dataDir string) *Manager
NewManager creates a cost manager with the given pricing table.
func (*Manager) AllCosts ¶
func (m *Manager) AllCosts() []SessionCost
AllCosts returns costs for all sessions, sorted by total cost descending.
func (*Manager) GetOrCreateTracker ¶
GetOrCreateTracker returns the tracker for a session, creating one if needed.
func (*Manager) SessionCost ¶
func (m *Manager) SessionCost(sessionID string) (SessionCost, bool)
SessionCost returns cost for a specific session.
type ModelRate ¶
type ModelRate struct {
InputPerM float64 `json:"input_per_m"`
OutputPerM float64 `json:"output_per_m"`
CacheReadPerM float64 `json:"cache_read_per_m"`
CacheWritePerM float64 `json:"cache_write_per_m"`
}
ModelRate holds per-million-token pricing for a single model.
type PricingTable ¶
PricingTable maps provider+model to pricing rates.
func DefaultPricingTable ¶
func DefaultPricingTable() PricingTable
DefaultPricingTable returns built-in pricing for known models.
func (PricingTable) Get ¶
func (t PricingTable) Get(provider, model string) (ModelRate, bool)
Get returns the rate for a provider+model, or false if not found.
func (PricingTable) Merge ¶
func (t PricingTable) Merge(other PricingTable) PricingTable
Merge overlays another pricing table on top of this one.
type SessionCost ¶
type SessionCost struct {
Provider string `json:"provider"`
Model string `json:"model"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
CacheReadTokens int64 `json:"cache_read_tokens"`
CacheWriteTokens int64 `json:"cache_write_tokens"`
TotalCostUSD float64 `json:"total_cost_usd"`
}
SessionCost tracks cumulative token usage and estimated cost for a session.
type TokenUsage ¶
type TokenUsage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheRead int `json:"cache_read_tokens"`
CacheWrite int `json:"cache_write_tokens"`
}
TokenUsage records token consumption for a single API call. Defined in the cost package to avoid circular imports.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker accumulates token usage and computes cost.
func NewTracker ¶
func NewTracker(provider, model string, pricing PricingTable) *Tracker
NewTracker creates a cost tracker for the given provider/model.
func (*Tracker) Record ¶
func (t *Tracker) Record(usage TokenUsage)
Record adds a usage update from an API call.
func (*Tracker) SessionCost ¶
func (t *Tracker) SessionCost() SessionCost
SessionCost returns a snapshot of the current cost.