---
title: Adapters and Providers
description: Understand provider objects and adapter dispatch.
type: conceptual
summary: Learn how providers, clients, adapters, and wire translations connect models to APIs.
---

# Adapters and Providers



Providers own configuration and clients. Adapters translate framework messages,
tools, params, and generated files to provider wire formats.

## Provider objects

`Model` stores a model ID, adapter key, and provider reference:

```python
provider = ai.get_provider("openai")
model = ai.Model("gpt-5.4", provider=provider)
```

`ai.get_model` resolves a provider from a model ID and defaults unprefixed IDs
to AI Gateway:

```python
model = ai.get_model("anthropic/claude-sonnet-4")
```

## Client creation

Providers create upstream clients from API keys, base URLs, headers, and env
vars. You can also pass a client that your app owns:

```python
provider = ai.get_provider(
    "openai",
    base_url="http://localhost:1234/v1",
    api_key="your_access_token_here",
    client=http_client,
)
```

## Adapter registry

Provider subclasses register handles such as `openai`, `anthropic`, and
`vercel`. `get_provider` uses models.dev metadata to choose the provider class
for a provider ID.

## Stream adapters

Stream adapters implement `provider.stream`. They convert messages and tools to
the provider request, then yield public events:

```python
async for event in model.provider.stream(model, messages, tools=tools):
    yield event
```

OpenAI-compatible providers use the OpenAI chat-completions protocol.
Anthropic-compatible providers use the Anthropic messages protocol. AI Gateway
uses the Language Model v3 stream protocol.

## Generate adapters

`ai.generate` prepares messages and calls `provider.generate`. AI Gateway
supports image and video generation:

```python
result = await ai.generate(
    model,
    [ai.user_message("A mothership over the ocean.")],
    ai.ImageParams(n=1),
)
```

## Provider wire translation

Adapters translate the same internal parts differently per provider:

* `TextPart` and `FilePart` become user content.
* `ToolCallPart` becomes provider tool-call wire data.
* `ToolResultPart.get_model_input()` becomes the tool result sent back to the
  model.
* Provider-executed tools become provider tool declarations.

## Custom adapters

Add a provider by subclassing `Provider`, setting `handles`, and implementing
`from_modelsdev_provider`, `stream`, `list_models`, and `probe`. Implement
`generate` only if the provider supports non-streaming media generation.


---

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

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