PHPackages                             aisdk/ollama - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. aisdk/ollama

ActiveLibrary

aisdk/ollama
============

Official Ollama provider for the PHP AI SDK.

v0.8.0(1mo ago)113↓25%MITPHPPHP ^8.3CI passing

Since Jul 11Pushed 1mo agoCompare

[ Source](https://github.com/phpaisdk/ollama)[ Packagist](https://packagist.org/packages/aisdk/ollama)[ Docs](https://github.com/phpaisdk/ollama)[ RSS](/packages/aisdk-ollama/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (7)Versions (7)Used By (0)

aisdk/ollama
============

[](#aisdkollama)

[![GitHub Workflow Status](https://camo.githubusercontent.com/fda96641009850b8494bd9d8149391d2bce0f612f5b7bae71e2c27847cec8c05/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706870616973646b2f6f6c6c616d612f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473)](https://github.com/phpaisdk/ollama/actions)[![Total Downloads](https://camo.githubusercontent.com/ad66b9405ec93a13328f23f30f1480ec5b822033ccb02f92d35d034aba91332c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616973646b2f6f6c6c616d61)](https://packagist.org/packages/aisdk/ollama)[![Latest Version](https://camo.githubusercontent.com/270f93737b4878edbf0a02f6476b0f6eeef1ad8d89a5d9057b9499e8c9039ca0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616973646b2f6f6c6c616d61)](https://packagist.org/packages/aisdk/ollama)[![License](https://camo.githubusercontent.com/4de55d7af095e9270c943e615521f70af4f29f0019befd389d903f35ced20e34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616973646b2f6f6c6c616d61)](https://packagist.org/packages/aisdk/ollama)[![Why PHP in 2026](https://camo.githubusercontent.com/d2b9305e630caf7daae4ca023de39ece0b885c37461629d42961533f00868b76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5768795f5048502d696e5f323032362d3741383645383f7374796c653d666c61742d737175617265266c6162656c436f6c6f723d313831383162)](https://whyphp.dev)

---

Official Ollama provider for the framework-agnostic PHP AI SDK. It supports text, streaming, native embeddings, and Ollama's experimental OpenAI-compatible image endpoint.

Installation
------------

[](#installation)

```
composer require aisdk/ollama
```

Basic Usage
-----------

[](#basic-usage)

```
use AiSdk\Generate;
use AiSdk\Ollama;

$result = Generate::text()
    ->model(Ollama::model('your-installed-model'))
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;
```

Any model installed on the configured Ollama server can be selected. Like every AI SDK provider package, this package treats model IDs as opaque provider values and does not ship a model inventory.

Ollama's OpenAI-compatible Chat Completions endpoint is the default. Select the Responses endpoint globally or per request when needed:

```
Ollama::create(['api' => 'responses']);

$result = Generate::text('Explain this code.')
    ->model(Ollama::model('your-installed-model'))
    ->providerOptions('ollama', ['api' => 'responses'])
    ->run();
```

Supported values are `chat_completions` and `responses`. Chat Completions supports Ollama's documented vision, function tools, reasoning effort, and structured-output fields. Ollama Responses supports streaming and function tools, but its documented request fields do not currently expose reasoning or structured-output controls. The selected installed model remains responsible for accepting model-dependent features.

Available models
----------------

[](#available-models)

Read the current server registry instead of relying on package data:

```
$models = Ollama::availableModels();

foreach ($models as $model) {
    echo $model->id;
}
```

`availableModels()` calls Ollama's native `/api/tags` endpoint. To load a model's optional capabilities—such as embeddings, vision, tools, audio input, or thinking—inspect it explicitly:

```
$definition = Ollama::inspectModel('your-installed-model');

if (in_array('image_input', $definition->capabilityNames(), true)) {
    // The installed model advertises vision support.
}
```

Inspection calls `/api/show` and returns informational details reported by the current Ollama server. It does not change adapter behavior, and ordinary generation does not perform hidden discovery requests.

Embeddings
----------

[](#embeddings)

Ollama embeddings use the native `/api/embed` endpoint and accept one text or a batch:

```
use AiSdk\Generate;
use AiSdk\Ollama;

$result = Generate::embedding(['Search query', 'Document text'])
    ->model(Ollama::model('embeddinggemma'))
    ->dimensions(256)
    ->providerOptions('ollama', [
        'truncate' => false,
        'keep_alive' => '10m',
    ])
    ->run();

$queryVector = $result->embeddings[0]->vector;
$documentVector = $result->embeddings[1]->vector;
```

`truncate` and `keep_alive` are passed to Ollama unchanged. The selected installed model remains the authority on supported output dimensions.

Image generation
----------------

[](#image-generation)

```
$image = Generate::image('A small robot')
    ->model(Ollama::model('your-installed-image-model'))
    ->size('1024x1024')
    ->run();
```

Image generation is experimental in Ollama. Ollama does not currently expose an OpenAI-compatible speech endpoint, so this package intentionally does not implement `Generate::speech()`.

Streaming
---------

[](#streaming)

```
use AiSdk\Generate;
use AiSdk\Ollama;

foreach (Generate::text('Tell me a story.')->model(Ollama::model('your-installed-model'))->stream()->chunks() as $chunk) {
    echo $chunk;
}
```

Configuration
-------------

[](#configuration)

No API key is required for a local Ollama server. Provide one only if your server is protected.

VariableDescriptionDefault`OLLAMA_BASE_URL`Base URL for the OpenAI-compatible API`http://localhost:11434/v1``OLLAMA_NATIVE_BASE_URL`Base URL for native API endpointsDerived by removing `/v1` from `OLLAMA_BASE_URL``OLLAMA_API_KEY`Optional bearer token—```
Ollama::create([
    'baseUrl' => 'http://localhost:11434/v1',
    'nativeBaseUrl' => 'http://localhost:11434',
]);
```

Testing
-------

[](#testing)

```
composer test
```

Documentation
-------------

[](#documentation)

- [PHP AI SDK documentation](https://phpaisdk.com/docs)
- [Ollama documentation](https://phpaisdk.com/docs/ollama)

Community
---------

[](#community)

- [Contributing](https://github.com/phpaisdk/.github/blob/main/CONTRIBUTING.md)
- [Support](https://github.com/phpaisdk/.github/blob/main/SUPPORT.md)
- For private security reports, email .

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef29d1962da41e7526023f215cf844494e209b2fd163742084cb919a3b508021?d=identicon)[aisdk](/maintainers/aisdk)

---

Top Contributors

[![RanaMoizHaider](https://avatars.githubusercontent.com/u/58527494?v=4)](https://github.com/RanaMoizHaider "RanaMoizHaider (11 commits)")

---

Tags

ailocalllmollamaopenai-compatibleaisdk

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aisdk-ollama/health.svg)

```
[![Health](https://phpackages.com/badges/aisdk-ollama/health.svg)](https://phpackages.com/packages/aisdk-ollama)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
