Documentation
¶
Index ¶
- Constants
- func ExportCSV(w io.Writer, entries []CallLogEntry, progress func(current, total int)) error
- func ExportJSON(w io.Writer, entries []CallLogEntry, progress func(current, total int)) error
- func TrackCost(toolName, serverName string, tokenCount int64)
- func TrackCostFromStrings(toolName, serverName, requestJSON, responseJSON string)
- type CallLogEntry
- type Clock
- type CostBreakdown
- type CostTracker
- func (c *CostTracker) FormatCLI(showByTool, showByServer bool) string
- func (c *CostTracker) FormatJSON() (string, error)
- func (c *CostTracker) GetBreakdown() CostBreakdown
- func (c *CostTracker) GetByServer() map[string]int64
- func (c *CostTracker) GetByTool() map[string]int64
- func (c *CostTracker) GetEntries(since time.Time) []CallLogEntry
- func (c *CostTracker) GetPromptHashes() map[string]int64
- func (c *CostTracker) GetPromptHashesForServerTool(server, tool string) map[string]int64
- func (c *CostTracker) GetServerToolStats(serverName string) []NamedServerToolStat
- func (c *CostTracker) GetToolServerStats(toolName string) []NamedServerToolStat
- func (c *CostTracker) GetTotal() int64
- func (c *CostTracker) Reset()
- func (c *CostTracker) Track(toolName, serverName string, tokenCount int64)
- func (c *CostTracker) TrackAt(toolName, serverName string, tokenCount int64, ts time.Time)
- func (c *CostTracker) TrackWithPromptHash(toolName, serverName string, tokenCount int64, hash string, clock Clock)
- type Estimator
- type ExportRow
- type NamedServerToolStat
- type RealClock
- type ServerCost
- type ServerToolKey
- type ServerToolStat
- type ToolCost
Constants ¶
const DefaultCharsPerToken = 4
DefaultCharsPerToken is the heuristic constant used by Estimator: roughly 1 token per 4 characters of content, matching the OpenAI/Anthropic guidance for English text. This is the same primitive the runtime cost tracker uses (TrackCostFromStrings) and the same primitive the benchmark suite uses (tests/bench/token_economy_bench_test.go), so internal cost-tracker accounting and benchmarked savings numbers are computed identically.
Variables ¶
This section is empty.
Functions ¶
func ExportCSV ¶ added in v0.8.0
func ExportCSV(w io.Writer, entries []CallLogEntry, progress func(current, total int)) error
func ExportJSON ¶ added in v0.8.0
func ExportJSON(w io.Writer, entries []CallLogEntry, progress func(current, total int)) error
func TrackCostFromStrings ¶
func TrackCostFromStrings(toolName, serverName, requestJSON, responseJSON string)
Types ¶
type CallLogEntry ¶ added in v0.8.0
func GetEntries ¶ added in v0.8.0
func GetEntries(since time.Time) []CallLogEntry
type CostBreakdown ¶
type CostBreakdown struct {
ByTool []ToolCost `json:"by_tool"`
ByServer []ServerCost `json:"by_server"`
Total int64 `json:"total"`
Duration time.Duration `json:"duration"`
}
type CostTracker ¶
type CostTracker struct {
// contains filtered or unexported fields
}
func GlobalCostTracker ¶
func GlobalCostTracker() *CostTracker
func NewCostTracker ¶
func NewCostTracker() *CostTracker
func (*CostTracker) FormatCLI ¶
func (c *CostTracker) FormatCLI(showByTool, showByServer bool) string
func (*CostTracker) FormatJSON ¶
func (c *CostTracker) FormatJSON() (string, error)
func (*CostTracker) GetBreakdown ¶
func (c *CostTracker) GetBreakdown() CostBreakdown
func (*CostTracker) GetByServer ¶
func (c *CostTracker) GetByServer() map[string]int64
func (*CostTracker) GetByTool ¶
func (c *CostTracker) GetByTool() map[string]int64
func (*CostTracker) GetEntries ¶ added in v0.8.0
func (c *CostTracker) GetEntries(since time.Time) []CallLogEntry
func (*CostTracker) GetPromptHashes ¶ added in v0.8.0
func (c *CostTracker) GetPromptHashes() map[string]int64
func (*CostTracker) GetPromptHashesForServerTool ¶ added in v0.8.0
func (c *CostTracker) GetPromptHashesForServerTool(server, tool string) map[string]int64
func (*CostTracker) GetServerToolStats ¶ added in v0.8.0
func (c *CostTracker) GetServerToolStats(serverName string) []NamedServerToolStat
func (*CostTracker) GetToolServerStats ¶ added in v0.8.0
func (c *CostTracker) GetToolServerStats(toolName string) []NamedServerToolStat
func (*CostTracker) GetTotal ¶
func (c *CostTracker) GetTotal() int64
func (*CostTracker) Reset ¶
func (c *CostTracker) Reset()
func (*CostTracker) Track ¶
func (c *CostTracker) Track(toolName, serverName string, tokenCount int64)
func (*CostTracker) TrackAt ¶ added in v0.8.0
func (c *CostTracker) TrackAt(toolName, serverName string, tokenCount int64, ts time.Time)
func (*CostTracker) TrackWithPromptHash ¶ added in v0.8.0
func (c *CostTracker) TrackWithPromptHash(toolName, serverName string, tokenCount int64, hash string, clock Clock)
type Estimator ¶ added in v0.9.1
type Estimator struct {
// contains filtered or unexported fields
}
Estimator counts tokens from raw string or JSON-marshalable values using a deterministic character-length heuristic. It is intentionally side-effect free and safe for concurrent use.
func NewEstimator ¶ added in v0.9.1
func NewEstimator() *Estimator
NewEstimator returns an Estimator configured with DefaultCharsPerToken. Callers can construct alternative ratios via NewEstimatorWithRatio if they need to match a specific tokenizer profile.
func NewEstimatorWithRatio ¶ added in v0.9.1
NewEstimatorWithRatio returns an Estimator with a custom chars/token ratio. Useful for benchmarks that want to assert savings against a fixed tokenizer-independent baseline.
func (*Estimator) CharsPerToken ¶ added in v0.9.1
CharsPerToken exposes the configured ratio for diagnostics.
func (*Estimator) EstimateJSON ¶ added in v0.9.1
EstimateJSON marshals the value to JSON and returns the estimated token count of the resulting JSON. Returns 0 if marshaling fails (to keep benchmarks best-effort). We deliberately swallow the marshal error so the estimator surface is `int` only — callers needing strict error handling should marshal themselves and call EstimateTokens directly.
func (*Estimator) EstimateTokens ¶ added in v0.9.1
EstimateTokens returns the estimated token count for the given content using the configured chars/token ratio. Empty content returns 0.