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.
Model identifier as expected by the target provider.
str
API key for authentication.
str
required
The base URL of the OpenAI-compatible API endpoint.
str
Human-readable name for this model instance.
str
Provider name for logging and metrics.
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 Messagefor 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)