openai.OllamaClient

A local Ollama server through its OpenAI-compatible chat-completions endpoint.

Reference version

Signature

class openai.OllamaClient

A 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 /v1 is load-bearing — Ollama serves the OpenAI-compatible API only under that prefix, and a bare :11434 default 404s on every call.
  • no credential is required (and none is sent unless one is configured).
  • the system role 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_url prompt would otherwise reach a server that cannot read it (inline_image_urls).

Source:<builtin>/openai/ollama.bamlbytes 8685416

Fields

model

string

base_url

ai.Credential | null

api_key

ai.Credential | null

request_body

baml.json.json | null

headers

map<string, string> | null

query_params

map<string, string> | null

temperature

float | null

max_tokens

int | null

top_p

float | null

stop

string[] | null

seed

int | null

capture_wire

bool

Static methods

function

new

(
model: string,
base_url: ai.Credential | null = …,
api_key: ai.Credential | null = …,
request_body: baml.json.json | null = …,
headers: map<string, string> | null = …,
query_params: map<string, string> | null = …,
temperature: float | null = …,
max_tokens: int | null = …,
top_p: float | null = …,
stop: string[] | null = …,
seed: int | null = …,
capture_wire: bool = …
) -> openai.OllamaClient

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

function

compat

(self) -> openai.internal.ChatCompat throws baml.errors.Io | baml.errors.ParseError

The provider record: everything the shared chat core needs to know about this endpoint.

function

params

(
self,
preview: bool = …
) -> openai.internal.ChatParams throws baml.errors.Io | baml.errors.ParseError

The per-request parameters handed to the shared chat core.

Parameters

  • preview: omit the credential, for rendering a request without sending it.
function

resolved_api_key

(self) -> string | null throws baml.errors.Io | baml.errors.ParseError

The request-time credential, if one is configured. Ollama requires none, so null is the ordinary case and no auth header is sent.

function

resolved_base_url

(self) -> string throws baml.errors.Io | baml.errors.ParseError

The 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

function

id

(self) -> string
function

invoke

(
self,
input: ai.ModelTurnInput
) -> ai.ModelTurn throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure
function

render

(
self,
input: ai.ModelTurnInput
) -> baml.http.Request throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Source:<builtin>/openai/ollama.bamlbytes 42474982

ai.stream.StreamingClient for openai.OllamaClient

Instance methods

function

invoke_stream

(
self,
input: ai.ModelTurnInput
) -> ai.stream.TurnStream throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Source:<builtin>/openai/ollama.bamlbytes 49885414