accountant

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 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.

README

accountant

accountant is the context accountant: a Go library that keeps the books for a context optimizer. It says how many tokens each change to an LLM request saved or caused, for each billing tier.

A tool such as a context optimizer edits a request before it goes to the provider. It may shorten a tool output, remove unused tool declarations, or replace old messages with a summary. accountant answers one question for each change:

If this change had never been made, how would the provider have billed these tokens on this request?

The answer depends on the provider's prompt cache. A change inside a cached prefix can break the cache and cost more than it saves. accountant keeps that state for each conversation thread and prices every change in tokens for the input, cache write (5-minute and 1-hour) and cache read tiers. The host turns tokens into money with accountant.Figure and its own rates.

Use

The library is stateful, and Compute is deterministic. For each request:

  1. Trackers.BeginRequest takes the body the client sent.
  2. Request.Add records each change an operator reports (rewrite, spend, setting).
  3. Request.EndRequest takes the body that was forwarded and the cache facts.
  4. Request.Compute takes the billed Usage and returns a Result.
ts := accountant.NewTrackers()
r := ts.BeginRequest(accountant.RequestMeta{RequestID: "r2", Session: "s1", At: now}, client, clientBreakpoints)
r.Add(accountant.Operation{Kind: accountant.KindRewrite, ChangeID: "mask:1", At: at,
    SizeBefore: accountant.Size{Bytes: 8000}, SizeAfter: accountant.Size{Bytes: 1000}})
r.EndRequest(accountant.Thread{ID: "main"}, forwarded, forwardedBreakpoints, facts)
res := r.Compute(accountant.Usage{CacheRead: 4000, CacheWrite: 1000})
// res.Ops[0].Saved is a accountant.TierTokens

example_test.go is a complete program that runs under go test.

A change is reported once, on its first request. Compute applies it again on later requests until it ends, so one thread's result depends on the requests before it. Results fail open: a failed check goes into Result.Checks and is logged as a warning, and pricing goes on.

The module imports only the standard library, so any host can use it. boundary_test.go enforces that.

Layout

Path What it holds
accountant.go The whole public API: type aliases, constants and four functions
internal/engine/ The implementation and its unit tests. Not importable by hosts
test/cases/ The JSON cases and the loader (import "github.com/rossoctl/accountant/test/cases")
test/gen/ The Python generator that writes the cases
docs/ Specification, design, examples

Documents

Document What it holds
docs/spec.md The specification: words, requirements (R1 and on), scope
docs/design.md The design: types, Compute, cache effects, checks
docs/testing.md How the library is tested, and the exhaustive test-case list
docs/examples.md Eight worked examples with figures
docs/more_examples.md The plan for scenarios beyond the first eight, and which are written as cases
docs/issue_cases.md Test cases drawn from issues, and which are written as cases
docs/cached-prefix.md How providers decide what a cache read covers
docs/cortex-wiring.md How Cortex and context-guru plug it in
docs/metrics/metrics.md The metrics module: counters, labels and the Pricer contract
docs/events/events.md The events module (design): structural events for each request and ping, central collection

Test cases

test/ is the list of cases an implementation must meet: JSON files, each a sequence of requests with the expected Result. A host can play them through its own pricing code and compare. The cases are generated by test/gen/gen_cases.py (go generate ./test/cases), which computes the body hashes.

go vet ./...
go test ./...

Status

Pre-release (v0.x). The API follows the design in docs/design.md and may change between minor versions. RELEASING.md says how a version is made.

Not implemented yet. Compute adds no figure for these, and a zero there is not a measured zero:

  • Result.Interaction beyond the exact case of design §6.2. Compute sets it only on a rescued request with a client breakpoint and no SharedWarm, for a saved span at or before the ping's extent that the operations book at the read tier. Any other case adds zero.
  • The 20-block lookback (design §5.1), and the long-context tier.
  • A MessageSplice for whole tools or system blocks. A splice moves message positions only (design §4.3).

The full list is the "Not implemented" section of internal/engine/doc.go. Checks 2 (order) and 5 (attribution) are not missing: they are reserved numbers, not checks (design §6.5).

The Trackers hold about 10,000 threads and drop the oldest above that. A dropped thread loses its active changes (design §6.1, Memory).

License

Apache 2.0. See LICENSE.

Documentation

Overview

Package accountant is the context accountant: it tracks what a context optimizer saves. It prices the changes that the optimizer makes to an LLM request, in tokens for each billing tier.

