PHPackages                             ardagnsrn/ollama-php - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ardagnsrn/ollama-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ardagnsrn/ollama-php
====================

This is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform for running LLMs on your local machine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and customizable AI experience.

1.0.5(1y ago)21284.7k↓26.3%22[5 issues](https://github.com/ArdaGnsrn/ollama-php/issues)[1 PRs](https://github.com/ArdaGnsrn/ollama-php/pulls)MITPHPPHP ^8.1CI passing

Since Aug 14Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/ArdaGnsrn/ollama-php)[ Packagist](https://packagist.org/packages/ardagnsrn/ollama-php)[ Docs](https://github.com/ardagnsrn/ollama-php)[ RSS](/packages/ardagnsrn-ollama-php/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (7)Used By (0)

Ollama PHP Library
==================

[](#ollama-php-library)

This is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform for running LLMs on your local machine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and customizable AI experience.

[![Total Downloads](https://camo.githubusercontent.com/ad01a8c1c6e466a7a93c75d1363d36102061fafff866c6bbc1baad27de966e7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61726461676e73726e2f6f6c6c616d612d706870)](https://packagist.org/packages/ardagnsrn/ollama-php)[![Latest Version](https://camo.githubusercontent.com/58bace4e89b934d35ae09cad87a23592e4bbf4be468e5ebf82765c9712328d3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61726461676e73726e2f6f6c6c616d612d706870)](https://packagist.org/packages/ardagnsrn/ollama-php)[![License](https://camo.githubusercontent.com/0fe4a9acc16df01ff709e2b9ce23197123e3c8f6ecf6d0b02fe83532a2f70791/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f61726461676e73726e2f6f6c6c616d612d706870)](https://packagist.org/packages/ardagnsrn/ollama-php)

☕️ Buy me a coffee
------------------

[](#️-buy-me-a-coffee)

Whether you use this project, have learned something from it, or just like it, please consider supporting it by buying me a coffee, so I can dedicate more time on open-source projects like this :)

[![Buy Me A Coffee](https://camo.githubusercontent.com/9f44ce2dc3b3eecdd02598900866ffc518801df1932849703dae1e5ce5031070/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f637573746f6d5f696d616765732f6f72616e67655f696d672e706e67)](https://www.buymeacoffee.com/ardagnsrn)

Table of Contents
-----------------

[](#table-of-contents)

- [Get Started](#get-started)
- [Usage](#usage)
    - [Completions Resource](#completions-resource)
        - [create()](#create)
        - [createStreamed()](#createstreamed)
    - [Chat Resource](#chat-resource)
        - [create()](#create-1)
        - [createStreamed()](#createstreamed-1)
    - [Models Resource](#models-resource)
        - [list()](#list)
        - [show()](#show)
        - [create()](#create-2)
        - [createStreamed()](#createstreamed-2)
        - [copy()](#copy)
        - [delete()](#delete)
        - [pull()](#pull)
        - [pullStreamed()](#pullstreamed)
        - [push()](#push)
        - [pushStreamed()](#pushstreamed)
        - [runningList()](#runninglist)
    - [Blobs Resource](#blobs-resource)
        - [exists()](#exists)
        - [create()](#create-3)
    - [Embed Resource](#embed-resource)
        - [create()](#create-4)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

Get Started
-----------

[](#get-started)

> **Requires [PHP 8.1+](https://php.net/releases/)**
> **Requires [Ollama](https://ollama.com/)**

> You can find Official Ollama documentation [here](https://github.com/ollama/ollama/blob/main/docs/api.md).

First, install Ollama PHP via the [Composer](https://getcomposer.org/) package manager:

```
composer require ardagnsrn/ollama-php
```

Then, you can create a new Ollama client instance:

```
// with default base URL
$client = \ArdaGnsrn\Ollama\Ollama::client();

// or with custom base URL
$client = \ArdaGnsrn\Ollama\Ollama::client('http://localhost:11434');
```

Usage
-----

[](#usage)

### `Completions` Resource

[](#completions-resource)

#### `create`

[](#create)

Generate a response for a given prompt with a provided model.

```
$completions = $client->completions()->create([
    'model' => 'llama3.1',
    'prompt' => 'Once upon a time',
]);

$completions->response; // '...in a land far, far away...'

$response->toArray(); // ['model' => 'llama3.1', 'response' => '...in a land far, far away...', ...]
```

#### `createStreamed`

[](#createstreamed)

Generate a response for a given prompt with a provided model and stream the response.

```
$completions = $client->completions()->createStreamed([
    'model' => 'llama3.1',
    'prompt' => 'Once upon a time',
]);

foreach ($completions as $completion) {
    echo $completion->response;
}
// 1. Iteration: '...in'
// 2. Iteration: ' a'
// 3. Iteration: ' land'
// 4. Iteration: ' far,'
// ...
```

### `Chat` Resource

[](#chat-resource)

#### `create`

[](#create-1)

Generate a response for a given prompt with a provided model.

```
$response = $client->chat()->create([
    'model' => 'llama3.1',
    'messages' => [
        ['role' => 'system', 'content' => 'You are a llama.'],
        ['role' => 'user', 'content' => 'Hello!'],
        ['role' => 'assistant', 'content' => 'Hi! How can I help you today?'],
        ['role' => 'user', 'content' => 'I need help with my taxes.'],
    ],
]);

$response->message->content; // 'Ah, taxes... *chew chew* Hmm, not really sure how to help with that.'

$response->toArray(); // ['model' => 'llama3.1', 'message' => ['role' => 'assistant', 'content' => 'Ah, taxes...'], ...]
```

Also, you can use the `tools` parameter to provide custom functions to the chat. **`tools` parameter can not be used with `createStreamed` method.**

```
$response = $client->chat()->create([
    'model' => 'llama3.1',
    'messages' => [
        ['role' => 'user', 'content' => 'What is the weather today in Paris?'],
    ],
    'tools' => [
        [
            'type' => 'function',
            'function' => [
                'name' => 'get_current_weather',
                'description' => 'Get the current weather',
                'parameters' => [
                    'type' => 'object',
                    'properties' => [
                        'location' => [
                            'type' => 'string',
                            'description' => 'The location to get the weather for, e.g. San Francisco, CA',
                        ],
                        'format' => [
                            'type' => 'string',
                            'description' => 'The location to get the weather for, e.g. San Francisco, CA',
                            'enum' => ['celsius', 'fahrenheit']
                        ],
                    ],
                    'required' => ['location', 'format'],
                ],
            ],
        ]
    ]
]);

$toolCall = $response->message->toolCalls[0];

$toolCall->function->name; // 'get_current_weather'
$toolCall->function->arguments; // ['location' => 'Paris', 'format' => 'celsius']

$response->toArray(); // ['model' => 'llama3.1', 'message' => ['role' => 'assistant', 'toolCalls' => [...]], ...]
```

#### `createStreamed`

[](#createstreamed-1)

Generate a response for a given prompt with a provided model and stream the response.

```
$responses = $client->chat()->createStreamed([
    'model' => 'llama3.1',
    'messages' => [
        ['role' => 'system', 'content' => 'You are a llama.'],
        ['role' => 'user', 'content' => 'Hello!'],
        ['role' => 'assistant', 'content' => 'Hi! How can I help you today?'],
        ['role' => 'user', 'content' => 'I need help with my taxes.'],
    ],
]);

foreach ($responses as $response) {
    echo $response->message->content;
}
// 1. Iteration: 'Ah,'
// 2. Iteration: ' taxes'
// 3. Iteration: '... '
// 4. Iteration: ' *chew,'
// ...
```

### `Models` Resource

[](#models-resource)

#### `list`

[](#list)

List all available models.

```
$response = $client->models()->list();

$response->toArray(); // ['models' => [['name' => 'llama3.1', ...], ['name' => 'llama3.1:80b', ...], ...]]
```

### `show`

[](#show)

Show details of a specific model.

```
$response = $client->models()->show('llama3.1');

$response->toArray(); // ['modelfile' => '...', 'parameters' => '...', 'template' => '...']
```

### `create`

[](#create-2)

Create a new model.

```
$response = $client->models()->create([
    'name' => 'mario',
    'modelfile' => "FROM llama3.1\nSYSTEM You are mario from Super Mario Bros."
]);

$response->status; // 'success'
```

### `createStreamed`

[](#createstreamed-2)

Create a new model and stream the response.

```
$responses = $client->models()->createStreamed([
    'name' => 'mario',
    'modelfile' => "FROM llama3.1\nSYSTEM You are mario from Super Mario Bros."
]);

foreach ($responses as $response) {
    echo $response->status;
}
```

### `copy`

[](#copy)

Copy an existing model.

```
$client->models()->copy('llama3.1', 'llama3.2'); // bool
```

### `delete`

[](#delete)

Delete a model.

```
$client->models()->delete('mario'); // bool
```

### `pull`

[](#pull)

Pull a model from the Ollama server.

```
$response = $client->models()->pull('llama3.1');
$response->toArray() // ['status' => 'downloading digestname', 'digest' => 'digestname', 'total' => 2142590208, 'completed' => 241970]
```

### `pullStreamed`

[](#pullstreamed)

Pull a model from the Ollama server and stream the response.

```
$responses = $client->models()->pullStreamed('llama3.1');

foreach ($responses as $response) {
    echo $response->status;
}
```

### `push`

[](#push)

Push a model to the Ollama server.

```
$response = $client->models()->push('llama3.1');
$response->toArray() // ['status' => 'uploading digestname', 'digest' => 'digestname', 'total' => 2142590208]
```

### `pushStreamed`

[](#pushstreamed)

Push a model to the Ollama server and stream the response.

```
$responses = $client->models()->pushStreamed('llama3.1');

foreach ($responses as $response) {
    echo $response->status;
}
```

### `runningList`

[](#runninglist)

List all running models.

```
$response = $client->models()->runningList();

$response->toArray(); // ['models' => [['name' => 'llama3.1', ...], ['name' => 'llama3.1:80b', ...], ...]]
```

### `Blobs` Resource

[](#blobs-resource)

#### `exists`

[](#exists)

Check if a blob exists.

```
$client->blobs()->exists('blobname'); // bool
```

#### `create`

[](#create-3)

Create a new blob.

```
$client->blobs()->create('blobname'); // bool
```

### `Embed` Resource

[](#embed-resource)

#### `create`

[](#create-4)

Generate an embedding for a given text with a provided model.

```
$response = $client->embed()->create([
    'model' => 'llama3.1',
    'input' => [
        "Why is the sky blue?",
    ]
]);

$response->toArray(); // ['model' => 'llama3.1', 'embedding' => [0.1, 0.2, ...], ...]
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Arda GUNSUREN](https://github.com/ArdaGnsrn)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance72

Regular maintenance activity

Popularity51

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.2% 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 ~60 days

Recently: every ~43 days

Total

6

Last Release

386d ago

### Community

Maintainers

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

---

Top Contributors

[![ArdaGnsrn](https://avatars.githubusercontent.com/u/52893305?v=4)](https://github.com/ArdaGnsrn "ArdaGnsrn (30 commits)")[![sixty-nine](https://avatars.githubusercontent.com/u/398679?v=4)](https://github.com/sixty-nine "sixty-nine (2 commits)")[![ChobPT](https://avatars.githubusercontent.com/u/45816945?v=4)](https://github.com/ChobPT "ChobPT (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

llamallama3llmollamaollama-apiollama-phpopen-source-llmaillmllamamistralollamaArdaGnsrnllama3.1ollama-phpgemma2

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.7k409.0k6](/packages/theodo-group-llphant)[symfony/ai-platform

PHP library for interacting with AI platform provider.

521.4M289](/packages/symfony-ai-platform)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

318123.0k1](/packages/cognesy-instructor-php)

PHPackages © 2026

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