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.
OllamaProvider is the concrete provider class created by Ollama::create(). It extends AiSdk\Contracts\BaseProvider and implements multiple provider interfaces from aisdk/core, covering text generation, embeddings, image generation, model listing, and model inspection. Most applications interact with OllamaProvider indirectly through the Ollama facade — direct instantiation is an advanced pattern for cases where multiple provider instances with different configurations must coexist in the same process.
Namespace
Implemented Interfaces
OllamaProvider implements the following contracts from aisdk/core:
| Interface | Description |
|---|---|
TextProviderInterface | Enables text generation. The protected textModel() method returns an OllamaTextModel instance, which is resolved automatically by BaseProvider when $provider->model($id) is called with a text context. |
EmbeddingProviderInterface | Enables embedding generation. The protected embeddingModel() method returns an OllamaEmbeddingModel instance. |
ImageProviderInterface | Enables image generation. The protected imageModel() method returns an OllamaImageModel instance. |
AvailableModelsProviderInterface | Exposes the availableModels() method, which fetches the list of locally installed models from the Ollama server’s /api/tags endpoint. |
ModelInspectionProviderInterface | Exposes the inspectModel() method, which fetches detailed capabilities and metadata for a specific model from /api/show. |
Constructor
OllamaOptions instance. The options property is publicly accessible (read-only) after construction, allowing inspection of the active configuration. The recommended way to build an OllamaOptions instance is via its named static factory:
A configured
OllamaOptions value object. Carries the baseUrl, nativeBaseUrl, apiKey, api, headers, and optional sdk instance. Build with OllamaOptions::fromArray().Methods
name()
Always returns
'ollama' (the value of OllamaOptions::PROVIDER_NAME).availableModels()
GET request to {nativeBaseUrl}/api/tags and parses the response into an array of ModelDefinition objects. Each model entry in the Ollama response is mapped to a ModelDefinition using the model field (falling back to name) as the id, and preserving modified_at, size, digest, and details in the metadata.
Models with missing or empty id fields are silently skipped.
An array of
AiSdk\ModelDefinition objects, one per installed model. Each object exposes:| Property | Type | Description |
|---|---|---|
id | string | The model identifier as reported by the Ollama server (e.g. 'llama3.2:latest', 'private/model:latest'). |
metadata | array | A filtered associative array. Present keys: modified_at (string), size (int), digest (string), details (array). Keys are omitted when the server does not return a value for them. |
inspectModel()
POST request to {nativeBaseUrl}/api/show with body {"model": $modelId, "verbose": false} and returns a ModelDefinition with fully mapped capabilities. The Ollama-native capability strings are translated to typed AiSdk\Capability enum values according to this mapping:
| Ollama capability | SDK Capability values |
|---|---|
completion | TextGeneration, Streaming, TextInput |
vision | ImageInput |
audio | AudioInput |
tools | ToolCalling |
thinking | Reasoning |
image / image_generation | ImageGeneration |
embedding | Embedding |
completion is present, structured_output is also added to adaptedCapabilities with strategy 'JSON schema passed through the response format'.
The model identifier to inspect (e.g.
'llava', 'llama3.2', 'private/model:latest').An
AiSdk\ModelDefinition object with:| Property | Type | Description |
|---|---|---|
id | string | The queried $modelId value. |
capabilities | array<int, Capability> | Mapped SDK Capability enum instances derived from the Ollama capability strings. |
adaptedCapabilities | array | Contains structured_output info when completion is in the native capabilities array; empty array otherwise. |
metadata | array | Contains modified_at, details, model_info, and ollama_capabilities (the original raw string array from Ollama). Keys are omitted when the server does not return values for them. |
Direct Instantiation
For advanced use cases — such as running multiple Ollama providers pointing at different servers in the same process — you can bypass the facade and instantiateOllamaProvider directly:
The protected
textModel(), embeddingModel(), and imageModel() methods are part of the BaseProvider contract and are called automatically by the SDK’s routing logic when $provider->model($id) is invoked in the appropriate context. You do not call them directly. They return OllamaTextModel, OllamaEmbeddingModel, and OllamaImageModel instances respectively, each initialized with the same OllamaOptions instance held by the provider.