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, upstreamOrigin *url.URL, httpClient *http.Client) (*UsageLedger, error)
OpenUsageLedger creates the usage tables when absent. httpClient reads OpenAI's daily token history for the accounts in dataDirectory from upstreamOrigin.
func (*UsageLedger) ReadUsage ¶ added in v0.1.1
func (ledger *UsageLedger) ReadUsage(ctx context.Context, accountKeys []string) ([]*menupb.ReportingPeriod, []*menupb.AccountDay, *menupb.ProxyActivity, error)
ReadUsage imports changed session bytes once and reads all usage figures from one incremental fold. Returned reports belong to the caller.
func (*UsageLedger) Run ¶
func (ledger *UsageLedger) Run(ctx context.Context)
Run refreshes OpenAI's per-account report every ten minutes until ctx ends, so a slow OpenAI read never delays the local totals.
Source Files
¶
- account_attribution.go
- api_equivalent_price.go
- claude_price.go
- claude_response.go
- claude_task_titles.go
- codex_session_index.go
- codex_session_reader.go
- completion_reconciliation.go
- incremental_rows.go
- local_task_titles.go
- openai_daily_token_history_refresh.go
- openai_daily_token_history_store.go
- pi_session_changes.go
- pi_session_reader.go
- reporting_periods.go
- routed_work.go
- session_title_store.go
- session_usage_store.go
- session_usage_types.go
- task_totals.go
- task_usage_totals.go
- usage_fold.go
- usage_ledger.go
- usage_reports.go