pricing

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package pricing prices token usage deterministically. It is the basis of the dollar budget the governor enforces and the cost ledger records. Prices are static, defensible list prices (USD per 1M tokens) and are overridable via config — RiskKernel never asks an LLM what something costs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadOverrides added in v0.2.0

func LoadOverrides(path string) (map[string]Rate, error)

LoadOverrides reads model→Rate overrides from a JSON file — the hook for keeping prices current as providers change them, without recompiling. The format is a map of model name (or prefix) to its rate in USD per 1M tokens:

{
  "claude-sonnet-4": { "inputPerM": 3.0, "outputPerM": 15.0 },
  "my-finetuned-model": { "inputPerM": 0.5, "outputPerM": 1.0 }
}

These layer on top of the built-in list prices (pass the result to NewTable). A missing, unreadable, malformed, or negative-rate file is an error: pricing is the dollar budget's basis, so the daemon refuses to start rather than silently misprice.

Types

type Rate

type Rate struct {
	InputPerM  float64 `json:"inputPerM"`
	OutputPerM float64 `json:"outputPerM"`
}

Rate is a model's price in USD per 1,000,000 tokens. The JSON tags are the pricing-override file format (see LoadOverrides).

type Table

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

Table prices models. The zero value is usable (built-in rates only); use NewTable to layer config overrides on top.

func NewTable

func NewTable(overrides map[string]Rate) *Table

NewTable returns a Table seeded with the built-in rates, with overrides applied on top (override keys are matched by the same prefix rule).

func (*Table) Cost

func (t *Table) Cost(model string, promptTokens, completionTokens int64) (usd float64, ok bool)

Cost returns the USD cost of the given token counts for a model, and whether the model was priced. When ok is false the cost is 0 — the caller decides whether to treat an unpriced model as a dollar-budget enforcement gap.

func (*Table) Rate

func (t *Table) Rate(model string) (Rate, bool)

Rate returns the rate for a model and whether it was found. Matching is by longest case-insensitive prefix so dated snapshots resolve to their family.

Jump to

Keyboard shortcuts

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