pi_llm.models¶
models
¶
Dynamic model catalog.
Functions for constructing, fetching, and comparing LLM models.
get_model(provider, model_id, **overrides)
¶
Construct a Model from known metadata. Works offline.
Unknown models get sensible defaults (128k context, 16k max_tokens, no pricing).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
Provider name (e.g. |
required |
model_id
|
str
|
Model identifier (e.g. |
required |
**overrides
|
Any
|
Override any |
{}
|
Returns:
| Type | Description |
|---|---|
Model
|
A fully configured |
Example
model = get_model("openai", "gpt-4o") model.context_window 128000
fetch_models(provider='openai', api_key=None, base_url=None)
async
¶
Fetch available models from the provider's API.
Each returned model is enriched with local pricing and metadata.
This is optional — get_model() works without calling this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
Provider name (default |
'openai'
|
api_key
|
str | None
|
API key (falls back to |
None
|
base_url
|
str | None
|
Override the API base URL. |
None
|
Returns:
| Type | Description |
|---|---|
list[Model]
|
List of |
calculate_cost(model, usage)
¶
supports_xhigh(model)
¶
Check if a model supports the "xhigh" thinking level.
models_are_equal(a, b)
¶
Check if two models are the same by comparing id and provider.