usage

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 32 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) 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.

Jump to

Keyboard shortcuts

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