Skip to main content

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.

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

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

id
str
required
Model identifier as expected by the target provider.
api_key
str
API key for authentication.
base_url
str
required
The base URL of the OpenAI-compatible API endpoint.
name
str
Human-readable name for this model instance.
provider
str
Provider name for logging and metrics.
supports_native_structured_outputs
bool
default:"false"
Whether the provider supports OpenAI-style structured outputs.

Examples

Ollama

model = OpenAILike(
    id="llama3.2",
    base_url="http://localhost:11434/v1",
    name="Ollama Llama",
    provider="Ollama",
)

vLLM

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

LiteLLM Proxy

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

Azure OpenAI

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

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:
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.