openai.OllamaClient
A local Ollama server through its OpenAI-compatible chat-completions endpoint.
Signature
class openai.OllamaClientA local Ollama server through its OpenAI-compatible chat-completions endpoint.
The whole client is four deviations from openai.GenericClient:
- the base URL defaults to
http://localhost:11434/v1. The/v1is load-bearing — Ollama serves the OpenAI-compatible API only under that prefix, and a bare:11434default 404s on every call. - no credential is required (and none is sent unless one is configured).
- the
systemrole is allowed, like every other client here: Ollama passes it straight through to the model's template. - image URLs are fetched and inlined as base64. Ollama's OpenAI-compat
docs are explicit — "Base64 encoded image ✓ / Image URL ✗" — so an
Image.from_urlprompt would otherwise reach a server that cannot read it (inline_image_urls).
Source:<builtin>/openai/ollama.bamlbytes 868–5416
Fields
model
stringbase_url
ai.Credential | nullapi_key
ai.Credential | nullrequest_body
baml.json.json | nullheaders
map<string, string> | nullquery_params
map<string, string> | nulltemperature
float | nullmax_tokens
int | nulltop_p
float | nullstop
string[] | nullseed
int | nullcapture_wire
boolStatic methods
new
(Creates a client. Construction reads no environment variable, so declaring one is always safe; credentials and endpoints resolve when a request is built.
Instance methods
The provider record: everything the shared chat core needs to know about this endpoint.
params
(The per-request parameters handed to the shared chat core.
Parameters
preview: omit the credential, for rendering a request without sending it.
resolved_api_key
(self) -> string | null throws baml.errors.Io | baml.errors.ParseErrorThe request-time credential, if one is configured. Ollama requires
none, so null is the ordinary case and no auth header is sent.
resolved_base_url
(self) -> string throws baml.errors.Io | baml.errors.ParseErrorThe request-time base URL, or http://localhost:11434/v1. The /v1
is load-bearing: Ollama serves the OpenAI-compatible API only there.
Implementations
ai.Client for openai.OllamaClient
Instance methods
id
(self) -> stringinvoke
(render
(Source:<builtin>/openai/ollama.bamlbytes 4247–4982
ai.stream.StreamingClient for openai.OllamaClient
Instance methods
invoke_stream
(Source:<builtin>/openai/ollama.bamlbytes 4988–5414