symfony/ai-failover-platform
Symfony AI Failover Platform bridge that adds resilient fallback behavior across AI providers. Integrates with Symfony AI to automatically switch to alternate platforms on errors or outages, improving availability and reliability in production deployments.
symfony/ai) in a Laravel stack.symfony/http-client).*"This package eliminates AI downtime by automatically switching to backup providers if our primary service (e.g., OpenAI) fails—without manual intervention. It’s a turnkey solution to avoid costly disruptions, degraded user experiences, or lost revenue. For example:
Key Outcomes:
Ask: Should we prioritize this for our [critical AI feature, e.g., customer support chatbot] to ensure reliability at scale?"*
*"Symfony’s AI Failover Platform gives us a battle-tested way to handle AI provider failures with minimal code. Here’s how we’d integrate it into Laravel:
Dependencies:
composer require symfony/ai symfony/ai-failover-platform
symfony/http-client) using package aliases or Laravel’s composer.json overrides.Service Provider Setup:
Bind Symfony’s FailoverClient to Laravel’s container in AppServiceProvider:
public function register() {
$this->app->singleton(\Symfony\Component\Ai\Failover\FailoverClient::class, function ($app) {
return new \Symfony\Component\Ai\Failover\FailoverClient(
$app->make(\Symfony\Component\Ai\Provider\ProviderInterface::class),
new \Symfony\Component\Ai\Failover\ProviderRegistry(
$app['config']['ai.providers']
)
);
});
}
Configuration:
Define providers and failover strategy in config/ai.php:
'ai' => [
'providers' => [
'openai' => [
'class' => \Symfony\Component\Ai\Provider\OpenAiProvider::class,
'api_key' => env('OPENAI_API_KEY'),
'priority' => 1,
],
'anthropic' => [
'class' => \Symfony\Component\Ai\Provider\AnthropicProvider::class,
'api_key' => env('ANTHROPIC_API_KEY'),
'priority' => 2,
],
'local' => [
'class' => \App\Providers\LocalAiProvider::class, // Custom fallback
'priority' => 3,
],
],
'failover' => [
'strategy' => 'priority', // or 'round-robin'
'max_attempts' => 3,
'timeout' => 5, // seconds
],
],
Usage: Replace direct API calls with the failover client:
$response = app(\Symfony\Component\Ai\Failover\FailoverClient::class)
->complete('User:', 'Generate a summary...');
Adapters (if needed):
Http facade as a Symfony HttpClient adapter:
class LaravelHttpClient implements \Symfony\Contracts\HttpClient\HttpClientInterface {
use \Illuminate\Support\Facades\Http;
public function request(string $method, string $url, array $options = []): \Symfony\Contracts\HttpClient\ResponseInterface {
$response = Http::withOptions($options)->{$method}($url);
return new SymfonyHttpClientResponse($response);
}
}
EventDispatcher to Laravel’s Illuminate\Events.symfony/ai (if not already used).How can I help you explore Laravel packages today?