A host calls it in four steps for each request. [Trackers.BeginRequest] takes the body the client sent. [Request.Add] records each change an operator reported. [Request.EndRequest] takes the body that was forwarded and the cache facts. [Request.Compute] takes the billed Usage and returns a Result: the tokens each change saved or caused. The host turns tokens into money. A keep-alive ping has no request record: use ComputeStandalone. PingOps builds its operations.

Building Usage from a response

Usage counts each token once, in one tier. [Usage.Input] is the uncached input only. Providers do not agree on this, so a host must convert before it calls Compute. Output and thinking tokens go in [CallUsage.Output], not in Usage.

Anthropic: the usage fields are already apart. Copy them.

Input        = usage.input_tokens                  (leaves out cached tokens)
CacheRead    = usage.cache_read_input_tokens
CacheWrite   = usage.cache_creation_input_tokens   (all lifetimes)
CacheWrite1h = usage.cache_creation.ephemeral_1h_input_tokens

Example: input_tokens 50, cache_read 8,000, cache_creation 1,200 of which 1,000 are 1h gives Usage{Input: 50, CacheRead: 8000, CacheWrite: 1200, CacheWrite1h: 1000}.

OpenAI: prompt_tokens (Responses API: input_tokens) includes the cached tokens. Subtract them.

CacheRead  = usage.prompt_tokens_details.cached_tokens   (Responses API: input_tokens_details.cached_tokens)
CacheWrite = usage.cache_write_tokens              (GPT-5.6 and later; 0 before)
Input      = usage.prompt_tokens - CacheRead - CacheWrite   (CacheWrite is 0 before GPT-5.6)

Example: prompt_tokens 9,000, cached_tokens 8,000, no writes gives Usage{Input: 1000, CacheRead: 8000}. If Input is not reduced, the 8,000 cached tokens count twice. No check reports this: the ratio and every saving come out too high, so the host must subtract. Limits: this rule assumes that prompt_tokens includes the write tokens, which docs/ does not yet state. Usage has no 12-hour tier. Put all writes in CacheWrite and leave CacheWrite1h at 0. The library books a write by the TTL of the Breakpoint, not by CacheWrite1h: only "1h" reaches the long tier. The 2.5x price of a 12-hour write has no tier, so that extra price is not tracked.

Gemini (not yet recorded in docs/cached-prefix.md): promptTokenCount includes the cached tokens. Subtract them.

CacheRead = usageMetadata.cachedContentTokenCount
Input     = usageMetadata.promptTokenCount - CacheRead

Example: promptTokenCount 9,000, cachedContentTokenCount 8,000 gives Usage{Input: 1000, CacheRead: 8000}. Gemini bills no cache write per request, so CacheWrite is 0.

The module imports only the standard library. Its design is in docs/design.md, and a complete program is in the package example.

This file is the whole public API. The implementation is in internal/engine, with the state it keeps for each thread; none of that is part of the API.

Example

An operator shortens a tool output from 8,000 bytes to 1,000 on the second request. The first two messages are already cached, so they are read in both bills. The new message would have been written to the cache, so the saving is the tokens it did not write, at the 5-minute write tier.

package main

import (
	"fmt"
	"strings"
	"time"

	"github.com/rossoctl/accountant"
)

// body hashes one request body: one entry per message, in order.
func body(sizes ...int) accountant.Body {
	msgs := make([][]byte, len(sizes))
	for i, n := range sizes {
		msgs[i] = []byte(fmt.Sprintf("m%d", i) + strings.Repeat(".", n))
	}
	return accountant.NewBody(nil, nil, msgs)
}

