TheDocumentation 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.
Ollama class lives in the root AiSdk\ namespace (defined in src/Root/Ollama.php) and acts as a static facade over OllamaProvider. It manages a process-level singleton provider instance, meaning you configure the provider once at application bootstrap and all subsequent calls to Ollama::model(), Ollama::availableModels(), and Ollama::inspectModel() share that same instance automatically.
Namespace and Import
Methods
Ollama::create()
OllamaProvider from the given configuration array and stores it as the process-level default. All subsequent calls to Ollama::model(), Ollama::availableModels(), and Ollama::inspectModel() will use this instance until Ollama::reset() is called.
Internally, this passes the config array to OllamaOptions::fromArray(), which reads values from the array and falls back to environment variables (OLLAMA_API_KEY, OLLAMA_BASE_URL, OLLAMA_NATIVE_BASE_URL) when array keys are absent.
Optional configuration array. Supported keys:
| Key | Type | Default | Description |
|---|---|---|---|
baseUrl | string | http://localhost:11434/v1 | The OpenAI-compatible API base URL. Also read from OLLAMA_BASE_URL. Trailing slashes are stripped automatically. |
nativeBaseUrl | string | Derived from baseUrl by stripping /v1 | The native Ollama API base URL used for /api/tags and /api/show. Also read from OLLAMA_NATIVE_BASE_URL. |
apiKey | string|null | null | Bearer token sent in the Authorization header. Also read from OLLAMA_API_KEY. Pass null or omit for unauthenticated local installs. |
api | string|OllamaApi | 'chat_completions' | Which Ollama API to use. Accepts 'chat_completions' or 'responses'. |
headers | array<string, string> | [] | Additional HTTP headers merged into every request. |
sdk | Sdk|null | null | An explicit AiSdk\Support\Sdk instance providing the HTTP client and PSR-17 factories. Falls back to the global Generate::sdk() singleton. |
The newly created and stored
OllamaProvider instance.Ollama::model()
AiSdk\Contracts\Model instance. The model ID is treated as an opaque value — any string the Ollama server accepts is valid.
The model identifier to pass through to the Ollama server. Examples:
'llama3.2', 'acme/private-model:latest', 'llava', 'nomic-embed-text'.A model reference implementing
AiSdk\Contracts\Model. Pass this directly to Generate::text()->model() or other generation builders.Ollama::availableModels()
/api/tags endpoint and returns an array of ModelDefinition objects representing every model currently installed on that server. The HTTP request is issued synchronously using the configured SDK HTTP client.
An array of
AiSdk\ModelDefinition objects. Each object exposes:| Property | Type | Description |
|---|---|---|
id | string | The model identifier (e.g. 'private/model:latest'). |
metadata | array | Raw metadata from the Ollama response. Contains modified_at, size, digest, and details keys when present on the server response. |
Ollama::inspectModel()
/api/show endpoint for the specified model and returns a ModelDefinition with mapped SDK capabilities and full metadata. Capability mapping translates Ollama’s native capability strings (completion, vision, audio, tools, thinking, image, image_generation, embedding) into typed AiSdk\Capability enum values. See OllamaProvider for the full mapping table.
The model identifier to inspect (e.g.
'llava', 'llama3.2').An
AiSdk\ModelDefinition object. Key properties:| Property | Type | Description |
|---|---|---|
id | string | The queried model identifier. |
capabilities | array<int, Capability> | Mapped SDK Capability enum values (e.g. TextGeneration, ImageInput, ToolCalling, Reasoning). |
adaptedCapabilities | array | Contains structured_output strategy info when the model supports completion. |
metadata | array | Raw Ollama metadata: modified_at, details, model_info, and ollama_capabilities (the original string array from the server). |
Ollama::default()
OllamaProvider. If no provider has been configured yet, it lazily creates one by calling Ollama::create() with an empty config array (which applies defaults and reads from environment variables).
The active singleton
OllamaProvider instance.Ollama::reset()
$default property to null. The next call to any static method that requires a provider will lazily re-initialize it. This method is essential in test suites to prevent state leaking between test cases.
Usage Examples
Ollama::reset() in afterEach hooks alongside Generate::reset() to keep tests isolated:
/v1/responses endpoint at creation time:
chat_completions API but route a single request through the Responses API using provider options:
