# Laravel AI Integration: Is There a LangChain for PHP, and What Should You Use?

> LangChain is Python and JavaScript. Laravel teams have their own options: a provider client, a multi-provider layer, or a LangChain-style framework for RAG and agents. Which one fits which job.

*2026-10-12T12:32:39Z*

A question I get from Laravel teams: "We want to add AI. Is there a LangChain for Laravel, or do we need a Python service?"

**The short answer:** you don't need Python. LangChain itself is Python and JavaScript, but PHP has three kinds of tools that cover the same ground: a **provider client** (such as `openai-php/laravel`) when you call one model, a **multi-provider layer** (such as Prism) when you want to switch between OpenAI, Anthropic, Gemini or a local model, and **LangChain-style frameworks** (such as LLPhant or Neuron AI) when you need RAG pipelines or agents. Start with the smallest one that does the job, and keep it behind your own service class.

## Do you need LangChain at all?

LangChain bundles many things: model clients, prompt templates, document loaders, text splitters, vector stores, retrievers, tools and agents. Most Laravel features need one or two of these.

| You're building | What you actually need |
|---|---|
| Summaries, classification, extraction | One model call with structured output |
| A chat feature | A model client, conversation storage, streaming |
| Search over your own documents (RAG) | Embeddings, a vector store, retrieval, a model call |
| An agent that takes actions | Tool calling, a loop with a budget, authorization on every tool |

The first two don't need a framework. The last two are where a LangChain-style library saves time.

## The three kinds of tools

### 1. A provider client

`openai-php/laravel` wraps the OpenAI API with a Laravel facade and config. Anthropic and other providers have PHP clients too. Use one when a feature talks to one provider and you're happy to stay there.

### 2. A multi-provider layer

**Prism** gives you one fluent API over several providers, including OpenAI, Anthropic, Gemini and Ollama, with text, structured output, tool calling and embeddings. Use it when you want to route different tasks to different models, or keep the option to switch providers without touching business code.

### 3. A LangChain-style framework

**LLPhant** is a PHP framework inspired by LangChain, with document readers, splitters, embeddings, vector store adapters and question-answering chains. **Neuron AI** focuses on agents: tools, memory and RAG in PHP. Use one of these when you're building RAG or agents and don't want to write the plumbing yourself.

## The part no library does for you

Whichever you pick, the hard parts of production AI are architecture, not the SDK:

- **One boundary.** Call AI through your own use-case services, such as `SummariseTicket` or `ClassifyLead`, not from controllers. Then a library change touches one layer.
- **Queues.** Most AI work, like embeddings, enrichment and batch summaries, belongs in Laravel queue jobs, not the request.
- **Structured output.** Ask for JSON, validate it into a DTO, and reject anything that doesn't fit.
- **Authorization.** If an agent can call a tool, the tool runs your normal policies. The model proposes; your app decides.
- **Budgets.** Cap retries, tool steps and tokens per workflow, and log cost per tenant.

I wrote about the cost side in detail in [Adding AI to a Laravel or Go product without runaway costs](/en/blog/add-ai-laravel-go-without-runaway-costs).

## Where RAG data should live

If you already run PostgreSQL, `pgvector` is often enough for a Laravel RAG feature: embeddings sit next to the records they describe, and permissions stay in one database. A dedicated vector database makes sense at larger scale. I covered a private setup in [Building a private RAG stack on PostgreSQL](/en/blog/private-rag-postgres-pgvector-bm25-tei).

## When a separate Python service does make sense

- You need a Python-only library, such as a specific model runtime or evaluation tool.
- A data or ML team already owns Python services.
- You run local models on GPUs, and that box has its own scaling needs.

Even then, keep the Laravel side the same: a use-case service that calls an internal API instead of a provider.

## Honest limits

- **PHP's AI ecosystem is smaller than Python's.** New techniques usually land in Python first.
- **These libraries move fast.** Pin versions and read the changelog before upgrading.
- **A framework won't fix a vague use case.** If you can't say what a good answer looks like, no library will make the feature reliable.

## FAQ

### Is there a LangChain for Laravel?
Not LangChain itself, which is Python and JavaScript. PHP has LangChain-style frameworks such as LLPhant and Neuron AI for RAG and agents, and Prism for a single API over several model providers.

### Do I need Python to add AI to a Laravel app?
No. Model APIs are HTTP, and PHP libraries cover model calls, structured output, tool calling, embeddings and RAG. A Python service only makes sense for Python-only tools or GPU workloads.

### What's the best way to integrate OpenAI into Laravel?
Use a client such as `openai-php/laravel` or a multi-provider layer such as Prism, call it from your own service classes, run heavy work in queues, and validate structured output before using it.

### Can Laravel do RAG?
Yes. Store embeddings in PostgreSQL with pgvector or in a vector database, retrieve the relevant chunks for a question, and pass them to the model. LLPhant and Neuron AI include RAG building blocks.

## Next steps

Adding AI to a Laravel product and want it to stay maintainable as usage grows? See [AI integration](/en/ai/integration) or [get in touch](/en/contact).

---

Source: https://fadymondy.com/en/blog/laravel-ai-integration-langchain-php