// An operator shortens a tool output from 8,000 bytes to 1,000 on the second request. The first
// two messages are already cached, so they are read in both bills. The new message would have been
// written to the cache, so the saving is the tokens it did not write, at the 5-minute write tier.
func main() {
	ts := accountant.NewTrackers()
	t0 := time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC)
	facts := accountant.EntryFacts{TTL: 5 * time.Minute, Lifetime: accountant.LifetimeExact}
	thread := accountant.Thread{ID: "main"}
	last := accountant.Position{Section: accountant.SectionMessages, Index: 1}

	// Request 1: nothing changed, the provider wrote the cache.
	first := body(2000, 2000)
	r1 := ts.BeginRequest(accountant.RequestMeta{RequestID: "r1", Session: "s1", At: t0}, first,
		[]accountant.Breakpoint{{Pos: last, TTL: "5m"}})
	r1.EndRequest(thread, first, []accountant.Breakpoint{{Pos: last, TTL: "5m"}}, facts)
	r1.Compute(accountant.Usage{CacheWrite: 4000})

	// Request 2: the client sent 8,000 bytes at message 2; an operator forwarded 1,000.
	client, forwarded := body(2000, 2000, 8000), body(2000, 2000, 1000)
	at := accountant.Position{Section: accountant.SectionMessages, Index: 2}
	r2 := ts.BeginRequest(accountant.RequestMeta{RequestID: "r2", Session: "s1", At: t0.Add(10 * time.Second)},
		client, []accountant.Breakpoint{{Pos: at, TTL: "5m"}})
	r2.Add(accountant.Operation{ID: "op1", Kind: accountant.KindRewrite, Operator: "mask", ChangeID: "mask:1", At: at,
		SizeBefore: accountant.Size{Bytes: 8000}, SizeAfter: accountant.Size{Bytes: 1000}})
	r2.EndRequest(thread, forwarded, []accountant.Breakpoint{{Pos: at, TTL: "5m"}}, facts)
	res := r2.Compute(accountant.Usage{CacheRead: 4000, CacheWrite: 1000})

	p := res.Ops[0]
	fmt.Printf("saved %+v\ncaused %+v\nchecks %d\n", p.Saved, p.Caused, len(res.Checks))
}
Output:
saved {Input:0 CacheWrite5m:6992 CacheWrite1h:0 CacheRead:0}
caused {Input:0 CacheWrite5m:0 CacheWrite1h:0 CacheRead:0}
checks 0

Index

Examples

Constants

View Source
const (
	TierInput        = engine.TierInput
	TierCacheRead    = engine.TierCacheRead
	TierCacheWrite5m = engine.TierCacheWrite5m
	TierCacheWrite1h = engine.TierCacheWrite1h
	TierOutput       = engine.TierOutput

	DirSaved = engine.DirSaved
	DirAdded = engine.DirAdded
)
View Source
const (
	WithheldCheckSum          = engine.WithheldCheckSum
	WithheldCheckUniqueChange = engine.WithheldCheckUniqueChange
	WithheldCheckSpans        = engine.WithheldCheckSpans
	WithheldCheckOther        = engine.WithheldCheckOther
	WithheldUnpriced          = engine.WithheldUnpriced
	WithheldSizeUnknown       = engine.WithheldSizeUnknown
	WithheldImplausibleSize   = engine.WithheldImplausibleSize

	// SizeNotGiven is the legacy tokensBefore of a host with no measure of the request size: [Withhold]
	// skips the size gate.
	//
	// Deprecated: call Withhold(res) and the library measures the size.
	SizeNotGiven = engine.SizeNotGiven
)

The reasons Withhold returns.

View Source
const (
	KindRewrite = engine.KindRewrite
	KindSpend   = engine.KindSpend
	KindSetting = engine.KindSetting

	SectionTools    = engine.SectionTools
	SectionSystem   = engine.SectionSystem
	SectionMessages = engine.SectionMessages

	PhaseHot     = engine.PhaseHot
	PhaseCold    = engine.PhaseCold
	PhaseUnknown = engine.PhaseUnknown

	LifetimeExact   = engine.LifetimeExact
	LifetimeMinimum = engine.LifetimeMinimum
	LifetimeUnknown = engine.LifetimeUnknown

	BillingAPI          = engine.BillingAPI
	BillingSubscription = engine.BillingSubscription
	BillingUnknown      = engine.BillingUnknown

	EffectBreak       = engine.EffectBreak
	EffectRescue      = engine.EffectRescue
	EffectSplit       = engine.EffectSplit
	EffectTTLPremium  = engine.EffectTTLPremium
	EffectTTLRescue   = engine.EffectTTLRescue
	EffectMarkPremium = engine.EffectMarkPremium
	EffectMarkPayback = engine.EffectMarkPayback

	CauseModelChanged = engine.CauseModelChanged

	CompactionManual  = engine.CompactionManual
	CompactionAuto    = engine.CompactionAuto
	CompactionUnknown = engine.CompactionUnknown
)
View Source
const (
	CheckSum          = engine.CheckSum
	CheckUniqueChange = engine.CheckUniqueChange
	CheckSpans        = engine.CheckSpans
	CheckConservation = engine.CheckConservation
	CheckSharedWarm   = engine.CheckSharedWarm
	CheckBadUsage     = engine.CheckBadUsage
	CheckRatioRange   = engine.CheckRatioRange
	CheckBreakpoints  = engine.CheckBreakpoints
	CheckMediaUnseen  = engine.CheckMediaUnseen
	CheckMediaTokens  = engine.CheckMediaTokens
	CheckSizeTokens   = engine.CheckSizeTokens
	CheckSizeRange    = engine.CheckSizeRange
	CheckOpaqueTokens = engine.CheckOpaqueTokens
)

