Skip to main content

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.

aisdk/ollama is installed like any Composer package. Before you begin, make sure your local environment satisfies the prerequisites below — specifically that an Ollama server is reachable, because every API call the SDK makes is a live HTTP request to that server.

System Requirements

RequirementDetails
PHP^8.3
ComposerAny current version
OllamaA running Ollama server. See ollama.com for installation instructions.
PSR-18 HTTP clientAny PSR-18-compliant client: Guzzle, Symfony HTTP Client, or another. The SDK uses PSR-18 discovery to find your client automatically.

Installation

1

Install the package via Composer

Run the following command in your project root:
composer require aisdk/ollama
This installs aisdk/ollama and its two dependencies — aisdk/core and aisdk/openai-compatible — into your vendor/ directory.
2

Pull a model from the Ollama library

Use the Ollama CLI to download a model onto your server. For example, to pull Llama 3.2:
ollama pull llama3.2
Pass the same model name string to Ollama::model() when constructing requests. Any model available in the Ollama library can be pulled this way.
3

Verify Ollama is running

Start the Ollama server if it is not already running:
ollama serve
To confirm the server is reachable and inspect your installed models, call the native tags endpoint:
curl http://localhost:11434/api/tags
A successful response returns a JSON object listing every model available on the server. The SDK’s Ollama::availableModels() method calls this same endpoint.

Autoloading

The package registers two PSR-4 namespace mappings in its composer.json:
NamespaceSource directoryWhat lives here
AiSdk\src/Root/The Ollama static facade — the primary entry point
AiSdk\Ollama\src/OllamaProvider, OllamaOptions, model adapters, and supporting classes
Composer’s autoloader handles both namespaces automatically after composer require. You do not need to add any require or include statements in your code.
// Both classes are available immediately after autoloading
use AiSdk\Ollama;            // from src/Root/Ollama.php
use AiSdk\Ollama\OllamaOptions; // from src/OllamaOptions.php

Environment Variables

The provider reads optional configuration from your environment. Set these in your .env file or shell before any SDK calls are made:
VariableDescriptionDefault
OLLAMA_BASE_URLBase URL for the OpenAI-compatible APIhttp://localhost:11434/v1
OLLAMA_NATIVE_BASE_URLBase URL for native API endpoints (tags, show, embed)Derived by stripping /v1 from OLLAMA_BASE_URL
OLLAMA_API_KEYOptional bearer token for protected servers
You can also set these programmatically at bootstrap time by calling Ollama::create():
use AiSdk\Ollama;

Ollama::create([
    'baseUrl'       => 'http://localhost:11434/v1',
    'nativeBaseUrl' => 'http://localhost:11434',
]);
No API key is needed when connecting to a local Ollama server. OLLAMA_API_KEY is only required if your Ollama instance is hosted remotely or sits behind an authenticating reverse proxy that expects a bearer token.

Build docs developers (and LLMs) love