usage

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 5 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 splits a project's token use the ways that show where it went (#417): input, cached input, output and reasoning, per model, per task and per attempt, with the retries apart. `orch report usage` and the dashboard's /api/usage read the same Build, so the two cannot disagree.

These are orch's own records of what each dispatch reported, in this project. They are not the provider's subscription quota (a ChatGPT or Claude plan's 5-hour window), which other projects and interactive use share; Quota carries that plan quota as claude and codex last reported it (#577). orch's budget guardrail is its own, per-project limit on these numbers unless a budget says `source: provider`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddQuota added in v0.31.0

func AddQuota(ctx context.Context, u *Usage, r QuotaReader) error

AddQuota fills u.Quota with the newest report of each backend that spent.

Types

type Attempt

type Attempt struct {
	Attempt int `json:"attempt"`
	Tokens
}

Attempt is one attempt of a task. Attempt 0 holds rows written before orch recorded attempts.

type Model

type Model struct {
	Backend string `json:"backend"`
	Model   string `json:"model"`
	Tokens
}

Model is one backend and model's use.

type PlanQuota added in v0.31.0

type PlanQuota struct {
	Backend string              `json:"backend"`
	Windows []state.QuotaWindow `json:"windows"`
	SeenAt  string              `json:"seen_at"`
}

PlanQuota is one backend's subscription windows as its CLI last reported them (claude's rate_limit_event, codex's session rollout), as of SeenAt.

type QuotaReader added in v0.31.0

type QuotaReader interface {
	LatestQuota(ctx context.Context, backend string) (state.ProviderQuota, bool, error)
}

QuotaReader is the slice of the state backend AddQuota reads.

type Task

type Task struct {
	TaskID   string    `json:"task_id"`
	Attempts []Attempt `json:"attempts"`
	// RetryTokens is what attempts after the first used.
	RetryTokens int `json:"retry_tokens"`
	Tokens
}

Task is one task's use, attempt by attempt.

type Tokens

type Tokens struct {
	Dispatches int `json:"dispatches"`
	// Input is fresh input: what the dispatches sent that the prompt cache
	// did not hold.
	Input int `json:"input"`
	// CachedInput is input read back from the prompt cache — context the
	// agent re-read, cheaper per token but often most of them.
	CachedInput int `json:"cached_input"`
	CacheWrite  int `json:"cache_write"`
	// Output includes Reasoning.
	Output    int     `json:"output"`
	Reasoning int     `json:"reasoning"`
	CostUSD   float64 `json:"cost_usd"`
	// Estimated is true when some rows' counts were inferred because the CLI
	// reported none.
	Estimated bool `json:"estimated"`
}

Tokens is what a set of dispatches used.

func (Tokens) Total

func (t Tokens) Total() int

Total is every token, input of all kinds and output.

type Usage

type Usage struct {
	Total       Tokens  `json:"total"`
	RetryTokens int     `json:"retry_tokens"`
	ByModel     []Model `json:"by_model"`
	ByTask      []Task  `json:"by_task"`
	// Quota is the plan quota each backend's CLI last reported, the whole
	// account's, sorted by backend; filled by AddQuota, nil before.
	Quota []PlanQuota `json:"quota,omitempty"`
}

Usage is the whole breakdown. ByModel and ByTask lead with the heaviest.

func Build

func Build(rows []state.Spend) Usage

Build splits rows, a project's spend.

Jump to

Keyboard shortcuts

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