Names of the checks in CheckFailure.Check.

View Source
const (
	UnitBytes  = engine.UnitBytes
	UnitTokens = engine.UnitTokens
)

Units of CheckFailure.Unit.

View Source
const (
	ReasonEndRequestMissing = engine.ReasonEndRequestMissing
	ReasonPingResultUnknown = engine.ReasonPingResultUnknown
	ReasonUnknownKind       = engine.ReasonUnknownKind
	ReasonNegativeSize      = engine.ReasonNegativeSize
	ReasonPenaltyUnknown    = engine.ReasonPenaltyUnknown
	ReasonNoUsage           = engine.ReasonNoUsage
	ReasonNotSpend          = engine.ReasonNotSpend
	ReasonBadUsage          = engine.ReasonBadUsage
	ReasonRatioRange        = engine.ReasonRatioRange
	ReasonMediaUnseen       = engine.ReasonMediaUnseen
	ReasonMediaTokens       = engine.ReasonMediaTokens
	ReasonBreakpoints       = engine.ReasonBreakpoints
	ReasonSizeRange         = engine.ReasonSizeRange
)

Machine-stable reasons in Result.Unpriced.

View Source
const RulesVersion = engine.RulesVersion

RulesVersion is the version of the accountant rules (R46). Result.Version and RemovalFigure.Version carry it. It stays 1 with the Ratio API: the Ratio path is opt-in, and a nil Ratio changes no figure.

Variables

This section is empty.

Functions

func AvoidedMissesUSD added in v0.11.0

func AvoidedMissesUSD(n int64, missUSD float64) float64

AvoidedMissesUSD is the dollars saved when n misses do not happen: n x missUSD, never negative.

func LatePingCost added in v0.11.0

func LatePingCost(in LatePingInput, p SizedPricer) (usd float64, estimated bool)

LatePingCost is the dollars of a ping that arrives after its entry expired: it writes the prefix. See LatePingInput.

func MissCost added in v0.11.0

func MissCost(in MissInput, p SizedPricer) (usd float64, estimated bool)

MissCost is the extra dollars of one cache miss over a hit, never negative. See MissInput.

func OpaqueKey added in v0.2.0

func OpaqueKey(s string) uint64

OpaqueKey is the key under which a host stores the token count of one thinking signature, or of the data string of a redacted_thinking block.

func PingCost added in v0.11.0

func PingCost(in PingInput, p SizedPricer) (usd float64, estimated bool)

PingCost is the dollars of one keep-alive ping, at the rates of its own prompt size. 0 with estimated true means the rate is unknown. See PingInput.

func PingOps added in v0.1.1

func PingOps(p Ping, b Billing) (RequestOps, PingFacts)

PingOps turns a keep-alive Ping into a RequestOps with one spend, for ComputeStandalone, and returns the PingFacts the thread's next real request passes in EntryFacts.

func PingWindowID added in v0.4.0

func PingWindowID(thread string, start time.Time) string

PingWindowID gives the id of the keep-alive window that starts at start on thread: the ChangeID of the ping's spend, PingFacts.PingWindow, and the change of the rescue on the thread's next request. The thread "" becomes "main". Use it for a ping that PingOps does not see, such as a refused one, so the host does not copy the rule. It does not check start: a zero start gives "ka:<thread>:0001-01-01T00:00:00Z".

func RequestCost added in v0.11.0

func RequestCost(in RequestCostInput, p SizedPricer) (usd float64, estimated bool)

RequestCost is the dollars of one billed request, at the rates of its prompt size. See RequestCostInput.

func SplitOpaqueTokens added in v0.2.0

func SplitOpaqueTokens(opaques []string, tokens int) []int

SplitOpaqueTokens splits the thinking tokens of one response between the thinking blocks it made, in proportion to the length of their signatures. The parts add up to tokens.

func Withhold added in v0.9.0

func Withhold(res Result, tokensBefore ...int) string

