Download the PHP package arturas88/anyllm without Composer
On this page you can find all versions of the php package arturas88/anyllm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arturas88/anyllm
More information about arturas88/anyllm
Files in arturas88/anyllm
Package anyllm
Short Description Production-ready PHP library for LLMs - OpenAI, Anthropic, Google, Mistral, xAI, OpenRouter, Ollama. One interface, all providers, zero vendor lock-in.
License MIT
Homepage https://github.com/arturas88/anyllm
Informations about the package anyllm
AnyLLM PHP - Universal LLM Library
One interface, all providers. Zero vendor lock-in.
Features • Installation • Quick Start • Documentation • Examples
🎉 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 & Monitoring. ✅
✨ Features
🔥 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 & RAG - Semantic search and retrieval-augmented generation
- Multi-Modal - Text, images, files, audio (provider-dependent)
🚀 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
- Token Counter - Estimate costs before making calls
- Config Validator - Catch errors before API calls
- Prompt Templates - Reusable templates with variables
- Agents & Workflows - Autonomous AI and multi-step pipelines
- Testing Support - Built-in fakes for unit tests
- Comprehensive Docs - Examples for every feature
📦 Installation
Prerequisites
- PHP 8.2+
- Composer
- An API key from your preferred provider (get OpenAI key at https://platform.openai.com/api-keys)
Step 1: Install Dependencies
Step 2: Configure API Key
Get your API key: https://platform.openai.com/api-keys
Then set it up:
Important: Make sure to use your actual API key, not the placeholder!
Step 3: Test It Works
You should see:
Run Your First Example
Expected output:
🚀 Quick Start
1. Basic Chat
2. Conversation with History
3. With Retry & Caching
4. Structured Output
5. Tool Calling
6. Agents & Workflows
Agents - Autonomous Problem Solving
Human-in-the-Loop Agents
Workflows - Multi-Step Orchestration
Workflows with Structured Output
Human-in-the-Loop Workflows
7. Production Features
Persistence
Logging
Rate Limiting
Caching
6. Embeddings & Semantic Search
Middleware Pipeline
Streaming with Controls
Metrics Dashboard
🎯 Supported Providers
| Provider | Chat | Streaming | Tools | Embeddings | Images | Audio | Vision | Local |
|---|---|---|---|---|---|---|---|---|
| OpenAI | ✅ | ✅ | ✅ | ✅ | ✅ DALL-E | ✅ Whisper | ✅ | ❌ |
| Anthropic | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ Claude | ❌ |
| ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ Gemini | ❌ | |
| Mistral | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ Pixtral | ❌ |
| xAI (Grok) | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
| OpenRouter | ✅ | ✅ | Varies | Varies | Varies | Varies | Varies | ❌ |
| Ollama | ✅ | ✅ | Varies | Varies | ❌ | ❌ | Varies | ✅ |
📚 Documentation
- Changelog - Version history
- Contributing - How to contribute
- Troubleshooting - Common issues & solutions 🔧
- Database Schema - Database structure reference
💡 Examples
Comprehensive examples for every feature:
🛠️ Quick Commands
🏗️ Architecture
⚡ Performance
With Caching (Redis)
- 200-600x faster than API calls
- 100% cost savings on cache hits
- Perfect for: Identical prompts, embeddings, common queries
With Conversation Summarization
- 60-80% token reduction after threshold
- Massive cost savings on long conversations
- Context preserved with intelligent summaries
With Rate Limiting
- Prevents runaway costs
- Protects against abuse
- Multi-tier subscription support
🔧 Configuration
Create config/any-llm.php:
🗄️ Database Setup
SQLite (Recommended for Local Development)
Perfect for local development - no server setup required:
MySQL/PostgreSQL (Production)
Supported Databases:
- ✅ SQLite - Perfect for local development (zero setup)
- ✅ MySQL - Production-ready, high performance
- ✅ PostgreSQL - Advanced features, JSON support
🎯 Best Practices
1. Always Use Retry Logic
2. Cache Expensive Calls
3. Monitor Usage
4. Set Rate Limits
5. Use Conversations for Chat
🧪 Testing
🔧 Common Issues & Troubleshooting
Issue 1: "OPENAI_API_KEY not set"
Solution: Make sure you created the .env file with your API key:
Issue 2: "cURL error 77: certificate file"
This happens with some local PHP environments (like Laravel Herd).
Solution: Set the certificate path or disable SSL verification (development only):
Issue 3: "Class not found"
Solution: Regenerate the autoloader:
Issue 4: Example returns empty response
Possible causes:
- Invalid API key
- Rate limit exceeded
- Model doesn't support the feature
- Network connectivity issue
Debug:
API Key Issues
Rate Limits
Token Issues
Debugging
Debug HTTP requests and responses to see exactly what's being sent to and received from LLM providers:
The debug output shows:
- REQUEST: Full request payload (method, endpoint, data)
- RESPONSE: Complete response from the API
- CHUNK: Streaming response chunks
Base64-encoded content (images, PDFs, etc.) is automatically truncated in logs for readability, but you can show full content with showFullBase64: true.
🚢 Production Checklist
- [ ] Configure API keys securely
- [ ] Set up database (run migrations)
- [ ] Configure Redis for caching & rate limiting
- [ ] Enable logging (database or file)
- [ ] Set appropriate rate limits
- [ ] Enable retry logic
- [ ] Configure conversation summarization
- [ ] Set up metrics monitoring
- [ ] Test in staging environment
- [ ] Review security (API key storage)
📊 Benchmarks
- API Response: 1-3 seconds (provider-dependent)
- Cache Hit: 5-10ms (200-600x faster!)
- Token Estimation: ~0.1ms per 1000 chars
- Database Query: 10-50ms
- Redis Cache: 1-5ms
🤝 Contributing
Contributions welcome! The library is designed for easy extension:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
📝 License
MIT License - see LICENSE file for details.
🙏 Credits
Built with ❤️ using PHP 8.2+, Guzzle, and modern PHP best practices.
Ready for production use!
Start building amazing LLM-powered applications today.
Get Started • View Examples • Changelog
All versions of anyllm with dependencies
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0|^2.0