usage

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL