laravel/ai
Laravel AI SDK for a unified, Laravel-friendly API across providers like OpenAI, Anthropic, and Gemini. Build agents with tools and structured output, generate images, synthesize/transcribe audio, create embeddings, and more—all through one consistent interface.
generate(), embed(), converse()) while allowing provider-specific optimizations (e.g., failover, model aliases).QueuedAgentPrompt and AgentStreamed classes enable asynchronous, stateful interactions, critical for latency-sensitive or long-running processes.OpenAiGateway, BedrockGateway) allows granular provider swapping without refactoring core logic. This is ideal for multi-cloud/AI-provider strategies (e.g., cost optimization via failover).Conversation and ConversationMessage models enable persistent AI state, useful for auditability or user-specific contexts.composer require laravel/ai, config publishing). The service provider auto-registers gateways, making it drop-in ready for new projects or incremental adoption.Embeddings::for()).Image::of(), Audio::speak()).InsufficientCreditsException) reduce runtime surprises.providerOptions(['temperature' => 0.7])).failover([OpenAiGateway::class, AnthropicGateway::class])).conversation_table config).
Risk: Poorly configured state management could lead to race conditions or data loss (mitigated by Laravel’s queue/retry mechanisms).conversations table?Fake gateways, but complex agent workflows may need custom test doubles.QueuedAgentPrompt.AgentStarted, AgentFinished, AgentFailed for observability.Conversation/ConversationMessage models (supports MySQL, PostgreSQL, SQLite).HttpClient, Serializer).| Phase | Effort | Key Actions | Dependencies |
|---|---|---|---|
| Evaluation | Low | - Install laravel/ai in a sandbox. |
None |
- Test basic APIs (e.g., Chat::create()->generate()). |
|||
| - Benchmark latency/cost vs. direct provider APIs. | |||
| Pilot Integration | Medium | - Integrate one provider (e.g., OpenAI) for a non-critical feature. | Laravel app, API keys |
| - Implement error handling (e.g., retry logic for rate limits). | |||
| - Add usage logging (e.g., token counts, timestamps). | |||
| Core Adoption | High | - Replace direct provider calls with SDK abstractions. | All AI-dependent features |
| - Migrate conversations to database-backed storage. | Database | ||
| - Implement agent workflows (tools, memory, structured output). | Custom tools | ||
| Optimization | Ongoing | - Configure failover between providers. | Multiple API keys |
| - Tune queue workers for async processing. | Laravel queues | ||
| - Add monitoring (e.g., Prometheus metrics for token usage). | Observability stack |
omitNullHeaders fix in v0.8.1).Gateway interfaces.curl to OpenAI) with SDK methods (e.g., Chat::create()->generate()).How can I help you explore Laravel packages today?