The Ollama provider can be configured in two ways: through environment variables that are loaded automatically at runtime, or throughDocumentation 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::create(array $config) for programmatic control. Both approaches ultimately build an OllamaOptions instance (via OllamaOptions::fromArray()) that is stored as the process-level default and used by all subsequent provider calls.
Environment variables
Set these variables in your environment or.env file. They are picked up automatically via Env::loadOptionalSetting() — no explicit call to Ollama::create() is needed when relying solely on environment configuration.
| Variable | Description | Default |
|---|---|---|
OLLAMA_BASE_URL | Base URL for the OpenAI-compatible API | http://localhost:11434/v1 |
OLLAMA_NATIVE_BASE_URL | Base URL for native API endpoints (/api/tags, /api/show, /api/embed) | Derived by removing /v1 from OLLAMA_BASE_URL |
OLLAMA_API_KEY | Optional bearer token | — |
Programmatic configuration
CallOllama::create() with an associative array of options. Any key you omit falls back to its environment variable or default value.
Configuration options reference
Base URL for Ollama’s OpenAI-compatible API. Trailing slashes are stripped automatically. Defaults to
http://localhost:11434/v1. Can also be set via the OLLAMA_BASE_URL environment variable.Base URL for Ollama’s native REST endpoints (
/api/tags, /api/show, /api/embed). Defaults to baseUrl with the /v1 suffix removed. Can also be set via the OLLAMA_NATIVE_BASE_URL environment variable.Bearer token sent as
Authorization: Bearer <token> on every request. Only needed for remote or password-protected Ollama servers. Can also be set via the OLLAMA_API_KEY environment variable. See Authentication.Default API surface used for all text generation requests. One of
chat_completions (default) or responses. Can be overridden per request. See API Endpoints.Additional HTTP headers merged into every outbound request. When
apiKey is also set, the Authorization header from apiKey is added first via array_merge; because PHP array_merge lets later string keys overwrite earlier ones, a conflicting Authorization entry in headers will override the apiKey value.A custom
AiSdk\Support\Sdk instance. Use this in tests or when you need to inject a custom HTTP client or PSR factory. When omitted, the SDK-level default (Generate::sdk()) is used.Singleton behavior
Ollama::create() stores the returned OllamaProvider as the process-level default. All static helper methods — Ollama::model(), Ollama::availableModels(), Ollama::inspectModel() — delegate to this singleton. If Ollama::create() has not been called yet, the first access to Ollama::default() auto-initialises a provider using only environment variables and built-in defaults.
Call Ollama::reset() to clear the singleton, for example between test cases:
