> For the complete documentation index, see [llms.txt](https://docs.mozilla.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mozilla.ai/api-reference/list-models.md).

# List Models

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

### `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()`

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

| 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

Returns a `Sequence` of [`Model`](/api-reference/completion-1/model.md) objects. Each `Model` has at minimum an `id` field containing the model identifier string.

### Usage

```python
from any_llm import list_models

models = list_models("openai")
for model in models:
    print(model.id)
```

#### Async

```python
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())
```

#### Using the AnyLLM class

```python
from any_llm import AnyLLM

llm = AnyLLM.create("openai")
models = llm.list_models()
print(f"Available models: {len(models)}")
```

{% hint style="info" %}
Not all providers support listing models. Check the [providers page](/providers.md) for support details, or query `ProviderMetadata.list_models` programmatically.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mozilla.ai/api-reference/list-models.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
