---
title: ai.providers
description: Reference for provider APIs.
type: reference
summary: Reference for ai.providers.
---

# ai.providers



`ai.get_provider` is the usual entry point for application code. Use
`ai.providers` when you need provider classes, provider protocols, or
provider-specific namespaces.

## Public APIs

* `get_provider`
* `Provider`
* `ProviderProtocol`
* `OpenAICompatibleProvider`
* `AnthropicCompatibleProvider`
* `GatewayProvider`
* `history_utils`

## Provider operations

`Provider` and `ProviderProtocol` define these model operations:

* `stream`: Stream a language-model response.
* `generate`: Generate a buffered language-model response.
* `generate_image`: Generate images.
* `generate_video`: Generate videos.
* `generate_audio`: Generate speech.
* `embed`: Embed text values.
* `transcribe`: Transcribe audio.
* `rerank`: Rerank documents against a query.

Application code normally uses `ai.stream`, `ai.experimental_generate`, or
[`ai.ops`](/docs/reference/ops) instead of calling provider methods directly.
A protocol only needs to implement the operations that it supports.

## ai.providers.history\_utils

Message-history repair utilities. `ai.stream` passes history to the
provider as-is; provider implementations call these before converting
messages to their wire format.

```python
from ai.providers import history_utils


repaired = history_utils.repair(messages)
```

`repair` strips internal messages, removes non-model parts, replaces
invalid tool args with `{}`, and inserts error results for missing tool
calls, logging a warning for every fix. It raises `IntegrityError` on
duplicate tool ids and orphaned tool results — those have no safe
automatic fix. The individual fix functions (`drop_internal`,
`fix_tool_args`, `close_orphaned_tool_calls`) each return a new message
list plus the issues they fixed — use them when a provider needs
different choices or the issues themselves — and `check_tool_ids`
detects the unfixable issues without raising.

Validate a history yourself when you want issues to raise instead of
being repaired.

```python
history_utils.validate(messages)  # raises IntegrityError on any issue
issues = history_utils.inspect(messages)  # or just report them
```

APIs:

* `repair`
* `drop_internal`
* `fix_tool_args`
* `close_orphaned_tool_calls`
* `check_tool_ids`
* `inspect`
* `validate`
* `Issue`
* `IntegrityError`


---

For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md)

For an index of all available documentation, see [/llms.txt](/llms.txt)

For agent-facing discovery, including API and MCP surfaces, see [/agents.md](/agents.md)