pricing

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 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 pricing turns token usage into money. Amounts are int64 nano-USD (1e-9 USD) so budgets and usage events never accumulate float drift.

Index

Constants

View Source
const NanoPerUSD = 1_000_000_000

NanoPerUSD converts USD to the internal unit.

Variables

This section is empty.

Functions

func Cost

func Cost(m *proxydb.Model, usage llm.TokensUsage, mode Mode) int64

Cost prices usage on m in the given mode, rounding each part up so a budget is never under-charged by a fraction of a nano-USD. The cached part of the input is priced at the cache rates, scaled like input for the mode.

func MaxInputCost added in v1.0.0

func MaxInputCost(m *proxydb.Model, n int64, mode Mode) int64

MaxInputCost is the most n input tokens can cost in mode: plain input or, if dearer, all of it written to the cache, plus the characters they can hold for a model billed by character. Spend reservations book it.

func Rate added in v1.0.0

func Rate(m *proxydb.Model, mode Mode, p Part) float64

Rate is the per-Mtok rate Cost applies to a cache part in mode.

Types

type Mode

type Mode int

Mode selects which of a model's rates apply.

const (
	ModeStandard Mode = iota // off-peak interactive rate
	ModePeak                 // peak rate where the model has one, else standard
	ModeBatch                // batch rate, defaulting to half the standard rate
)

func ModeAt

func ModeAt(m *proxydb.Model, t time.Time) Mode

ModeAt is the interactive mode for a call starting at t. Peak rates exist only for DeepSeek V4 today, which doubles for UTC 01:00-04:00 and 06:00-10:00.

type Part added in v1.0.0

type Part int

Part names a priced part of the input for Rate.

const (
	CacheRead Part = iota
	CacheWrite
)

Jump to

Keyboard shortcuts

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