usage

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 7 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 usage is the hub's side of spend (docs/hub/usage.md): the price list and what a call costs at list prices, and taking in the facts machines report.

Index

Constants

View Source
const (
	ProviderAnthropic  = "anthropic"
	ProviderOpenAI     = "openai"
	ProviderKimi       = "kimi"
	ProviderMoonshot   = "moonshot"
	ProviderZai        = "zai"
	ProviderOpenRouter = "openrouter"
	ProviderDeepSeek   = "deepseek"
	ProviderMiniMax    = "minimax"
	ProviderXAI        = "xai"
)

Providers of the price list: who a call was paid to, not which CLI made it.

Variables

This section is empty.

Functions

func AccountLabel

func AccountLabel(a store.Account, ok bool) string

AccountLabel is the account's name, or its provider and plan while nobody has named it.

func MonthStart

func MonthStart(t time.Time, loc *time.Location) time.Time

MonthStart is the midnight of the first day of t's month in loc.

func PriceKey

func PriceKey(provider, model string) string

PriceKey is the price list's key of a model at a provider; "" when the model names none. A Claude model whose family key is not in the list gets no price here, never a neighbour family's.

func PriceProvider

func PriceProvider(cli, baseURLHost string) string

PriceProvider is the provider a call is priced by: the host it went to, else the CLI's own vendor.

func PriceUnpriced

func PriceUnpriced(ctx context.Context, s store.Store) (int, error)

PriceUnpriced prices the stored calls that had no price when they came (a model the list did not know yet) by the list as it is now, and sums their hours anew. It returns how many it priced; calls whose model the list still lacks stay.

func Seed

func Seed(ctx context.Context, s store.Store) (int, error)

Seed adds the seed rows that are missing; rows already there (an administrator's correction) are kept. It returns how many it added.

func SeedRows

func SeedRows() []store.Price

SeedRows are the rows the hub puts in an empty price list: internal/pricing's tables (the runtime's own numbers, so the hub and /api/platform/stats agree), in effect from the beginning. Rows of other providers are added the same way with their own effective_from when their prices are confirmed; a model without a row has no price.

Types

type Book

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

Book is the price list in memory, ready to price calls.

func NewBook

func NewBook(prices []store.Price) *Book

func (*Book) Cost

func (b *Book) Cost(provider, model string, ts int64, t Tokens) (micros int64, ver int64, unit string, ok bool)

Cost is a call's list price in micro-units of the row's unit (micro-dollars for usd), and the row's version (its effective_from); false when the model has no price: the caller keeps NULL, never 0.

func (*Book) Price

func (b *Book) Price(provider, model string, ts int64) (store.Price, bool)

Price is the row in effect at ts (epoch ms) for a model at a provider; false when there is none.

type Payer

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

Payer computes paid (docs/hub/analytics.md, «Money and periods»): on a key or a prepaid balance it is the list price; on a subscription, the account's monthly fee split in proportion to everyone's list on it in that calendar month; nothing on an account the hub does not know.

func NewPayer

func NewPayer(ctx context.Context, st store.Store, loc *time.Location, accountIDs []string) (*Payer, error)

NewPayer is a payer over these accounts, with calendar months cut in loc.

func (*Payer) Account

func (p *Payer) Account(id string) (store.Account, bool)

Account is one of the payer's accounts.

func (*Payer) Paid

func (p *Payer) Paid(ctx context.Context, accountID string, at, list int64) (int64, error)

Paid is what list micro-dollars spent at `at` (epoch ms) on the account cost.

type Tokens

type Tokens struct {
	Input, Output, CacheRead, CacheWrite5m, CacheWrite1h int64
}

Tokens of one call. Input does not include the tokens read from the cache.

Jump to

Keyboard shortcuts

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