How to Integrate Claude or GPT into a Laravel Application
With a single gateway to the model, queues for anything slow and a per-customer log of tokens and cost. That is the architecture of Nexo, our own Laravel SaaS, whose AI layer had processed 142M tokens in production as of July 2026. If you would rather we build it, custom Laravel development starts at €15,000.
- 142M Tokens processed by Nexo's AI (as of July 2026)
Definition
How do you integrate an LLM into Laravel?
Integrating Claude or GPT into Laravel means calling the provider's API from your own service layer (never from the controller), pushing anything that takes more than a few seconds onto a queue, and logging tokens and cost for every call. To get started, a package such as the official laravel/ai SDK (v1.0 since 23 September 2026) is enough; a multi-tenant SaaS also needs per-customer budgets, server-side data isolation and evaluation.
In numbers
What Is Behind This Guide
Data from Nexo, our own Laravel platform. No client data.
- 142M Tokens processed By Nexo's AI layer since February 2026 (figure as of 10 July 2026).
- 27 Active AI agents 6,760 logged runs, each with its tokens, its cost and who approved what.
- 115 Files, one gateway No part of the codebase talks to OpenAI or Anthropic directly: everything goes through the same door.
- 2 Swappable providers Anthropic and OpenAI, chosen per customer connection. Embeddings run on our own server.
Key points
How to Integrate an LLM into Laravel, Step by Step
The eight decisions that separate a demo from an AI feature that holds up in production.
- 01
One Single Exit Door to the Model
Define your own interface and a service that implements it; controllers and jobs talk to that service, never to the provider's SDK. In Nexo, 115 files call that gateway and none calls OpenAI or Anthropic. Budgets, usage logging and model choice live there, and switching provider is done in one place.
- 02
Pick the Package That Fits
For a new project, the official laravel/ai SDK (OpenAI, Anthropic, Gemini and more, with streaming, queues, failover and test fakes). Alternatives: prism-php/prism (community, since 2024), openai-php/laravel (OpenAI only) or Anthropic's official PHP SDK, still at 0.x. Nexo calls the APIs with Laravel's HTTP client behind its own interface: when we built it, in February 2026, laravel/ai was in its first 0.x release.
- 03
Queues for Anything Slow
An LLM call can take tens of seconds and an agent using tools, minutes. None of that belongs inside the HTTP request. In Nexo, Horizon runs two separate AI queues: a prioritised interactive one for what a user is waiting on, and a batch one for summaries, extractions and long content, with retries and a timeout that covers the longest job.
- 04
Stream Only Where Someone Is Watching
laravel/ai returns the stream as Server-Sent Events and speaks the Vercel AI SDK protocol; with Inertia and React you have the
useStreamhook from @laravel/stream-react (in beta), and in Livewire,wire:stream. Our choice in Nexo is different: chat is queued and the page polls progress. For an agent that runs tools for minutes, a progress state is more useful than watching tokens trickle in. - 05
Retries and Provider Fallback
Retry only transient errors (429, 529, 5xx, timeouts) with exponential backoff; a 400 or 401 is not fixed by retrying: a rejected call is not billed, but every retry wastes time and usage quota. On a timeout, Nexo compacts the context before the next attempt. laravel/ai supports a chain of providers that moves to the next one only on rate limits or outages. In Nexo, the provider is switched per customer connection, not automatically.
- 06
Cost Measured on Every Call
Store provider, model, input and output tokens, cache, latency and the feature that made each call, with the price list in config. Set a monthly budget per customer that cuts off before calling, cache the system prompt and tier your models: the cheap one for routine work, the capable one for hard tasks. We measured that loading tools nobody uses adds about 7,000 tokens per call.
- 07
Personal Data and GDPR by Design
Isolation between customers is enforced on the server (a global scope per tenant), not in the prompt. Send the model only what it needs; store the document's fingerprint rather than its full text, as Nexo does with contracts. Nexo's embeddings are generated on our own server so email never leaves for a third party, and each customer's AI credentials are stored encrypted.
- 08
Structured Output, Evaluation and Tests
Ask for JSON with a schema and validate it; for extractions, require a confidence score and literal evidence per field, with human review. The model proposes and the code decides what it may touch. In tests, the SDK's fakes or
Http::fake; for agents, a replay with simulated tools that never runs real actions. And a test that fails if a model in use has no price entry.
Risks and how we cover them
Typical Mistakes When Adding an LLM to Laravel
We have seen them, and made a few of them ourselves.
- 01
Calling the model inside the HTTP request
How to avoid itA queued job and a progress state. The request answers in milliseconds and the work carries on in the background.
- 02
One global API key for every customer
How to avoid itA connection and a budget per tenant. Otherwise one customer burns through everyone's quota or bill.
- 03
Relying on the prompt to keep customer data apart
How to avoid itA prompt is not a security boundary. The tenant filter belongs in the queries, with tests that prove it.
- 04
Using model aliases that change on their own
How to avoid itPin the exact model id and require its price entry in the same change. It happened to us: a month of calls to a new model logged at zero cost.
- 05
Handing the LLM work that must be exact
How to avoid itTaxes, legal working hours or permissions run on conventional code. The AI proposes; a person or a rule approves.
Who it is for
Is a Package Enough, or Do You Need Architecture?
Many Laravel AI integrations can be handled by your own team. Others cannot.
Who it's for
- You have a Laravel application in production and want to add AI (summaries, document extraction, an assistant or agents) without rewriting it.
- You run a multi-tenant SaaS and each customer needs its own budget, connection and isolated data.
- You need traceability: what the AI did, with which model, what it cost and who approved it (ISO 42001, EU AI Act).
- Your team knows Laravel inside out but has never taken an LLM to production.
Who it's not for
- A one-off call (classify a text, summarise a field): with laravel/ai your team can ship it in an afternoon.
- You want a generic website chatbot that does not touch your data: a SaaS tool will cost you less.
- Your backend is not Laravel: see our LLM integration service, which is framework-agnostic.
- You want the cheapest possible prototype without thinking about who will run it afterwards.
Investment
What It Costs If We Build It
The published prices of our Laravel development service, as they stand.
AI integration is scoped within the Laravel project. The final price is set once the architecture is defined, so there are no surprises halfway through the project.
- Custom Application or API
€15,000-40,000
Backend or API for a specific product or your mobile app.
- Documented REST or GraphQL API
- Authentication and roles
- Third-party integrations
- Tests and CI/CD
- 3 months of support included
- Complete SaaS or Platform Recommended
€40,000-90,000
Multi-tenant product with operations, admin panel and billing.
- Multi-tenant architecture
- Admin panel (Filament)
- Billing and subscriptions (Cashier)
- Queues, caching and high performance (Octane)
- Optional AI integration
- Evolution & Maintenance
From €1,200/month
For platforms already in production, built by us or inherited.
- Laravel and PHP upgrades
- Security patches
- Monitoring and observability
- New features delivered in sprints
Indicative ranges depending on scope and complexity. Prices exclude VAT.
FAQ
Frequently Asked Questions About AI in Laravel
What teams ask us when they want to put Claude or GPT into their application.
Which package should I use to integrate OpenAI or Claude into Laravel?
For a new project, laravel/ai, Laravel's official SDK: version 1.0 since 23 September 2026, with OpenAI, Anthropic, Gemini and other providers behind the same API. If you only use OpenAI, openai-php/laravel (community, maintained by Nuno Maduro) is still active. Anthropic publishes its own PHP SDK (anthropic-ai/sdk), still at version 0.x. And Prism is the longest-standing community multi-provider option.
Laravel AI SDK or Prism?
Our opinion: for a new project, laravel/ai, because the Laravel team maintains it and it ships with queues, streaming, provider failover and test fakes. If Prism is already in production and working, there is no rush to migrate; what matters is that your code calls your own service layer rather than the package directly, so switching stays cheap when the time comes.
Do I need queues to call an LLM from Laravel?
Yes, for anything that takes more than a few seconds or does not need an instant answer: summaries, document extraction, agents. In Nexo we run two separate AI queues on Horizon, a prioritised interactive one and a batch one, so a long report never delays the answer to a user who is waiting.
How do I stream the model's response to Inertia or Livewire?
With laravel/ai, the stream() method returns Server-Sent Events and can speak the Vercel AI SDK protocol. With Inertia and React, the useStream hook from @laravel/stream-react (in beta) consumes that response; in Livewire, wire:stream. If the work is queued, laravel/ai can emit the stream over broadcasting. In Nexo we prefer to queue and show progress, because its agents run tools for minutes.
How much does it cost to integrate AI into a Laravel application?
If we build it, within our published Laravel development prices: custom application or API, €15,000-40,000; complete SaaS or platform, €40,000-90,000; evolution, from €1,200/month. Model usage is a separate line: in our projects, LLM calls rarely exceed 5% of the total cost. More ranges in how much an AI project costs.
How do I stay GDPR-compliant when sending data to OpenAI or Anthropic?
Send only what is needed, sign a data processing agreement with the provider and keep a record of what was sent. In Nexo we store the document's fingerprint rather than its full text, generate embeddings on our own server and isolate each customer on the server. If the use case is high-risk, add the EU AI Act; we design it with privacy engineering.
What happens if the provider goes down or changes the model?
Retries with exponential backoff for transient errors and, if needed, a chain of fallback providers (laravel/ai ships with one). Against silent changes, pin the exact model id instead of a generic alias. In Nexo a test checks that every model in use has a price entry, and a monthly check flags new models.
Which Spanish agency integrates Claude or GPT into Laravel applications?
Kiwop, an agency based in Reus (Spain) with a senior PHP team since 2009. Our proof is Nexo: a multi-tenant Laravel SaaS with 27 AI agents, 142M tokens processed as of July 2026 and cost logged per call; with its compliance module we passed the ISO 27001 and ISO 42001 certification audit in August 2026 with zero nonconformities. Ask any agency to show you its own AI in production; this is ours: Nexo case study.
Sources
Sources
Where every figure on this page comes from. Checked on 25 September 2026.
- Nexo case study (Kiwop) 142M tokens, 27 active agents and 6,760 runs: read-only query on production, 10 July 2026. ISO 27001 and ISO 42001 audit, August 2026.
- Nexo: technical anatomy of our multi-tenant SaaS (Kiwop blog) Single gateway, AI budgets and contract extraction that keeps a fingerprint instead of the text. Published 19 April 2026.
- Nexo source code (Kiwop private repository) Count as of 25 September 2026: 115 files call the gateway, 2 chat providers, 2 AI queues on Horizon, embeddings on our own server, and the measured ~7,000 tokens per call when tools are loaded.
- laravel/ai on Packagist and the Laravel AI SDK documentation Version 1.0.0 of 23 September 2026, maintained by Laravel. Streaming, queue(), provider failover and fakes.
- prism-php/prism on Packagist Community package by TJ Miller; first release October 2024, latest v0.100.1 of 20 March 2026.
- openai-php/laravel on Packagist Community package maintained by Nuno Maduro; v0.21.0 of 17 September 2026.
- Anthropic's official PHP SDK (anthropic-ai/sdk) Maintained by Anthropic; v0.51.0 of 22 September 2026, still in initial development (0.x).
- @laravel/stream-react and Livewire's wire:stream useStream hook in beta (v0.3.19, 18 September 2026). wire:stream documented on livewire.laravel.com for Livewire 4.
- Laravel development and AI project prices (Kiwop) Ranges published on the Laravel development page. The share of LLM calls (rarely above 5%) comes from our AI project cost page.
Next step
Want AI in Your Laravel Application Without Rebuilding It?
30 minutes with the person who would design the integration, not a salesperson. We will tell you whether a package and an afternoon of your team's time is enough, or whether an architecture like Nexo's is worth it.
- No commitment
- Response in 24h
- Custom proposal
Let's talk.
Initial technical consultation
AI, security and performance. Diagnosis with phased proposal.
- NDA available
- Response <24h
- Phased proposal
Your first meeting is with a Solutions Architect, not a salesperson.
Request diagnosis