Ollama provider for the PHP AI Client SDK. Works as both a Composer package with the php-ai-client package and as a WordPress plugin with the wp-ai-client plugin.
Ollama lets you run large language models locally or remotely. Ollama exposes an OpenAI-compatible API, and this provider uses that API to communicate with any model you have pulled into Ollama (Llama, Mistral, Gemma, Phi, and many more) or any available Ollama Cloud model.
- PHP 7.4+
- php-ai-client
^0.4or wp-ai-client^0.2 - Ollama running locally or remotely (like Ollama Cloud)
- Install and activate the wp-ai-client plugin.
- Place this plugin in your
wp-content/plugins/directory. - Activate "WordPress AI Client Provider for Ollama" from the Plugins screen.
composer require wordpress/ai-client-provider-ollamaBy default, the provider connects to http://localhost:11434. You can change this in two ways:
- Environment variable (takes precedence): Set the
OLLAMA_HOSTenvironment variable. - WordPress admin: Go to Settings > Ollama Settings and enter your Ollama host URL.
For local Ollama instances, no API key is needed. The plugin automatically registers an empty API key as a fallback.
For remote Ollama instances that require authentication (e.g., Ollama Cloud), enter the API key in the wp-ai-client Settings > AI Credentials screen. If using Ollama Cloud, you also need to set your Ollama host URL in the Settings > Ollama Settings screen to https://ollama.com.
use WordPress\AI_Client\Prompt_Builder;
$result = Prompt_Builder::create()
->using_provider( 'ollama' )
->set_system_instruction( 'You are a helpful assistant.' )
->add_text_message( 'Hello, how are you?' )
->generate_text();use WordPress\AiClient\AiClient;
use WordPress\AiClient\Providers\Http\DTO\ApiKeyRequestAuthentication;
use WordPress\AiClientProviderOllama\Provider\OllamaProvider;
require_once 'vendor/autoload.php';
$registry = AiClient::defaultRegistry();
$registry->registerProvider(OllamaProvider::class);
$registry->setProviderRequestAuthentication('ollama', new ApiKeyRequestAuthentication(''));
$result = AiClient::prompt('Hello!')
->usingProvider('ollama')
->generateText();