Withhold returns the first gate a Result fails, or "" when a host may book its savings. With a reason, the host books no saving for the request, only the calls of its spends.

Call it as Withhold(res). The size bound then uses the library's own measure of the client messages ([Result.MessageTokens]) and counts message tokens only, so a removed tool declaration does not trip it. The optional size is the legacy form: the size of the body the client sent, by the host's own measure, or SizeNotGiven, which skips the size bound. The optional size is deprecated: a variadic cannot carry its own marker, so new code must not pass it. See docs/design.md §6.7.

Types

type Billing

type Billing = engine.Billing

What a host reports.

func BillingFrom added in v0.3.0

func BillingFrom(h http.Header) Billing

BillingFrom reads the client's upstream credential header (x-api-key or Authorization, as the request arrived, before any plugin rewrites it) and returns the Billing it implies: an API key gives BillingAPI; an OAuth token from a subscription login gives BillingSubscription; anything else, or no credential, gives BillingUnknown. It reads only the credential's type and returns no part of the credential (R2). Cortex and the context-guru proxy both call this, so the two hosts share one rule (design §7.1).

type BillingMode

type BillingMode = engine.BillingMode

Parts of an operation.

type Body

type Body = engine.Body

What a host reports.

func NewBody

func NewBody(tools, system, messages [][]byte) Body

NewBody hashes the content of one request body, one entry for each position of each section.

func NewBodyCounted added in v0.2.0

func NewBodyCounted(tools, system, messages [][]byte, count OpaqueCount) Body

NewBodyCounted is NewBody with the host's token count for each thinking block (design D16). It looks up each signature, and each redacted_thinking data string, by its OpaqueKey. A block with no count keeps the fixed price.

type Breakpoint

type Breakpoint = engine.Breakpoint

What a host reports.

type CacheEffect

type CacheEffect = engine.CacheEffect

What the library returns.

type CacheEffectCause

type CacheEffectCause = engine.CacheEffectCause

Parts of an operation.

type CacheEffectKind

type CacheEffectKind = engine.CacheEffectKind

Parts of an operation.

type CachePhase

type CachePhase = engine.CachePhase

Parts of an operation.

type CallUsage

type CallUsage = engine.CallUsage

What a host reports.

type CheckFailure

type CheckFailure = engine.CheckFailure

What the library returns.

type CompactionRecord added in v0.1.1

type CompactionRecord = engine.CompactionRecord

What the library returns.

type CompactionTrigger added in v0.1.1

type CompactionTrigger = engine.CompactionTrigger

Parts of an operation.

type EntryFacts

type EntryFacts = engine.EntryFacts

What a host reports.

type FigureInput added in v0.9.0

type FigureInput = engine.FigureInput

FigureInput is the billed usage and the Result that Figure prices.

type Kind

type Kind = engine.Kind

Parts of an operation.

type LatePingInput added in v0.11.0

type LatePingInput = engine.LatePingInput

LatePingInput is a ping that fires after its entry expired.

type LifetimeKind

type LifetimeKind = engine.LifetimeKind

Parts of an operation.

type MessageSplice

type MessageSplice = engine.MessageSplice

Parts of an operation.

type MissInput added in v0.11.0

type MissInput = engine.MissInput

MissInput is one cache miss on a prefix.

type ModelCall

type ModelCall = engine.ModelCall

What a host reports.

type OpaqueCount added in v0.2.0

type OpaqueCount = engine.OpaqueCount

What a host reports.

type Operation

type Operation = engine.Operation

What a host reports.

type Ping added in v0.1.1

type Ping = engine.Ping

What a host reports.

type PingFacts added in v0.1.1

type PingFacts = engine.PingFacts

What a host reports.

type PingInput added in v0.11.0

type PingInput = engine.PingInput

PingInput is one keep-alive ping: the prefix it reads, the fresh input it carries and its output.

type Position

type Position = engine.Position

Parts of an operation.

func SharedWarmFrom added in v0.1.1

func SharedWarmFrom(fwd Body, siblings []Sibling) *Position

SharedWarmFrom returns the EntryFacts.SharedWarm of a request that forwarded fwd: the last position that one of the siblings kept warm (R54). The host chooses the Sibling list.

type PricedOp

type PricedOp = engine.PricedOp

What the library returns.

type Provider added in v0.1.1

type Provider = engine.Provider

What a host reports.

type Ratio added in v0.12.0

