A provider-agnostic AI library for PHP. Supports chat completions, embeddings, image generation, tool calling, and streaming across multiple providers (OpenAI, Google, Anthropic, AWS Bedrock).
- Provider-Agnostic — Common interface across OpenAI, Google, Anthropic, and AWS Bedrock
- Chat Completions — Send messages and receive AI-generated responses
- Streaming — Token-by-token streaming via Server-Sent Events
- Embeddings — Generate vector embeddings for semantic search
- Image Generation — Generate images from text prompts
- Tool/Function Calling — Define tools the AI can invoke during conversation
- Conversation Management — Built-in conversation history with swappable storage
- Enterprise Ready — Retry logic, rate limiting, caching, health checks, metrics, audit logging
| Build Status |
|---|
composer require webfiori/ai<?php
use WebFiori\Ai\Provider\OpenAI\OpenAIClient;
use WebFiori\Ai\Message;
$client = new OpenAIClient([
'api_key' => 'sk-...',
'model' => 'gpt-4o',
]);
$response = $client->chat([
new Message('system', 'You are a helpful assistant.'),
new Message('user', 'What is PHP?'),
]);
echo $response->getMessage()->getContent();$client->streamChat(
messages: [
new Message('user', 'Write a story about PHP'),
],
onToken: function (string $token) {
echo $token;
flush();
},
);use WebFiori\Ai\Provider\Google\GoogleClient;
$client = new GoogleClient([
'api_key' => 'your-gemini-api-key',
'model' => 'gemini-2.5-flash',
]);
$response = $client->chat([
new Message('user', 'What is PHP?'),
]);Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for a list of changes and version history.