PHPackages                             tawshiqulislam/laravel-llm-failover - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tawshiqulislam/laravel-llm-failover

ActiveLibrary[API Development](/categories/api)

tawshiqulislam/laravel-llm-failover
===================================

A provider-agnostic LLM gateway for Laravel with retries, graceful failover, chronological chat history, and pluggable AI drivers.

v1.0.0(1mo ago)23MITPHPPHP ^8.3

Since Jun 23Pushed 1mo agoCompare

[ Source](https://github.com/tawshiqulislam/laravel-llm-failover)[ Packagist](https://packagist.org/packages/tawshiqulislam/laravel-llm-failover)[ RSS](/packages/tawshiqulislam-laravel-llm-failover/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel LLM Failover Gateway
============================

[](#laravel-llm-failover-gateway)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b4e4ce4dafb75149151d9bea9674276548c7f9c707582cff3d19e24ee0a770c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74617773686971756c69736c616d2f6c61726176656c2d6c6c6d2d6661696c6f7665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tawshiqulislam/laravel-llm-failover)[![Total Downloads](https://camo.githubusercontent.com/69e6ccba5fffd8dcbef916f551e60f539eef92c731dc82b8b658ffdf42aa08f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74617773686971756c69736c616d2f6c61726176656c2d6c6c6d2d6661696c6f7665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tawshiqulislam/laravel-llm-failover)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

A resilient, provider-agnostic LLM gateway for Laravel applications.

Designed for production AI chat systems—including WhatsApp bots, Messenger bots, customer support assistants, and web chat applications—the package protects your application from upstream AI failures such as rate limits (`429`), service overloads (`503`), network timeouts, and provider-specific API quirks.

---

Features
========

[](#features)

- 🚀 **Driver-based architecture** – Easily switch between AI providers (`Gemini`, `OpenAI`, and future drivers) without changing your application code.
- 🛡️ **Built-in resilience** – Automatic retries, timeout handling, and graceful degradation.
- 🔄 **Gemini role collapsing** – Merges consecutive conversation roles to satisfy Gemini's strict message schema.
- ⚡ **Graceful fallbacks** – Handles rate limits, temporary outages, and empty AI responses without crashing your application.
- 🕒 **Chronological history builder** – Prevents conversation ordering issues caused by identical timestamps or UUID-based primary keys.
- 🔌 **Laravel native** – Dependency Injection, Service Container binding, configuration publishing, and zero boilerplate integration.

---

Requirements
============

[](#requirements)

- PHP 8.2+
- Laravel 11+

---

Installation
============

[](#installation)

Install the package via Composer:

```
composer require tawshiqulislam/laravel-llm-failover
```

---

Publish the Configuration
=========================

[](#publish-the-configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag="llm-failover-config"
```

This will create:

```
config/llm-failover.php

```

The published configuration allows your application to map drivers to your environment variables.

---

Environment Configuration
=========================

[](#environment-configuration)

Add the following variables to your project's `.env` file.

Required
--------

[](#required)

These values are required for the package to function.

```
LLM_DEFAULT_DRIVER=gemini

GEMINI_API_KEY=your_actual_gemini_api_key
```

---

Optional
--------

[](#optional)

These values already have sensible defaults but can be overridden.

```
# AI model
GEMINI_DEFAULT_MODEL=gemini-2.5-flash

# Gemini API endpoint
GEMINI_BASE_URL=https://generativelanguage.googleapis.com/v1beta/models

# Maximum output tokens
GEMINI_MAX_OUTPUT_TOKENS=1000

# Temperature (0.0 - 2.0)
GEMINI_TEMPERATURE=0.7
```

---

Default Configuration
=====================

[](#default-configuration)

The published configuration looks like this:

```
return [

    'default' => env('LLM_DEFAULT_DRIVER', 'gemini'),

    'drivers' => [

        'gemini' => [
            'api_key' => env('GEMINI_API_KEY'),
            'base_url' => env(
                'GEMINI_BASE_URL',
                'https://generativelanguage.googleapis.com/v1beta/models'
            ),
            'default_model' => env('GEMINI_DEFAULT_MODEL', 'gemini-2.5-flash'),
            'max_output_tokens' => env('GEMINI_MAX_OUTPUT_TOKENS', 1000),
            'temperature' => env('GEMINI_TEMPERATURE', 0.7),
        ],

        'openai' => [
            'api_key' => env('OPENAI_API_KEY'),
        ],

    ],

];
```

---

What's Next?
============

[](#whats-next)

After installation you can:

- Inject the `LlmDriverInterface`
- Send chat conversations to your preferred LLM provider
- Build chronological conversation histories using the included trait
- Easily swap providers through configuration

Documentation for usage examples will be added in future releases.

---

License
=======

[](#license)

The MIT License (MIT).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

45d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3780a49740c88188609aac7bc39101b18340290cc78a0be4c4cfe9a3b5753fb0?d=identicon)[tawshiqulislam](/maintainers/tawshiqulislam)

---

Top Contributors

[![tawshiqulislam](https://avatars.githubusercontent.com/u/88878782?v=4)](https://github.com/tawshiqulislam "tawshiqulislam (2 commits)")

---

Tags

laravel-packagellm

### Embed Badge

![Health badge](/badges/tawshiqulislam-laravel-llm-failover/health.svg)

```
[![Health](https://phpackages.com/badges/tawshiqulislam-laravel-llm-failover/health.svg)](https://phpackages.com/packages/tawshiqulislam-laravel-llm-failover)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M353](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

818336.8k3](/packages/defstudio-telegraph)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k1](/packages/mike-bronner-laravel-model-caching)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45844.8k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

58174.6k18](/packages/api-platform-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5222.6k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
