Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/ollama/llms.txt
Use this file to discover all available pages before exploring further.
OllamaTextModel is the internal model class created by OllamaProvider when a text generation request is made. It implements TextModelInterface and handles both non-streaming and streaming generation, routing requests through either Ollama’s OpenAI-compatible Chat Completions endpoint or the Responses API depending on configuration.
Namespace
This class is not instantiated directly. Use
Ollama::model() to obtain a model instance and the Generate facade to dispatch requests.Adapter Capabilities
The following capabilities are declared byOllamaTextModel via its ADAPTER_CAPABILITIES constant. These capabilities reflect what the adapter supports at the protocol level and are always declared regardless of which specific model is installed on the Ollama server:
| Capability | Description |
|---|---|
TextGeneration | Generates text completions from prompts and message history |
Streaming | Supports server-sent event streaming via stream() |
ToolCalling | Forwards tool/function definitions and parses tool calls |
StructuredOutput | Enforces structured JSON output via the Chat Completions API |
Reasoning | Passes reasoning effort controls to thinking-capable models |
TextInput | Accepts plain text as input |
ImageInput | Accepts image URLs or base64 data as vision input |
Methods
generate(TextModelRequest $request): TextModelResponse
Sends a synchronous generation request and returns the full response once complete.
Internally, generate():
- Resolves which API to use (Chat Completions or Responses) via
resolveApi()— see API Resolution below. - Validates the request/API combination via
ensureApiRequestSupported()— see Validation below. - Builds the request body using
ChatRequestBuilder::build()orResponsesRequestBuilder::build()depending on the resolved API. - Strips the internal
apikey from the built body before sending. - POSTs to the appropriate URL and parses the response using
ChatResponseParserorResponsesResponseParser.
stream(TextModelRequest $request): Generator
Sends a streaming request and returns a Generator that yields string chunks as they arrive from the server. Chunks are parsed from server-sent events using ChatStreamParser or ResponsesStreamParser, depending on the resolved API.
provider(): string
Returns the provider identifier string 'ollama'.
modelId(): string
Returns the model ID string that was passed at construction — for example 'llama3.2' or 'acme/private-model:latest'.
API Resolution
Each request is routed to one of two Ollama API backends. The API is resolved in the following order:- Per-request override — if
$request->providerOptionsFor('ollama')['api']is set, that string is normalised to anOllamaApienum case viaOllamaApi::resolve()and used for the request. - Global default — if no per-request override is present, the already-resolved
$this->options->apienum (set at provider creation time viaOllama::create(['api' => ...])) is used directly.
URL Routing
The request URL is assembled from the configuredbaseUrl (default: http://localhost:11434/v1):
| API | Endpoint |
|---|---|
| Chat Completions | {baseUrl}/chat/completions |
| Responses | {baseUrl}/responses |
Validation Constraints
Before every requestensureApiRequestSupported() enforces the following rules. Violations throw InvalidArgumentException:
Thrown when the resolved API is Use the Chat Completions API (the default) if you need to pass reasoning effort controls explicitly.
Responses and $request->reasoning is not null.Thrown when the resolved API is
Responses and $request->output is not null.Thrown when Ollama’s thinking models accept
$request->reasoning->effort === 'minimal', regardless of API.low, medium, or high reasoning effort only.