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
- func AccountLabel(a store.Account, ok bool) string
- func MonthStart(t time.Time, loc *time.Location) time.Time
- func PriceKey(provider, model string) string
- func PriceProvider(cli, baseURLHost string) string
- func PriceUnpriced(ctx context.Context, s store.Store) (int, error)
- func Seed(ctx context.Context, s store.Store) (int, error)
- func SeedRows() []store.Price
- type Book
- type Payer
- type Tokens
Constants ¶
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 ¶
AccountLabel is the account's name, or its provider and plan while nobody has named it.
func MonthStart ¶
MonthStart is the midnight of the first day of t's month in loc.
func PriceKey ¶
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 ¶
PriceProvider is the provider a call is priced by: the host it went to, else the CLI's own vendor.
func PriceUnpriced ¶
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 ¶
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 ¶
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 (*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.
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.