litellm

package
v0.7.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func NewLiteLLM(url string, client *http.Client, ttl time.Duration) *LiteLLM

NewLiteLLM builds a resolver. url="" uses LiteLLMPricesURL; ttl<=0 uses 6h.

func (*LiteLLM) Load

func (l *LiteLLM) Load(ctx context.Context) error

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

func (l *LiteLLM) Price(ctx context.Context, model string) (modelinfo.Price, bool)

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

func (l *LiteLLM) Unresolved() (err error, failures int)

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) Window

func (l *LiteLLM) Window(ctx context.Context, model string) (int, bool)

func (*LiteLLM) WindowExact

func (l *LiteLLM) WindowExact(ctx context.Context, model string) (int, bool, bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL