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

# OpenAI-Like Providers

> Connect to any provider that exposes an OpenAI-compatible API.

The `OpenAILike` class lets you connect to any LLM provider that implements the OpenAI chat completions API. This includes self-hosted models (vLLM, Ollama, LiteLLM), cloud providers with OpenAI-compatible endpoints, and custom proxies.

## Basic Usage

```python theme={null}
from definable.model import OpenAILike
from definable.model.message import Message

model = OpenAILike(
    id="my-model",
    api_key="your-api-key",
    base_url="https://your-provider.com/v1",
)

response = model.invoke(
    messages=[Message(role="user", content="Hello!")],
    assistant_message=Message(role="assistant", content=""),
)
print(response.content)
```

## Parameters

<ParamField path="id" type="str" required>
  Model identifier as expected by the target provider.
</ParamField>

<ParamField path="api_key" type="str">
  API key for authentication.
</ParamField>

<ParamField path="base_url" type="str" required>
  The base URL of the OpenAI-compatible API endpoint.
</ParamField>

<ParamField path="name" type="str">
  Human-readable name for this model instance.
</ParamField>

<ParamField path="provider" type="str">
  Provider name for logging and metrics.
</ParamField>

<ParamField path="supports_native_structured_outputs" type="bool" default="false">
  Whether the provider supports OpenAI-style structured outputs.
</ParamField>

## Examples

### Ollama

```python theme={null}
model = OpenAILike(
    id="llama3.2",
    base_url="http://localhost:11434/v1",
    name="Ollama Llama",
    provider="Ollama",
)
```

### vLLM

```python theme={null}
model = OpenAILike(
    id="meta-llama/Llama-3-8b-chat-hf",
    base_url="http://localhost:8000/v1",
    name="vLLM Llama",
    provider="vLLM",
)
```

### LiteLLM Proxy

```python theme={null}
model = OpenAILike(
    id="gpt-4o",
    api_key="your-litellm-key",
    base_url="http://localhost:4000/v1",
    name="LiteLLM Proxy",
    provider="LiteLLM",
)
```

### Azure OpenAI

```python theme={null}
model = OpenAILike(
    id="gpt-4o",
    api_key="your-azure-key",
    base_url="https://your-resource.openai.azure.com/openai/deployments/gpt-4o",
    provider="Azure",
)
```

## Streaming

```python theme={null}
from definable.model.message import Message

for chunk in model.invoke_stream(
    messages=[Message(role="user", content="Tell me a joke.")],
    assistant_message=Message(role="assistant", content=""),
):
    if chunk.content:
        print(chunk.content, end="", flush=True)
```

## Creating Custom Provider Classes

For repeated use, subclass `OpenAILike`:

```python theme={null}
from definable.model.openai.like import OpenAILike

class MyProviderChat(OpenAILike):
    id: str = "my-default-model"
    name: str = "MyProvider"
    provider: str = "MyProvider"
    base_url: str = "https://api.myprovider.com/v1"
    supports_native_structured_outputs: bool = True
```

This is exactly how `DeepSeekChat`, `MoonshotChat`, and `xAI` are implemented internally.
