Documentation
¶
Overview ¶
Package modelinfo describes models: their context window, output limit, capabilities and per-token prices, read from LiteLLM's public price table (model_prices_and_context_window.json). It imports nothing from the harness; callers pass the provider they configured as a hint to Lookup.
The table is data, not authority: ids are matched conservatively (exact, then provider-prefixed, then the same name under another provider or a dated release of the same model) and never across unrelated models.
Index ¶
Constants ¶
const ( // DefaultURL is LiteLLM's public price table. DefaultURL = "https://raw.githubusercontent.com/BerriAI/litellm/refs/heads/main/model_prices_and_context_window.json" // DefaultTTL is how long the cached copy is used without asking again. DefaultTTL = 24 * time.Hour )
Defaults of Options.
const DefaultContextWindow = 128000
DefaultContextWindow is the context window assumed for a model whose window is not known (not in the configured windows nor in the price table).
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Info ¶
type Info struct {
ID string
Provider string
// ContextWindow is the input window in tokens, MaxOutput the largest answer.
ContextWindow, MaxOutput int
// Prices are in dollars per token. Priced is false when the table has no
// price at all for the model (a zero price is then "unknown", not "free").
InputPerToken, OutputPerToken, CacheReadPerToken, CacheWritePerToken float64
Priced bool
// Tier holds the higher prices some models charge for a request whose
// prompt exceeds Tier.Above tokens (nil: one price).
Tier *Tier
Vision, Reasoning, Tools bool
}
Info is what is known about one model. A zero field is unknown.
type Options ¶
type Options struct {
// CacheDir holds the downloaded table (model_prices.json) and its ETag; ""
// keeps nothing on disk (the table is fetched again at every start).
CacheDir string
// URL replaces DefaultURL.
URL string
// File, when set, is a local table read instead of the URL (and never cached).
File string
// Override is a user file in the same schema; its models win over the table's.
Override string
// TTL is the age under which the cache is used as is (default DefaultTTL).
TTL time.Duration
// HTTPClient performs the request (default http.DefaultClient).
HTTPClient *http.Client
// Offline makes no request: the cache, however old, is all there is.
Offline bool
}
Options configure Load.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a set of models. It is safe for concurrent use; the zero value and a nil *Table are empty.
func Load ¶
Load reads the table: the cache when fresh, else the URL (a conditional GET that sends nothing but the request itself), else the stale cache. With none of them the table is empty and the error says why; callers may ignore it, a table without data answers every Lookup with false.
func LoadAsync ¶
LoadAsync returns the table at once and fills it in the background; Ready reports when it is done. Starting never waits for the network.
func (*Table) Lookup ¶
Lookup finds the model id as served by the provider providerHint (the configured provider type or name; "" when unknown): an exact entry, then "<hint>/<id>", then the same name under another prefix, then the same model as a dated release or an undated alias. A miss is (Info{}, false).
type Tier ¶
Tier is the price list of requests above a prompt size ("_above_200k_tokens"). A zero price falls back to the base price.
type Usage ¶
type Usage struct {
In, Out, Cached int
// Prompt is the size of the largest single prompt, which selects the price
// tier (0: the base prices).
Prompt int
}
Usage is the token usage a cost is computed from. In counts every input token including the cached ones; reasoning tokens are part of Out.