Documentation
¶
Overview ¶
Package cost keeps the prompt-cache ledger per thread and model and prices a switch in uncached tokens, with USD only when a model has list prices. Codex's cache is per model and effort-neutral (research spikes 3 and 5).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
Cache is the warmth rule: a model is warm from its last response until TTL minus WarmMargin has passed.
type CacheState ¶
CacheState is what the ledger remembers per thread and model.
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
Ledger remembers, per thread, each model's cached prefix and the model the thread last ran on. Keys ignore effort: Codex's cache is effort-neutral. A detour to another model does not evict the previous model's entry. Safe for concurrent use.
func (*Ledger) Observe ¶
Observe records a completed response on model: its whole input is now the model's cached prefix, and model becomes the thread's current model.
func (*Ledger) SwitchTax ¶
SwitchTax is how many more uncached input tokens the thread's next request, of tokens context tokens, writes on candidate than on the thread's current model. A warm model pays only what its cached prefix lacks; a cold one pays all tokens. It is 0 for the current model, for a candidate warm on at least the current model's prefix, and when the current model is cold or unknown, since staying then protects nothing.
The tax is relative to staying, not the candidate's absolute uncached tokens: the part both models must write is paid either way and must not raise the switch bar.