PHPackages                             soukicz/llm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. soukicz/llm

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

soukicz/llm
===========

LLM client with support for cache, tools and async requests

0.5.0(6mo ago)445.6k↓18.5%3[1 issues](https://github.com/soukicz/php-llm/issues)[2 PRs](https://github.com/soukicz/php-llm/pulls)BSD-3-ClausePHPPHP &gt;=8.3CI passing

Since Apr 23Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/soukicz/php-llm)[ Packagist](https://packagist.org/packages/soukicz/llm)[ RSS](/packages/soukicz-llm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (8)Versions (13)Used By (0)

PHP LLM - Agentic AI Framework for PHP
======================================

[](#php-llm---agentic-ai-framework-for-php)

Build powerful **AI agents** that can use tools, self-correct, and take autonomous actions. A unified PHP framework for Large Language Models with support for Anthropic Claude, OpenAI GPT, Google Gemini, and more.

> **What is Agentic AI?** Agents that can call functions, validate outputs, iterate on responses, and make decisions autonomously - not just generate text.

```
composer require soukicz/llm
```

---

📚 Full Documentation
--------------------

[](#-full-documentation)

**→ Complete guides, API reference, and examples: [soukicz.github.io/php-llm](https://soukicz.github.io/php-llm/)**

---

Why PHP LLM?
------------

[](#why-php-llm)

- 🤖 **Build AI Agents** - Create autonomous agents with tools, feedback loops, and state management
- 🔄 **Unified API** - One interface for Anthropic, OpenAI, Gemini, and more
- 🛠️ **Function Calling** - Empower agents to interact with external systems and APIs
- 📝 **Built-in Tools** - TextEditorTool for file manipulation, embeddings API, and more
- ✅ **Self-Correcting** - Validate and refine outputs with feedback loops
- 📸 **Multimodal** - Process images and PDFs alongside text (with caching support)
- 🧠 **Reasoning Models** - Advanced thinking with o3 and o4-mini reasoning models
- 📡 **Streaming** - Real-time response streaming with optional listener for live progress updates
- ⚡ **Async &amp; Caching** - Fast, cost-effective operations with prompt caching
- 💾 **State Persistence** - Save and resume conversations with thread IDs
- 📊 **Monitoring** - Built-in logging, cost tracking, and debugging interfaces

Key Concepts
------------

[](#key-concepts)

Before you start, understanding these core concepts will help you use the library effectively:

### Async by Default

[](#async-by-default)

All LLM clients in this library are **asynchronous by default** using Guzzle Promises. The `run()` method is a convenience wrapper that calls `runAsync()->wait()` internally. For production applications handling multiple requests, use the async methods directly for better performance.

### Two Types of Clients

[](#two-types-of-clients)

- **LLM Clients** (`AnthropicClient`, `OpenAIClient`, etc.) - Low-level API clients that send a single request and return a single response. Use these when you need direct control over individual API calls.
- **Agent Client** (`LLMAgentClient`) - High-level orchestrator that handles multi-turn conversations, automatic tool calling, feedback loops, and retries. Use this for building agents that need to iterate or use tools.

### Model Versions

[](#model-versions)

Anthropic and OpenAI models require explicit version constants:

```
