Laravel AI SDK
Unified, expressive API for interacting with AI providers from Laravel
Repository Health
Technical Analysis
The Laravel AI SDK (laravel/ai) is the official AI package for Laravel, providing a unified, expressive API for interacting with providers such as OpenAI, Anthropic, Gemini, Mistral, Cohere, AWS Bedrock, Groq, Ollama, and more. It lets you build intelligent agents with tools and structured output, generate images, synthesize and transcribe audio, create vector embeddings, and rerank documents through a single, consistent, Laravel-friendly interface.
Built around a manager and facade with a provider abstraction, the SDK swaps model backends without changing application code. It integrates deeply with the framework’s container, queue, console, and filesystem components, and supports streaming responses, tool calling, approvals, and structured schemas out of the box.
What You Get
- A unified
Aifacade and manager that routes calls to any supported provider - First-class agents with tool calling, approvals, middleware, and structured output
- Providers for OpenAI, Anthropic, Gemini, Mistral, Cohere, Bedrock, Groq, Ollama, and more
- Embeddings, reranking, image generation, and audio transcription/synthesis APIs
- Streaming responses plus queueable agent prompts backed by Laravel’s queue system
Common Use Cases
- Adding chat, summarization, or extraction features that can switch AI providers freely
- Building autonomous agents that call application tools and return structured data
- Generating embeddings for semantic search or images and audio for content workflows
Under The Hood
Architecture - The SDK is organized around an AiManager resolved through the Ai facade (src/Ai.php) and registered by AiServiceProvider. A Provider abstraction under src/Providers implements a dedicated class per backend (AnthropicProvider, OpenAiProvider, GeminiProvider, BedrockProvider, and roughly a dozen more), while a Gateway layer normalizes requests and responses. Higher-level concerns live in focused namespaces: Agents, Tools, Messages, Streaming, Embeddings, Schema/ObjectSchema for structured output, plus Jobs and QueuedAgentPrompt for queued execution.
Tech Stack - Pure PHP targeting PHP 8.3+, depending on Laravel 12/13 components (illuminate/console, container, contracts, database, filesystem, json-schema, support), the AWS SDK for Bedrock, laravel/prompts, and laravel/serializable-closure. It optionally integrates laravel/mcp for MCP client and server tools.
Code Quality - Testing uses Pest with Unit, Feature, and Integration suites plus fixtures and datasets, alongside PHPStan static analysis, Laravel Pint formatting, and Rector for automated refactoring. The provider-per-file structure and consistent contracts keep the large surface maintainable.
API Design - The public API is deliberately expressive and Laravel-idiomatic, exposing a single Ai facade whose fluent methods read naturally for text, agents, embeddings, images, and audio. Official documentation on laravel.com covers the full feature set, and provider swapping requires only configuration changes rather than code changes.
Used by 2 apps in this directory
Bagisto
Analytics · Ecommerce
Open-source Laravel eCommerce platform for building multi-vendor marketplaces, B2B stores, headless commerce, and AI-powered storefronts.
Firecrawl
AI Development · Developer Tools
Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.