toolusage

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 4 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 toolusage extracts metering evidence from one upstream response.

Index

Constants

View Source
const (
	SourceVendorReported  = "vendor_reported"
	SourceResponseDerived = "response_derived"
)
View Source
const MaxCount int64 = 1 << 50

MaxCount bounds upstream counters before they can become price multipliers.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheUsage

type CacheUsage struct {
	CacheReadTokens        int64
	CacheCreationTokens    int64
	CacheCreation5mTokens  int64
	CacheCreation1hTokens  int64
	CacheCreation12hTokens int64
}

CacheCreationTokens includes all TTLs. The unclassified remainder uses the ordinary write price (30m for OpenAI). Gemini reads are a subset of input.

func ExtractCacheUsage

func ExtractCacheUsage(raw []byte) CacheUsage

ExtractCacheUsage reads one JSON/SSE frame or a standalone usage object. Malformed counters are ignored individually, preserving valid sibling fields.

func ExtractCacheUsageObject

func ExtractCacheUsageObject(r map[string]any) CacheUsage

ExtractCacheUsageObject accepts an already decoded response or usage container (UseNumber).

type ToolUsageItem

type ToolUsageItem struct {
	Tool     string `json:"tool"`
	Unit     string `json:"unit"`
	Quantity int64  `json:"quantity"`
	Source   string `json:"source,omitempty"`
}

ToolUsageItem contains only normalized labels and a quantity, never vendor text.

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker's zero value is ready for a single response, including its stream.

func (*Tracker) Observe

func (t *Tracker) Observe(raw []byte)

Observe consumes one response object or SSE event. Tool declarations and client functions supply no evidence of a hosted invocation.

func (*Tracker) ObserveObject

func (t *Tracker) ObserveObject(event map[string]any)

ObserveObject accepts an already decoded upstream event (UseNumber).

func (*Tracker) Snapshot

func (t *Tracker) Snapshot() []ToolUsageItem

Snapshot returns detached quantities in a stable order. A vendor-reported zero stays visible and takes precedence over all observed response items.

Jump to

Keyboard shortcuts

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