Building AI Applications with PHP

A practical guide using PapiAI, Laravel, and Symfony.

PHP developers build ambitious applications with Laravel and Symfony every day — but the moment AI enters the picture, they're told to reach for Python. This book proves that's unnecessary.

Walk through the creation of two complete, production-grade AI applications from scratch: an intelligent customer support agent with Laravel and an AI content generation pipeline with Symfony. Both use PapiAI, an open-source PHP library with zero runtime dependencies, support for 10 LLM providers, and a proper agentic runtime.

Read the Book

What you'll learn

Agents & Tools

Build AI agents that reason autonomously, call PHP functions as tools, and execute multi-step workflows with PapiAI's agentic loop.

Streaming & Real-Time

Deliver token-by-token responses via Server-Sent Events. Build chat interfaces that feel instant, not sluggish.

RAG & Embeddings

Index your documents, embed queries, search by meaning. Give the AI access to your data without fine-tuning a model.

Structured Output

Constrain LLM responses to precise JSON schemas with PapiAI's Zod-inspired validation system. Get typed data back, not just prose.

Security & Cost Control

Defend against prompt injection, validate tool inputs, rate-limit usage, and set hard cost ceilings before a runaway conversation empties your wallet.

Architecture & Testing

Patterns for prompt management, agent routing, middleware pipelines, mock providers, and integration testing of non-deterministic systems.

Two complete projects

Project 1: Customer Support Agent (Laravel) — A real-time chat with streaming responses, conversation persistence in Eloquent, tool calling for order lookups and knowledge base search, and escalation to human agents.

Project 2: Content Generation Pipeline (Symfony) — A multi-step pipeline that generates structured articles via schemas, creates hero images with Google Imagen, and processes everything asynchronously with Symfony Messenger.