Documentation
¶
Overview ¶
Package prices parses the daily model price catalogue, normalizes model ids, and indexes prices by source and maker.
Index ¶
Constants ¶
const DefaultInterval = 24 * time.Hour
DefaultInterval is the default refresh cadence when Worker.Interval is unset.
Variables ¶
var Makers = []string{
"anthropic", "openai", "google", "xai", "deepseek", "mistral", "moonshotai", "zhipuai",
"alibaba", "meta", "minimax", "cohere",
}
Makers lists maker catalogue sources in search order. Builtin front-door types map to catalogue sources first.
var TypeSources = map[string]string{
"openai": "openai",
"anthropic": "anthropic",
"gemini": "google",
"vertex": "google-vertex",
"xai": "xai",
"deepseek": "deepseek",
"mistral": "mistral",
"groq": "groq",
"cerebras": "cerebras",
"openrouter": "openrouter",
"fireworks": "fireworks-ai",
"cohere": "cohere",
"bedrock": "amazon-bedrock",
"azure": "azure",
"nebius": "nebius",
"huggingface": "huggingface",
}
TypeSources maps front-door built-in provider types to catalogue source ids.
Functions ¶
func Fetch ¶
Fetch downloads and parses the price catalogue from rawURL with a 60 s timeout and a 32 MiB body cap, refusing empty results.
Types ¶
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog is an immutable in-memory price index. Callers swap it via atomic.Pointer.
func NewCatalog ¶
func NewCatalog(entries []store.CatalogEntry) *Catalog
NewCatalog builds an immutable price index from entries. Missing cache_read or cache_write rates default to input.
type Price ¶
type Price struct {
Input, Output, CacheRead, CacheWrite float64
}
Price holds token rates in USD per 1M tokens.
type Store ¶
type Store interface {
Catalog(ctx context.Context) ([]store.CatalogEntry, time.Time, error)
ReplaceCatalog(ctx context.Context, entries []store.CatalogEntry, fetchedAt time.Time) error
}
Store reads and replaces the persisted price catalogue. *store.Store implements it.
type Worker ¶
type Worker struct {
URL string
Interval time.Duration
Store Store
Client *http.Client
Log *slog.Logger
// contains filtered or unexported fields
}
Worker keeps an in-memory *Catalog backed by the store and refreshes it periodically from URL. An empty URL disables fetching and serves the stored copy only.