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.

The PHP AI SDK Ollama provider connects your PHP application to any model running on a local or remote Ollama server. It supports the full generation surface — text, streaming, embeddings, and experimental image generation — through a clean, framework-agnostic interface that works with any PSR-18 HTTP client.

Installation

Install via Composer and get the provider running in under a minute

Quickstart

Generate your first response from a local Ollama model

Guides

Explore text generation, streaming, embeddings, and image generation

API Reference

Full reference for the Ollama facade, provider, models, and types

What’s included

Text Generation

Chat Completions and Responses API support, with vision, tool calling, reasoning, and structured output

Streaming

Real-time server-sent event streaming for any installed text model

Embeddings

Native batch embeddings via Ollama’s /api/embed endpoint with dimension control

Image Generation

Experimental image generation through Ollama’s OpenAI-compatible endpoint

Model Discovery

List installed models and inspect their capabilities from the live server

Configuration

Base URL, native URL, API key, and per-request API endpoint overrides

Getting started

1

Install the package

Add the provider to your project with Composer:
composer require aisdk/ollama
2

Start Ollama

Make sure Ollama is running locally with at least one model pulled:
ollama pull llama3.2
ollama serve
3

Generate your first response

use AiSdk\Generate;
use AiSdk\Ollama;

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

echo $result->text;
No API key is required for a local Ollama server. The provider defaults to http://localhost:11434/v1. See Configuration if your server runs elsewhere or requires authentication.

Build docs developers (and LLMs) love