> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bindai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 02.4 providers

# Providers

Providers are the bridge between BindAI and large language models.

A provider implements the communication layer for a specific AI service, translating BindAI requests into the format expected by the underlying model and converting responses back into BindAI objects.

Because every provider implements the same interface, switching models requires little or no application code changes.

***

# What is a Provider?

A provider is responsible for:

* sending prompts to an AI model
* receiving model responses
* streaming tokens
* executing tool/function calling
* reporting token usage
* returning structured outputs

Applications interact with providers through the `ModelProvider` abstraction rather than provider-specific SDKs.

***

# Supported Providers

BindAI is designed to support multiple providers.

Current providers include:

* OpenAI
* Ollama
* Anthropic *(planned)*
* Google Gemini *(planned)*
* Azure OpenAI *(planned)*
* OpenRouter *(planned)*
* Groq *(planned)*
* Together AI *(planned)*

New providers can be added without changing the rest of the framework.

***

# Creating a Provider

Most providers can be created directly.

```python id="r9d5aw" theme={null}
from bindai_openai import OpenAIProvider

provider = OpenAIProvider.from_env()
```

The provider is then passed into an agent.

```python id="u7mxkc" theme={null}
agent = Agent(
    name="assistant",
    provider=provider,
)
```

***

# Provider Configuration

Providers are configured using a `ProviderConfiguration`.

Typical configuration includes:

* API key
* model
* base URL
* timeout
* organization
* custom headers

Example:

```python id="d2qbje" theme={null}
from bindai_core import ProviderConfiguration

config = ProviderConfiguration(
    api_key="...",
    model="gpt-4.1-mini",
)

provider = OpenAIProvider(config)
```

***

# Environment Variables

Most providers support loading configuration from environment variables.

Example:

```text id="k2syxh" theme={null}
OPENAI_API_KEY=your_api_key
OPENAI_MODEL=gpt-4.1-mini
```

Then simply create the provider.

```python id="n8whpr" theme={null}
provider = OpenAIProvider.from_env()
```

This keeps secrets out of source code.

***

# Supported Features

Depending on the provider, BindAI supports:

| Feature           | Supported |
| ----------------- | --------- |
| Chat completion   | ✓         |
| Streaming         | ✓         |
| Tool calling      | ✓         |
| Structured output | ✓         |
| Token usage       | ✓         |
| System prompts    | ✓         |

Some providers may support additional capabilities in future releases.

***

# Streaming

Providers support token streaming.

```python id="g6prxa" theme={null}
for chunk in provider.stream(
    request,
):
    print(chunk.delta, end="")
```

Streaming allows applications to display responses immediately instead of waiting for completion.

***

# Tool Calling

Providers can return tool requests generated by the language model.

Example flow:

```text id="fyvq3e" theme={null}
Model

↓

Tool Call

↓

Tool Result

↓

Model
```

BindAI automatically converts provider-specific tool calls into portable `ToolCall` objects.

***

# Structured Output

Providers can return structured data instead of plain text.

```python id="w3lbnk" theme={null}
result = agent.chat(
    "Create a user profile.",
    output=UserProfile,
)
```

If supported by the provider, the response is validated and returned as a Python object.

***

# Token Usage

Providers report token consumption whenever available.

Example:

```python id="s4heov" theme={null}
response.usage.prompt_tokens

response.usage.completion_tokens

response.usage.total_tokens
```

This information is useful for:

* monitoring costs
* analytics
* optimization

***

# Switching Providers

One of BindAI's goals is provider independence.

Changing providers usually requires only replacing the provider object.

OpenAI:

```python id="o1gjva" theme={null}
provider = OpenAIProvider.from_env()
```

Ollama:

```python id="l7dzcu" theme={null}
provider = OllamaProvider.from_env()
```

The rest of the application remains unchanged.

***

# Custom Providers

Any custom provider can integrate with BindAI by implementing the `ModelProvider` interface.

A provider should implement methods such as:

* `generate()`
* `stream()`
* `capabilities`

This allows organizations to connect proprietary models or internal AI services.

***

# Capabilities

Every provider exposes its supported capabilities.

Example:

```python id="x2ksrq" theme={null}
provider.capabilities
```

Capabilities may indicate support for features such as:

* streaming
* structured output
* tool calling
* vision
* embeddings

Applications can inspect these capabilities before using provider-specific features.

***

# Provider Architecture

The provider layer sits between the execution engine and the AI service.

```text id="v3au5d" theme={null}
Application

↓

Agent

↓

Execution Engine

↓

Model Provider

↓

Language Model
```

This separation allows the execution engine to remain provider-agnostic.

***

# Best Practices

* Store API keys in environment variables.
* Reuse provider instances when possible.
* Choose models appropriate for the task.
* Enable streaming for long responses.
* Monitor token usage in production.
* Prefer the provider abstraction instead of calling SDKs directly.
