Documentation
¶
Overview ¶
Package usage answers how many tokens each account and each task used, and what that work would cost at the provider's API prices.
Account totals come from OpenAI's own per-account report, which counts every machine and ChatGPT Work on the web. Task totals come from what this Mac saw: local Codex and Pi session history joined with the responses the relay recorded. Claude account and task totals use the same served responses. It keeps its own tables in the store's database.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClaudeResponseUsage ¶
type ClaudeResponseUsage struct {
// contains filtered or unexported fields
}
ClaudeResponseUsage reads accounting fields from native Messages API payloads. Content and tool arguments never enter the ledger.
func NewClaudeResponseUsage ¶
func NewClaudeResponseUsage(model, speed, inferenceGeo string) *ClaudeResponseUsage
func (*ClaudeResponseUsage) Observe ¶
func (observation *ClaudeResponseUsage) Observe(payload []byte) (bool, error)
Observe accepts a JSON response or one SSE data payload. Delta counts are cumulative; omitted fields retain the value from message_start.
func (*ClaudeResponseUsage) Record ¶
func (observation *ClaudeResponseUsage) Record(taskID store.TaskID, account store.AccountName, completedAt time.Time) (store.CompletedResponseRecord, error)
Record normalises Anthropic's disjoint input categories into the shared ledger's inclusive input count, preserving the cache subsets.
type UsageLedger ¶
type UsageLedger struct {
// contains filtered or unexported fields
}
func OpenUsageLedger ¶
func OpenUsageLedger(database *store.StoreDatabase, dataDirectory string, httpClient *http.Client) (*UsageLedger, error)
OpenUsageLedger creates the usage tables when absent. httpClient reads OpenAI's daily token history for the accounts in dataDirectory.
func (*UsageLedger) ReadRoutedWork ¶
func (ledger *UsageLedger) ReadRoutedWork(accountKeys []string) (*menupb.ProxyActivity, error)
ReadRoutedWork reports today's work through this proxy: requests, replies and tokens per account, and the ten most recent tasks. accountKeys lists the pool accounts, which appear even when idle.
func (*UsageLedger) Run ¶
func (ledger *UsageLedger) Run(ctx context.Context)
Run refreshes OpenAI's per-account report once a minute until ctx ends, so a slow OpenAI read never delays the local totals.
func (*UsageLedger) TotalUsage ¶
func (ledger *UsageLedger) TotalUsage(ctx context.Context) ([]*menupb.ReportingPeriod, []*menupb.AccountDay, error)
TotalUsage scans local Codex and Pi session history, joins it with the responses the proxy recorded and OpenAI's per-account report, and totals Today, 7 Days and 30 Days by account and by task, and each account's usage on each of the last 30 UTC dates, oldest first.
Source Files
¶
- account_attribution.go
- api_equivalent_price.go
- claude_price.go
- claude_response.go
- claude_task_titles.go
- codex_session_reader.go
- completion_reconciliation.go
- local_task_titles.go
- openai_daily_token_history_refresh.go
- openai_daily_token_history_store.go
- pi_session_reader.go
- reporting_periods.go
- routed_work.go
- session_usage_store.go
- session_usage_types.go
- task_totals.go
- task_usage_totals.go
- usage_ledger.go