usage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package usage turns the audit log's real, per-call judge token usage into a cost report - both judges this project has: the text provenance judge (internal/provenance, PROVENANCE_JUDGE_USAGE entries) and the screenshot-reasoning one (internal/visualprovenance, VISUAL_PROVENANCE_JUDGE_USAGE entries).

This is the first concrete slice of the metered-judge paid layer: real usage accounting from real API responses, not yet real billing. The point is to have a genuine, working answer to "here's how this would actually be billed" before any billing integration exists - the same "prove the mechanism standalone before wiring it into anything" pattern this project has used everywhere else (biscuit-go, the Anthropic SDK, Vault dynamic secrets all got a throwaway validation step before being built on top of).

One pricing rate covers both judges, deliberately not two: Anthropic bills image content as regular input tokens (confirmed against the real API response when internal/visualprovenance was validated - a screenshot simply produces a larger input_tokens count, not a different billing field), so the per-token rate below is the whole story for either judge. What differs is the token VOLUME per call, which the real numbers below already capture without needing a second rate.

Like internal/compliance, this is a single pass over the audit log - the append-only source of truth - not a running counter kept in memory, so a report generated at any point reflects real historical usage rather than only what happened to occur since the process last restarted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DayUsage

type DayUsage struct {
	Invocations   int     `json:"invocations"`
	InputTokens   int64   `json:"input_tokens"`
	OutputTokens  int64   `json:"output_tokens"`
	EstimatedCost float64 `json:"estimated_cost_usd"`
}

type JudgeUsage

type JudgeUsage struct {
	TotalInvocations int     `json:"total_invocations"`
	TotalErrors      int     `json:"total_errors"`
	InputTokens      int64   `json:"input_tokens"`
	OutputTokens     int64   `json:"output_tokens"`
	EstimatedCostUSD float64 `json:"estimated_cost_usd"`

	ByTool map[string]*ToolUsage `json:"by_tool"`
	ByDay  map[string]*DayUsage  `json:"by_day"`
}

JudgeUsage is real invocation counts and real token totals from real API responses, for one judge - text or visual - with an estimated dollar cost computed from the named, cited rate above, never presented as more precise than "estimated."

func (JudgeUsage) SortedDays

func (j JudgeUsage) SortedDays() []string

SortedDays returns ByDay's keys in chronological order, for a report that reads front-to-back rather than in random map order.

type Report

type Report struct {
	PricingNote string     `json:"pricing_note"`
	Text        JudgeUsage `json:"text_judge"`
	Visual      JudgeUsage `json:"visual_judge"`
}

func Generate

func Generate(auditLogPath string) (Report, error)

Generate reads the audit log once and tallies both judges' usage/error entries (see internal/handler's assessProvenance and assessVisualProvenance for exactly what gets written). Malformed lines are skipped, not fatal - the audit log is append-only and long-running; one bad line (a truncated write mid-crash, say) shouldn't take the whole report down.

type ToolUsage

type ToolUsage struct {
	Invocations   int     `json:"invocations"`
	InputTokens   int64   `json:"input_tokens"`
	OutputTokens  int64   `json:"output_tokens"`
	EstimatedCost float64 `json:"estimated_cost_usd"`
}

Jump to

Keyboard shortcuts

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