List Models
The list_models and alist_models functions return the available models for a given provider.
any_llm.list_models()
Section titled “any_llm.list_models()”def list_models( provider: str | LLMProvider, api_key: str | None = None, api_base: str | None = None, client_args: dict[str, Any] | None = None, **kwargs: Any,) -> Sequence[Model]any_llm.alist_models()
Section titled “any_llm.alist_models()”Async variant with the same parameters.
async def alist_models( provider: str | LLMProvider, api_key: str | None = None, api_base: str | None = None, client_args: dict[str, Any] | None = None, **kwargs: Any,) -> Sequence[Model]Parameters
Section titled “Parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
provider | str | LLMProvider | required | |
api_key | str | None | None | |
api_base | str | None | None | |
client_args | dict[str, Any] | None | None | |
**kwargs | Any | required |
Return Value
Section titled “Return Value”Returns a Sequence of Model objects. Each Model has at minimum an id field containing the model identifier string.
from any_llm import list_models
models = list_models("openai")for model in models: print(model.id)import asynciofrom any_llm import alist_models
async def main(): models = await alist_models("mistral") for model in models: print(model.id)
asyncio.run(main())Using the AnyLLM class
Section titled “Using the AnyLLM class”from any_llm import AnyLLM
llm = AnyLLM.create("openai")models = llm.list_models()print(f"Available models: {len(models)}")