Documentation
¶
Overview ¶
Package modelinfo resolves a model's context window (max input tokens) DYNAMICALLY, so context-guru's triggers can scale with the model rather than hard-coding thresholds. The window is obtained without maintaining our own model list: the primary source is LiteLLM's community-maintained model_prices_and_context_window.json (fetched once and cached); an optional gateway /model/info probe is tried first for deployments that expose it; a tiny embedded table is the last-resort fallback.
Every lookup fails OPEN: an unknown model returns ok=false and callers fall back to absolute thresholds. Nothing here ever blocks a request — fetches are cached, single-flighted, and time-bounded, and any error just leaves the window unknown.
Index ¶
Constants ¶
const LiteLLMPricesURL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"
LiteLLMPricesURL is the community-maintained map of model -> {max_input_tokens,…}. Overridable (air-gapped mirrors) via NewLiteLLM.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain []Resolver
Chain tries each resolver in order; the first ok wins.
type LiteLLM ¶
type LiteLLM struct {
URL string
Client *http.Client
TTL time.Duration
// contains filtered or unexported fields
}
LiteLLM fetches and caches the LiteLLM prices map, serving per-model windows.
func NewLiteLLM ¶
NewLiteLLM builds a resolver. url="" uses LiteLLMPricesURL; ttl<=0 uses 6h.
type Price ¶ added in v0.1.1
type Price struct {
Input float64 `json:"input"` // fresh (uncached) input per token
Output float64 `json:"output"` // completion per token
CacheRead float64 `json:"cache_read"` // cache-hit input per token
CacheWrite float64 `json:"cache_write"` // cache-creation input per token
}
Price is a model's per-token USD rates, in the four tiers a prompt-caching provider bills. Zero rates mean "unknown" — a caller must treat a Price it did not get an ok=true for as "no pricing", never as free.
type Pricer ¶ added in v0.1.1
Pricer resolves a model's per-token rates. ok=false means "unknown"; callers must then report cost as unavailable rather than zero.
type Static ¶
type Static struct {
// contains filtered or unexported fields
}
Static is a tiny last-resort table keyed by substring. Used only when a dynamic source is unavailable. Deliberately small — it is a floor, not a registry.
func DefaultStatic ¶
func DefaultStatic() Static
DefaultStatic covers the common families with conservative windows.
type Table ¶ added in v0.1.1
type Table struct {
// contains filtered or unexported fields
}
A Table is an OPERATOR-SUPPLIED price list, consulted before the public LiteLLM map. It exists because the public map prices the public API, and a gateway does not have to charge that: IBM's ete-litellm bills claude-sonnet-5 at $1.52/MTok in where anthropic.com bills $3.00, so every dollar figure this dashboard produced for that gateway was ~2x too high. A price list is also the only way to price a model the public map has never heard of — a preview deployment, an internal route name, or a server-resolved TIER like Bob's `premium`, which is not a model id at all and left every Bob request's cost reading "unknown".
Rates in the file are USD per MILLION tokens, because that is the unit every vendor's price page and every gateway's admin UI uses; storing per-token floats in a hand-edited file invites a factor-of-a-thousand typo that nothing would catch. They are converted once, here.
Nothing in a Table is a secret: these are list prices. It is a plain file, and a missing or malformed one is a startup error rather than a silent fallback — a price list that failed to load looks exactly like "this model is free".
func LoadTable ¶ added in v0.1.1
LoadTable reads a price list. An empty path returns a nil *Table, which prices nothing and is safe to put in a Chain.
func ParseTable ¶ added in v0.1.1
ParseTable builds a Table from the YAML document LoadTable reads.