One fluent Laravel API for OpenAI Anthropic Gemini and more
O

One fluent Laravel API for OpenAI Anthropic Gemini and more

One fluent Laravel API for OpenAI Anthropic Gemini and more

API
1,020 stars
N/A forks
N/A contributors

README

Project documentation from GitHub

Laravel AI: One Fluent API for OpenAI, Anthropic, Gemini, and More

If you've ever built an app that uses more than one AI provider, you know the pain. Each one—OpenAI, Anthropic, Google's Gemini—has its own SDK, its own method signatures, and its own quirks. Switching between them or supporting multiple options often means writing a bunch of adapter code. It's a hassle that pulls you away from building your actual features.

The Laravel team just dropped a new first-party package that aims to solve this. It’s called Laravel AI, and it provides a single, clean, fluent Laravel API to interact with all the major AI models. Think of it like Laravel's database layer, but for LLMs. You write your prompts one way, and you can decide—or let your users decide—which engine runs under the hood.

What It Does

Laravel AI is a Composer package that unifies multiple AI providers behind a consistent interface. You install it, configure your API keys, and suddenly you can send prompts and handle responses without caring if you're talking to GPT-4, Claude 3, or Gemini Pro. The package handles the differences for you.

It’s built on top of the excellent openai-php/client by Nuno Maduro but extends it significantly with Laravel-specific conveniences, like easy service container integration, managed configuration, and a beautifully fluent query builder-style API.

Why It's Cool

The biggest win is developer ergonomics. Instead of memorizing different SDK patterns, you use one familiar style. Need to switch a feature from OpenAI to Anthropic because of context length? That's now a configuration change, not a code rewrite.

It also embraces the Laravel ecosystem perfectly. Configuration is published to your config folder. You can easily swap providers via environment variables. It uses Laravel's HTTP client under the hood, so you benefit from its debugging and testing utilities. The fluent API makes complex tasks—like defining system messages, tools (functions), or response formats—readable and intuitive.

For example, streaming a response from a model looks as clean as:

$stream = AI::connect('openai')->chat()->createStreamed([ 'model' => 'gpt-4', 'messages' => [['role' => 'user', 'content' => 'Tell me a story']],
]); foreach ($stream as $response) { echo $response->choices[0]->delta->content;
}

The potential use cases are wide open: multi-provider SaaS platforms, fallback systems for when one provider is down, or simply future-proofing your app so you can easily adopt the next best model.

How to Try It

Getting started is straightforward. Install the package via Composer:

composer require laravel/ai

Next, publish the configuration file:

php artisan vendor:publish --tag=ai-config

This will create a <

Did you like this issue?

Join our weekly newsletter

Related Projects

Love discovering amazing projects?

Help us continue bringing you the best open-source discoveries every week.

Back to Projects
Last updated: Feb 16, 2026