A unified interface for multiple AI providers in Laravel applications.
- Support for multiple AI providers (OpenAI, Gemini, Claude, DeepSeek, Mistral, and Cohere)
- Unified API interface
- Easy driver switching
- Standardized response format
- Facade access
- Install via Composer:
composer require omer-hanaraey/laravel-ai-gateway
- Publish the configuration file:
php artisan vendor:publish --tag=ai-bridge-config
Add your API keys to your .env file:
AI_DEFAULT_DRIVER=openai
OPENAI_API_KEY=your_openai_key
OPENAI_MODEL=gpt-3.5-turbo
GEMINI_API_KEY=your_gemini_key
GEMINI_MODEL=gemini-pro
CLAUDE_API_KEY=your_claude_key
CLAUDE_MODEL=claude-2
DEEPSEEK_API_KEY=your_deepseek_key
DEEPSEEK_MODEL=deepseek-chat
MISTRAL_API_KEY=your_mistral_key
MISTRAL_MODEL=mistral-large-latest
COHERE_API_KEY=your_cohere_key
COHERE_MODEL=command-a-03-2025
COHERE_CLIENT_NAME=your_cohere_client
Usage Examples 🧑💻
use LaravelAiGateway\Ai\Facades\Ai;
$response = Ai::chat([
['role' => 'system', 'content' => 'You are a helpful assistant'],
['role' => 'user', 'content' => 'Tell me a joke about Laravel']
]);
echo $response->getContent();
Using Specific Drivers
$response = Ai::driver('claude')
->withModel('claude-3-haiku-20240307')
->chat([...]);
chat(array $messages)
: Send chat completiondriver(string $name)
: Switch between providers
All responses implement AiResponseInterface
with these methods:
getContent()
: string - Get the response contentgetUsage()
: array - Get usage statisticsisSuccessful()
: bool - Check if request succeeded
Run the tests with:
composer test tests
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
MIT License - Free for commercial and personal use.