PHPackages                             arturas88/anyllm - 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. arturas88/anyllm

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

arturas88/anyllm
================

Production-ready PHP library for LLMs - OpenAI, Anthropic, Google, Mistral, xAI, OpenRouter, Ollama. One interface, all providers, zero vendor lock-in.

v1.5.0(4mo ago)07[1 PRs](https://github.com/arturas88/anyllm/pulls)MITPHPPHP ^8.2CI passing

Since Dec 1Pushed 2mo agoCompare

[ Source](https://github.com/arturas88/anyllm)[ Packagist](https://packagist.org/packages/arturas88/anyllm)[ Docs](https://github.com/arturas88/anyllm)[ RSS](/packages/arturas88-anyllm/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (10)Used By (0)

AnyLLM PHP - Universal LLM Library
==================================

[](#anyllm-php---universal-llm-library)

 *One interface, all providers. Zero vendor lock-in.*

 [Features](#features) • [Installation](#installation) • [Quick Start](#quick-start) • [Documentation](#documentation) • [Examples](#examples)

---

🎉 Production-Ready Enterprise-Grade LLM Library
-----------------------------------------------

[](#-production-ready-enterprise-grade-llm-library)

A comprehensive, battle-tested PHP 8.2+ library providing a unified interface for interacting with multiple LLM providers. Built for production with persistence, logging, rate limiting, caching, metrics, middleware, and more.

**Latest**: All Priority 2 features complete! Embeddings, Middleware, Advanced Streaming, Metrics &amp; Monitoring. ✅

✨ Features
----------

[](#-features)

### 🔥 Core Capabilities

[](#-core-capabilities)

- **7 LLM Providers** - OpenAI, Anthropic, Google, Mistral, xAI, OpenRouter, Ollama
- **Unified Interface** - Same code works across all providers
- **Streaming Support** - Real-time response streaming with pause/resume/cancel
- **Structured Output** - Type-safe JSON with automatic hydration
- **Tool/Function Calling** - Let LLMs use your PHP functions
- **Agents** - Autonomous multi-iteration problem solving with tool integration
- **Workflows** - Multi-step orchestration with variable interpolation and human-in-the-loop
- **Embeddings &amp; RAG** - Semantic search and retrieval-augmented generation
- **Multi-Modal** - Text, images, files, audio (provider-dependent)

### 🚀 Production-Ready Infrastructure

[](#-production-ready-infrastructure)

- **💾 Persistence** - Database, Redis, File storage for conversations
- **📊 Logging** - Database and File logging with analytics dashboard
- **🚦 Rate Limiting** - Memory, Redis, Database rate limiters (distributed)
- **⚡ Caching** - Redis, Memcached, Database, File, Array caches
- **🔄 Retry Logic** - Exponential backoff on failures
- **📈 Metrics** - Prometheus export, dashboards, real-time monitoring
- **🔧 Middleware** - Intercept and transform requests/responses

### 🎯 Developer Experience

[](#-developer-experience)

- **Token Counter** - Estimate costs before making calls
- **Config Validator** - Catch errors before API calls
- **Prompt Templates** - Reusable templates with variables
- **Agents &amp; Workflows** - Autonomous AI and multi-step pipelines
- **Testing Support** - Built-in fakes for unit tests
- **Comprehensive Docs** - Examples for every feature

📦 Installation
--------------

[](#-installation)

### Prerequisites

[](#prerequisites)

- PHP 8.2+
- Composer
- An API key from your preferred provider (get OpenAI key at )

### Step 1: Install Dependencies

[](#step-1-install-dependencies)

```
composer require arturas88/anyllm
composer require guzzlehttp/guzzle
```

### Step 2: Configure API Key

[](#step-2-configure-api-key)

**Get your API key**:

Then set it up:

```
# Option 1: Create .env file (recommended)
cp .env.example .env
# Edit .env and replace 'sk-your-openai-api-key-here' with your actual key
nano .env  # or use your preferred editor

# Option 2: Export directly (temporary, for current session only)
export OPENAI_API_KEY=sk-your-actual-key-here
```

**Important**: Make sure to use your actual API key, not the placeholder!

### Step 3: Test It Works

[](#step-3-test-it-works)

```
composer test
```

You should see:

```
✅ Tests: 3, Assertions: 5

```

### Run Your First Example

[](#run-your-first-example)

```
php examples/basic-usage.php
```

Expected output:

```
=== Example 1: Simple Text Generation ===
Response: PHP is a server-side scripting language...
Tokens used: 37

=== Example 2: Chat Conversation ===
Assistant: PHP 8.2 introduced several new features...

```

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Basic Chat

[](#1-basic-chat)

```
