providerusage

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 1 Imported by: ? 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 providerusage reads the token tiers out of a provider's `usage` block.

One rule, one place. Four hosts need it (the proxy, the keep-alive keeper, the cheap-model clients and the transcript reader), and each used to keep its own copy. The copies handled different dialects, so a gap showed up as a silent zero, not as an error.

This package reads ONE block. It does not read a stream: the proxy merges the blocks of a server-sent-event stream itself, because that is transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Present

func Present(v gjson.Result) bool

Present reports whether a usage block is there: an object with at least one field. A JSON null or `{}` is absent, not a block in an unknown dialect. The proxy and agent/bob both use this rule, so the two always pick the same stream chunk.

Types

type Tiers

type Tiers struct {
	FreshInput   int64
	CacheRead    int64
	CacheWrite   int64
	CacheWrite1h int64
	Output       int64
}

Tiers is one response's billed token counts.

FreshInput, CacheRead and CacheWrite are disjoint. CacheWrite1h is a SUBSET of CacheWrite, never an addition to it.

func Parse

func Parse(u gjson.Result) (t Tiers, ok bool)

Parse reads a `usage` object. ok is false when the object has no field of a known dialect.

Dialects:

Anthropic        input_tokens (fresh only), cache_read_input_tokens,
                 cache_creation_input_tokens, cache_creation.ephemeral_1h_input_tokens
OpenAI Responses input_tokens (includes cache), input_tokens_details.{cached_tokens,
                 cache_write_tokens}
OpenAI chat      prompt_tokens (includes cache), prompt_tokens_details.cached_tokens
Output only      output_tokens alone. Anthropic's streaming message_delta carries exactly
                 this, and it holds the final completion count.

OpenAI counts cached tokens INSIDE its input total, so fresh is the difference. Anthropic reports the tiers apart. Reading one as the other double-counts the whole transcript.

func (Tiers) Zero

func (t Tiers) Zero() bool

Zero reports whether every count is zero.

Jump to

Keyboard shortcuts

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