PHPackages                             halilcosdu/laravel-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. [API Development](/categories/api)
4. /
5. halilcosdu/laravel-ollama

ActiveLibrary[API Development](/categories/api)

halilcosdu/laravel-ollama
=========================

Laravel Ollama API Wrapper - Interact with the Ollama API

v1.1.0(yesterday)269711MITPHPPHP ^8.2CI failing

Since Apr 23Pushed yesterday1 watchersCompare

[ Source](https://github.com/halilcosdu/laravel-ollama)[ Packagist](https://packagist.org/packages/halilcosdu/laravel-ollama)[ Docs](https://github.com/halilcosdu/laravel-ollama)[ Fund](https://www.buymeacoffee.com/halilcosdu5)[ RSS](/packages/halilcosdu-laravel-ollama/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (39)Versions (11)Used By (0)

Laravel Ollama
--------------

[](#laravel-ollama)

[![Latest Version on Packagist](https://camo.githubusercontent.com/69ae6ec66a90db5d3c69df843818e04841ce6eee429e3600a2890dbe30f50c4c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616c696c636f7364752f6c61726176656c2d6f6c6c616d612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/halilcosdu/laravel-ollama)[![GitHub Tests Action Status](https://camo.githubusercontent.com/788731cd5d97b43582793c917a5e5627c98979aea4cfd9d80b1745ce4279e495/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f68616c696c636f7364752f6c61726176656c2d6f6c6c616d612f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/halilcosdu/laravel-ollama/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f2d7f18d8dc816861a1769917009a8e59f690af105d34a05085dc880df9648ff/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f68616c696c636f7364752f6c61726176656c2d6f6c6c616d612f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/halilcosdu/laravel-ollama/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/52df3b65bb03186eacf4820470e0c97f7a3216afc556470d843c28251d723395/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616c696c636f7364752f6c61726176656c2d6f6c6c616d612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/halilcosdu/laravel-ollama)

Laravel Ollama is a PHP package that provides a simple and intuitive interface for interacting with the Ollama API. It is designed to be used with Laravel, a popular PHP framework, but can also be used in any PHP application. This package provides a set of methods for making requests to the Ollama API, including methods for setting the agent, prompt, model, format, options, and more. It also includes methods for handling responses from the API, such as retrieving the response in a specific format or streaming the response. With Laravel Ollama, you can easily integrate the Ollama API into your Laravel application and start making requests in a matter of minutes.
Features

- Easy configuration
- Fluent interface: chain methods together to build your requests.
- Flexible
- Covers the Ollama API endpoints: generate, chat, models, show, copy, delete, pull, push, create, embed, ps, version, embeddings (deprecated).

> **Notes**
>
> - `embeddings()` is deprecated upstream (POST /api/embeddings). Prefer `embed()` (POST /api/embed) for new code.
> - For chat with images, include base64-encoded images inside the relevant message's `images` array (per the Ollama chat schema); the fluent `image()` setter only applies to `ask()` (generate).

This package builds upon the foundational work provided by the Ollama Laravel package developed by [Cloud Studio](https://github.com/cloudstudio/ollama-laravel). Special thanks to them for their innovative approach and contributions to the Laravel community.

★ In the near future, I will add more features to this package.

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

[](#installation)

You can install the package via composer:

```
composer require halilcosdu/laravel-ollama
```

You can publish the config file with:

```
php artisan vendor:publish --tag="ollama-config"
```

This is the contents of the published config file:

```
return [
    'model' => env('OLLAMA_MODEL', 'llama3'),
    'url' => env('OLLAMA_URL', 'http://127.0.0.1:11434'),
    'default_prompt' => env('OLLAMA_DEFAULT_PROMPT', 'Hello world!'),
    'connection' => [
        'timeout' => env('OLLAMA_CONNECTION_TIMEOUT', 30),
    ],
];
```

Usage
-----

[](#usage)

```
@method static \HalilCosdu\Ollama\Ollama agent(string $agent): static
@method static \HalilCosdu\Ollama\Ollama getAgent(): string
@method static \HalilCosdu\Ollama\Ollama prompt(string $prompt): static
@method static \HalilCosdu\Ollama\Ollama getPrompt(): string
@method static \HalilCosdu\Ollama\Ollama model(string $model): static
@method static \HalilCosdu\Ollama\Ollama getModel()
@method static \HalilCosdu\Ollama\Ollama format(string $format): static
@method static \HalilCosdu\Ollama\Ollama getFormat(): string
@method static \HalilCosdu\Ollama\Ollama options(array $options = []): static
@method static \HalilCosdu\Ollama\Ollama getOptions(): array
@method static \HalilCosdu\Ollama\Ollama stream(bool $stream = false): static
@method static \HalilCosdu\Ollama\Ollama getStream(): bool
@method static \HalilCosdu\Ollama\Ollama raw(bool $raw): static
@method static \HalilCosdu\Ollama\Ollama getRaw(): bool
@method static \HalilCosdu\Ollama\Ollama models(): array
@method static \HalilCosdu\Ollama\Ollama show()
@method static \HalilCosdu\Ollama\Ollama copy(string $destination): static
@method static \HalilCosdu\Ollama\Ollama delete(): static
@method static \HalilCosdu\Ollama\Ollama pull(): static
@method static \HalilCosdu\Ollama\Ollama image(string $imagePath): static
@method static \HalilCosdu\Ollama\Ollama getImage(): ?string
@method static \HalilCosdu\Ollama\Ollama tools(array $tools): static
@method static \HalilCosdu\Ollama\Ollama getTools(): array
@method static \HalilCosdu\Ollama\Ollama embeddings(string $prompt)
@method static \HalilCosdu\Ollama\Ollama embed(string|array $input)
@method static \HalilCosdu\Ollama\Ollama ps()
@method static \HalilCosdu\Ollama\Ollama version()
@method static \HalilCosdu\Ollama\Ollama push(): static
@method static \HalilCosdu\Ollama\Ollama create(string $modelfile): static
@method static \HalilCosdu\Ollama\Ollama getKeepAlive(): string
@method static \HalilCosdu\Ollama\Ollama keepAlive(string $keepAlive): static
@method static \HalilCosdu\Ollama\Ollama ask()
@method static \HalilCosdu\Ollama\Ollama chat(array $conversation)
@method static \HalilCosdu\Ollama\Ollama toArray(): array
@method static \HalilCosdu\Ollama\Ollama toJson($options = 0): false|string
```

Usage
-----

[](#usage-1)

### Basic Usage

[](#basic-usage)

```
use HalilCosdu\Ollama\Facades\Ollama;

$response = Ollama::agent('You are a weather expert...')
    ->prompt('Why is the sky blue?')
    ->model('llama3')
    ->options(['temperature' => 0.8])
    ->stream(false)
    ->ask();
```

### Vision Support

[](#vision-support)

```
$response = Ollama::model('llava:13b')
    ->prompt('What is in this picture?')
    ->image(public_path('images/example.jpg'))
    ->ask();

// "The image features a close-up of a person's hand, wearing bright pink fingernail polish and blue nail polish. In addition to the colorful nails, the hand has two tattoos – one is a cross and the other is an eye."
```

### Chat Completion

[](#chat-completion)

```
$messages = [
    ['role' => 'user', 'content' => 'My name is Halil Cosdu and I live in Turkey'],
    ['role' => 'assistant', 'content' => 'Nice to meet you , Halil Cosdu'],
    ['role' => 'user', 'content' => 'where I live ?'],
];

$response = Ollama::agent('You know me really well!')
    ->model('llama3')
    ->chat($messages);

// "You mentioned that you live in Turkey."
```

### Show Model Information

[](#show-model-information)

```
$response = Ollama::model('llama3')->show();
```

### Copy a Model

[](#copy-a-model)

```
Ollama::model('llama3')->copy('NewModel');
```

### Delete a Model

[](#delete-a-model)

```
Ollama::model('llama3')->delete();
```

### Generate Embeddings

[](#generate-embeddings)

```
// New: /api/embed (preferred) — accepts a string or an array of inputs.
$embeddings = Ollama::model('llama3')->embed('Your prompt here');
$embeddings = Ollama::model('llama3')->embed(['first', 'second']);

// Deprecated: /api/embeddings (kept for backwards compatibility).
$embeddings = Ollama::model('llama3')->embeddings('Your prompt here');
```

### Tool Calling (Function Calling)

[](#tool-calling-function-calling)

```
$tools = [
    [
        'type' => 'function',
        'function' => [
            'name' => 'get_weather',
            'description' => 'Get the weather for a city',
            'parameters' => [
                'type' => 'object',
                'properties' => ['city' => ['type' => 'string']],
                'required' => ['city'],
            ],
        ],
    ],
];

$response = Ollama::model('llama3')
    ->tools($tools)
    ->chat([['role' => 'user', 'content' => 'Weather in Istanbul?']]);
```

### Running Models &amp; Server Version

[](#running-models--server-version)

```
Ollama::ps();       // GET /api/ps — models currently loaded into memory.
Ollama::version();  // GET /api/version — running Ollama server version.
```

### Push / Create a Model

[](#push--create-a-model)

```
Ollama::model('myorg/mymodel')->push();
Ollama::model('my-model')->create("FROM llama3\nSYSTEM You are helpful.");
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Halil Cosdu](https://github.com/halilcosdu)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

53

↑

FairBetter than 96% of packages

Maintenance100

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 71.7% 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 ~200 days

Total

5

Last Release

1d ago

Major Versions

v0.0.2 → v1.0.02026-04-09

### Community

Maintainers

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

---

Top Contributors

[![halilcosdu](https://avatars.githubusercontent.com/u/6373017?v=4)](https://github.com/halilcosdu "halilcosdu (38 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (1 commits)")

---

Tags

laravelHalilCosdularavel-ollama

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

44855.7k](/packages/harris21-laravel-fuse)

PHPackages © 2026

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