Documentation
¶
Overview ¶
Package litellm fetches and caches the LiteLLM community price/window map (model_prices_and_context_window.json) and prices the operator's own gateway rate card from it. It is the one network call modelinfo makes, which is why it is a sibling package rather than living in modelinfo itself: modelinfo's own resolvers (Static, Table, Chain) do no I/O, and the dispatch.Dispatcher split requires that every core package hold that line. This package is host-side — only proxy, proxyapp, cmd/ and its public facade models/litellm import it.
Index ¶
- Constants
- type LiteLLM
- func (l *LiteLLM) Load(ctx context.Context) error
- func (l *LiteLLM) Price(ctx context.Context, model string) (modelinfo.Price, bool)
- func (l *LiteLLM) Unresolved() (err error, failures int)
- func (l *LiteLLM) Window(ctx context.Context, model string) (int, bool)
- func (l *LiteLLM) WindowExact(ctx context.Context, model string) (int, bool, bool)
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 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.
func (*LiteLLM) Load ¶
Load fetches the document SYNCHRONOUSLY and reports whether it produced usable entries.
Window() cannot be used for this. It calls refreshIfStale, which starts a BACKGROUND fetch and returns "unknown" immediately, so a caller that wants to verify a configured document at startup would always see failure on the first call and success only some milliseconds later — a race whose two outcomes are "refuse to start" and "start fine". Exposed as its own method so that check is deterministic.
It also removes a smaller wart: with a background-only warm-up the FIRST request of a process is always served from the fallback window. On a benchmark that is one request per pass priced against the wrong denominator, which is exactly the kind of small, permanent, invisible error that makes a number untrustworthy without making it look wrong.
func (*LiteLLM) Price ¶
Price returns the model's per-token rates from the cached LiteLLM map, matched the same way Window matches (full id, then bare tail, then a contains scan).
func (*LiteLLM) Unresolved ¶
Unresolved reports why no model-window document has loaded, and how many attempts have failed. Exposed so a RUN can record it in its stats rather than requiring someone to notice a warning in a debug log: a benchmark that silently priced every threshold against the wrong window is a run whose numbers mean nothing, and the cheapest place to catch that is the artifact already collected per pass.
func (*LiteLLM) WindowExact ¶
Window returns the model's context window from the cached LiteLLM map. WindowExact: a hit in the fetched map is a per-model `max_input_tokens` published for that model, so it is measured. A miss is a miss — exactness says nothing when ok is false.