type Ratio = engine.Ratio

Ratio is the request's own tokens-per-byte ratio: see NewRatio and Result.Ratio. Result.Ratio is nil when nothing was priced, and also when the ratio is not in range.

func NewRatio added in v0.12.0

func NewRatio(billed int, forwarded Body) Ratio

NewRatio builds the ratio of a body that the provider billed for billed prompt tokens (input plus cache read plus cache write). It is the ratio [Request.Compute] builds for the request, so a host never writes the conversion again. See docs/design.md §4.2 rule 7.

func RatioFromText added in v0.12.0

func RatioFromText(tokens, bytes int, capped bool) Ratio

RatioFromText rebuilds a text Ratio from the counts [Ratio.Text] and [Ratio.Capped] returned, such as a host stored.

type RemovalFigure added in v0.11.0

type RemovalFigure = engine.RemovalFigure

RemovalFigure is the saving of such a change in dollars.

func RemovalSaving added in v0.11.0

func RemovalSaving(in RemovalInput, p SizedPricer) RemovalFigure

RemovalSaving prices a change that took tokens out of the head of a request, such as a tool declaration filter or a tool deferral. The host's tokenizer factor is applied once when Ratio is nil. With a Ratio the tokens are the provider's, the factor is 1 and Factor is ignored. See docs/design.md §6.6.

type RemovalInput added in v0.11.0

type RemovalInput = engine.RemovalInput

RemovalInput is a change that took tokens out of the head of a request.

type Request

type Request = engine.Request

Request is the record of one request, made by [Trackers.BeginRequest].

type RequestCostInput added in v0.11.0

type RequestCostInput = engine.RequestCostInput

RequestCostInput is the billed usage of one request.

type RequestMeta

type RequestMeta = engine.RequestMeta

What a host reports.

type RequestOps

type RequestOps = engine.RequestOps

What a host reports.

type Result

type Result = engine.Result

Result is what [Request.Compute] returns.

func ComputeStandalone

func ComputeStandalone(ops RequestOps) Result

ComputeStandalone prices operations that have no request record, such as a keep-alive ping.

type Section

type Section = engine.Section

Parts of an operation.

type SettingChange

type SettingChange = engine.SettingChange

Parts of an operation.

type Sibling added in v0.1.1

type Sibling = engine.Sibling

What a host reports.

type Size

type Size = engine.Size

Parts of an operation.

type SizedPricer added in v0.9.0

type SizedPricer = engine.SizedPricer

SizedPricer is the host's rate table: a rate for one token, at the prompt size of its request.

type Span

type Span = engine.Span

Parts of an operation.

type Thread

type Thread = engine.Thread

What a host reports.

type Tier added in v0.9.0

type Tier = engine.Tier

Tier is a price class of tokens.

func HeadTier added in v0.11.0

func HeadTier(u Usage) Tier

HeadTier is the tier the head of a request's prefix was billed at, from its usage.

type TierTokens

type TierTokens = engine.TierTokens

What the library returns.

type Trackers

type Trackers = engine.Trackers

Trackers holds the state of every thread. Make one with NewTrackers, and share it.

func NewTrackers

func NewTrackers() *Trackers

NewTrackers returns an empty set: every thread starts with no history.

type USDEffect added in v0.9.0

type USDEffect = engine.USDEffect

USDEffect is one priced cache effect.

type USDFigure added in v0.9.0

type USDFigure = engine.USDFigure

USDFigure is the savings of one request in dollars.

func Figure added in v0.9.0

func Figure(in FigureInput, p SizedPricer) USDFigure

Figure turns a Result into dollars: for each operation, the effects, the breaks and the re-rate of the tokens that stay when the request crosses a price line. It is deterministic and does no I/O. See USDFigure for the fields, and docs/design.md for the rules.

type USDLine added in v0.9.0

type USDLine = engine.USDLine

USDLine is one priced amount of one operation in one tier.

type Unpriced

type Unpriced = engine.Unpriced

What the library returns.

type Usage

type Usage = engine.Usage

What a host reports.

Directories

Path Synopsis
events module
host module
internal
engine
Package engine is the implementation of package accountant, which re-exports its public names.
Package engine is the implementation of package accountant, which re-exports its public names.
metrics module
test
cases
Package cases is the exhaustive list of test cases the implementation must meet (testing.md §10).
Package cases is the exhaustive list of test cases the implementation must meet (testing.md §10).

Jump to

Keyboard shortcuts

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