Laravel AI SDK

Unified, expressive API for interacting with AI providers from Laravel

SDK
Composer
vv0.10.3
1,104stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
87/100Excellent
Development Activity100
Maintenance100
Community80
Maturity28
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
89/100Excellent
Architecture90
Code Quality88
Innovation90
Learning Curve75

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 Ai facade 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search