Documentation
¶
Index ¶
- Constants
- func CostForTokens(pricing Pricing, inputTokens, outputTokens int64) (float64, float64, float64)
- func CostForTokensWithCache(pricing Pricing, inputTokens, outputTokens, cacheCreation, cacheRead int64) (float64, float64, float64)
- func HasLLMCredentials(cfg LLMCallerConfig) bool
- func SeedDemo(ctx context.Context, path string, overwrite bool) (int, int, error)
- func SortSessions(sessions []SessionSummary, sortKey, sortDir string)
- func StripTaggedSection(text, tag string) string
- type Filters
- type LLMCallFunc
- type LLMCallerConfig
- type ModelCost
- type Overview
- type PeriodComparison
- type Pricing
- type PricingTable
- type Querier
- type Query
- type SessionDetail
- type SessionMessage
- type SessionMessageGroup
- type SessionSummary
Constants ¶
const ( StatusCompleted = "completed" StatusFailed = "failed" StatusAbandoned = "abandoned" StatusUnknown = "unknown" )
const DemoSQLitePath = "tapes.demo.sqlite"
Variables ¶
This section is empty.
Functions ¶
func CostForTokens ¶
CostForTokens calculates cost using base input/output pricing. For cache-aware cost calculation, use CostForTokensWithCache.
func CostForTokensWithCache ¶
func CostForTokensWithCache(pricing Pricing, inputTokens, outputTokens, cacheCreation, cacheRead int64) (float64, float64, float64)
CostForTokensWithCache calculates cost accounting for prompt caching. When cache token counts are available, base input tokens are calculated as: baseInput = totalInput - cacheCreation - cacheRead Each token type is priced at its respective rate.
func HasLLMCredentials ¶
func HasLLMCredentials(cfg LLMCallerConfig) bool
HasLLMCredentials checks whether an API key can be resolved from the config without creating a caller. Used for auto-enabling insights.
func SortSessions ¶
func SortSessions(sessions []SessionSummary, sortKey, sortDir string)
SortSessions sorts session summaries in place by the given key and direction.
func StripTaggedSection ¶
StripTaggedSection removes all occurrences of a given XML-like tagged section (e.g. <system-reminder>…</system-reminder>) from text.
Types ¶
type LLMCallFunc ¶
LLMCallFunc is the signature for an LLM inference call.
func NewLLMCaller ¶
func NewLLMCaller(cfg LLMCallerConfig) (LLMCallFunc, error)
NewLLMCaller creates a LLMCallFunc based on the provided configuration. Resolution order for API key:
- Explicit APIKey in config
- credentials.Manager (from tapes auth)
- Environment variables (OPENAI_API_KEY / ANTHROPIC_API_KEY)
- Fall back to Ollama at localhost:11434
type LLMCallerConfig ¶
type LLMCallerConfig struct {
Provider string // "openai", "anthropic", or "ollama"
Model string // e.g. "gpt-4o-mini", "claude-haiku-4-5-20251001"
APIKey string // explicit API key (highest priority)
BaseURL string // override base URL
CredMgr *credentials.Manager // credentials from tapes auth
Logger *slog.Logger // optional logger; defaults to noop
}
LLMCallerConfig holds configuration for creating an LLM caller.
type Overview ¶
type Overview struct {
Sessions []SessionSummary `json:"sessions"`
TotalCost float64 `json:"total_cost"`
TotalTokens int64 `json:"total_tokens"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
TotalDuration time.Duration `json:"total_duration_ns"`
TotalToolCalls int `json:"total_tool_calls"`
SuccessRate float64 `json:"success_rate"`
Completed int `json:"completed"`
Failed int `json:"failed"`
Abandoned int `json:"abandoned"`
CostByModel map[string]ModelCost `json:"cost_by_model"`
PreviousPeriod *PeriodComparison `json:"previous_period,omitempty"`
}
type PeriodComparison ¶
type Pricing ¶
type Pricing struct {
Input float64 `json:"input"`
Output float64 `json:"output"`
CacheRead float64 `json:"cache_read"`
CacheWrite float64 `json:"cache_write"`
}
func PricingForModel ¶
func PricingForModel(pricing PricingTable, model string) (Pricing, bool)
type PricingTable ¶
func DefaultPricing ¶
func DefaultPricing() PricingTable
DefaultPricing returns hardcoded pricing per million tokens for supported models.
Last verified: 2026-03-08 Sources:
- Anthropic: https://platform.claude.com/docs/en/about-claude/pricing
- OpenAI: https://platform.openai.com/docs/pricing
- DeepSeek: https://api-docs.deepseek.com/quick_start/pricing
Anthropic cache multipliers: CacheWrite = 1.25x input, CacheRead = 0.10x input. OpenAI cache: CacheWrite = 1x input (no surcharge), CacheRead = 0.50x input (except o3-mini).
To override at runtime, use --pricing with a JSON file. See LoadPricing.
func LoadPricing ¶
func LoadPricing(path string) (PricingTable, error)
type Querier ¶
type Querier interface {
Overview(ctx context.Context, filters Filters) (*Overview, error)
SessionDetail(ctx context.Context, sessionID string) (*SessionDetail, error)
}
Querier is an interface for querying session data. This allows for mock implementations in testing and sandboxes.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func (*Query) SessionDetail ¶
type SessionDetail ¶
type SessionDetail struct {
Summary SessionSummary `json:"summary"`
Messages []SessionMessage `json:"messages"`
GroupedMessages []SessionMessageGroup `json:"grouped_messages,omitempty"`
ToolFrequency map[string]int `json:"tool_frequency"`
SubSessions []SessionSummary `json:"sub_sessions,omitempty"`
}
type SessionMessage ¶
type SessionMessage struct {
Hash string `json:"hash"`
Role string `json:"role"`
Model string `json:"model"`
Timestamp time.Time `json:"timestamp"`
Delta time.Duration `json:"delta_ns"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
TotalTokens int64 `json:"total_tokens"`
InputCost float64 `json:"input_cost"`
OutputCost float64 `json:"output_cost"`
TotalCost float64 `json:"total_cost"`
ToolCalls []string `json:"tool_calls"`
Text string `json:"text"`
}
type SessionMessageGroup ¶
type SessionMessageGroup struct {
Role string `json:"role"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Delta time.Duration `json:"delta_ns"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
TotalTokens int64 `json:"total_tokens"`
InputCost float64 `json:"input_cost"`
OutputCost float64 `json:"output_cost"`
TotalCost float64 `json:"total_cost"`
ToolCalls []string `json:"tool_calls"`
Text string `json:"text"`
Count int `json:"count"`
StartIndex int `json:"start_index"`
EndIndex int `json:"end_index"`
}
type SessionSummary ¶
type SessionSummary struct {
ID string `json:"id"`
Label string `json:"label"`
Model string `json:"model"`
Project string `json:"project"`
AgentName string `json:"agent_name,omitempty"`
Status string `json:"status"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration_ns"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
InputCost float64 `json:"input_cost"`
OutputCost float64 `json:"output_cost"`
TotalCost float64 `json:"total_cost"`
ToolCalls int `json:"tool_calls"`
MessageCount int `json:"message_count"`
SessionCount int `json:"session_count,omitempty"`
}