Skip to content

List Models

The list_models and alist_models functions return the available models for a given provider.

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]

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]
ParameterTypeDefaultDescription
providerstr | LLMProviderrequired
api_keystr | NoneNone
api_basestr | NoneNone
client_argsdict[str, Any] | NoneNone
**kwargsAnyrequired

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 asyncio
from any_llm import alist_models
async def main():
models = await alist_models("mistral")
for model in models:
print(model.id)
asyncio.run(main())
from any_llm import AnyLLM
llm = AnyLLM.create("openai")
models = llm.list_models()
print(f"Available models: {len(models)}")