pricing

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 3 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 is what a model costs, as its provider publishes it.

It is the one table the application states a price in. The chat client adds up what a conversation has spent from it, the picker shows it beside a model, and routing weighs a switch of model against it. Nothing else in the code states a price.

It is short and it is meant to be: a made-up price is worse than no price at all, so a model that is not in here is shown with its token counts and nothing else. Every rate says the day it was read and the page it was read from, because a price is a fact about a day rather than one that lasts, and a test fails a release whose table has not been read again for too long. Only a provider's own first-party rates are here: a model reached through a partner platform or a gateway is priced by whoever serves it, and is not guessed at.

Index

Constants

View Source
const Day = "2006-01-02"

Day is the layout of every date in the table.

Variables

This section is empty.

Functions

func Cost

func Cost(model string, u Usage) (float64, bool)

Cost returns what one request's tokens cost today, and whether that is known at all.

func CostOn

func CostOn(model string, u Usage, day time.Time) (float64, bool)

CostOn is Cost on a given day.

Types

type Entry

type Entry struct {
	Model string
	Rate
}

Entry is one model's rate for one stretch of days.

func Table

func Table() []Entry

Table returns a copy of every rate this build knows, for whatever has to list or check them.

type Rate

type Rate struct {
	In  float64
	Out float64
	// CacheRead is what input read from the prompt cache costs, where it is
	// not the usual tenth of In. Writing to the cache is charged a quarter more
	// than In, which is Anthropic's five-minute write; only Anthropic's answers
	// report a cache write at all.
	CacheRead float64
	// Above, when set, is a prompt length in tokens beyond which a request is
	// charged the Long rates instead. Google prices its Pro models higher for a
	// long prompt.
	Above                     int
	LongIn, LongOut, LongRead float64
	// From and Until are the first and last days this rate is published for,
	// as YYYY-MM-DD; empty is unbounded. A price already announced to change
	// is two entries, one either side of the day it changes.
	From, Until string
	// Checked is the day the rate was read off Source, as YYYY-MM-DD.
	Checked string
	Source  string
}

Rate is what a model costs, in dollars per million tokens.

func Lookup

func Lookup(model string, day time.Time) (Rate, bool)

Lookup returns the rate a model is charged at on a day, and whether this table knows one.

func (Rate) Cost

func (r Rate) Cost(u Usage) float64

Cost is what one request's tokens cost at this rate.

type Usage

type Usage struct {
	In, Out, CacheRead, CacheWrite int
}

Usage is the tokens one request read and wrote. In is every token of input, however it was priced; CacheRead and CacheWrite are the parts of it read from and written to a prompt cache.

Jump to

Keyboard shortcuts

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