pricing

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFileName = "defaults_llm_pricing.yaml"

DefaultFileName is the basename probed under management's datadir when AgentNetwork.PricingDefaultsFile doesn't configure an explicit path.

View Source
const ReloadInterval = time.Minute

ReloadInterval is the cadence at which the pricing file's mtime is polled for changes.

Variables

This section is empty.

Functions

func DefaultTable

func DefaultTable() map[string]map[string]Entry

DefaultTable returns the current default pricing table keyed surface -> model -> Entry: the management-side defaults file (see LoadFile / StartReloader) when one is loaded, merged over the compiled-in catalog table, which alone serves as the fallback when no file exists. The snapshot may change between calls as the file is re-read — consumers (the synthesizer on every reconcile, the catalog endpoint on every request) pick up fresh rates automatically. Callers must not mutate the returned maps.

func LoadFile

func LoadFile(path string, required bool) error

LoadFile loads the management-side pricing defaults file and makes it the live table (merged entry-whole over the compiled-in fallback; see DefaultTable). The path stays registered for the periodic reloader, so later edits — or the file (re)appearing after deletion — are picked up without a restart.

required governs the missing-file case: true for an explicitly configured path (a typo must fail startup rather than silently bill with built-ins the operator believes they replaced), false for the conventional <datadir>/defaults_llm_pricing.yaml probe (absent file = compiled-in defaults, still watched in case it appears). A file that exists but is malformed is always an error at load time.

func MarshalDefaultsYAML

func MarshalDefaultsYAML() []byte

MarshalDefaultsYAML renders the built-in default pricing table (catalog + supplementals, WITHOUT any operator override) as the YAML schema LoadOverrideFile consumes. It backs the generated defaults_llm_pricing.example.yaml so operators start from a file that matches the compiled-in rates exactly; a golden test keeps the two in sync. Output is deterministic (sorted surfaces and models).

func StartReloader

func StartReloader(ctx context.Context, interval time.Duration)

StartReloader launches the periodic mtime-poll goroutine for the file registered by LoadFile. Runtime failures are lenient — a parse error keeps the previously loaded table and logs a warning; a deleted file reverts to the compiled-in defaults — so a mid-edit save can never take pricing down. Returns immediately when no path was registered.

Types

type Entry

type Entry struct {
	InputPer1k         float64 `json:"input_per_1k"`
	OutputPer1k        float64 `json:"output_per_1k"`
	CachedInputPer1k   float64 `json:"cached_input_per_1k,omitempty"`
	CacheReadPer1k     float64 `json:"cache_read_per_1k,omitempty"`
	CacheCreationPer1k float64 `json:"cache_creation_per_1k,omitempty"`
}

Entry is a single model's pricing in USD per 1k tokens. This struct IS the wire shape: the synthesizer marshals it verbatim into cost_meter's ConfigJSON, and the proxy unmarshals the same field names.

A zero rate means "no rate configured" — the proxy bills that cache bucket at InputPer1k (identical semantics to the retired proxy-embedded table). CachedInputPer1k is the OpenAI shape (cached prompt tokens are a subset of input); CacheReadPer1k / CacheCreationPer1k are the Anthropic shape (additive buckets).

func LookupDefault

func LookupDefault(surfaces []string, model string) (Entry, bool)

LookupDefault returns the default entry for model on the first of the given surfaces that prices it. Used by the synthesizer to seed a per-provider entry with default cache rates before overlaying the operator's stored prices.

Jump to

Keyboard shortcuts

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