Download the PHP package octopus-llm/php without Composer
On this page you can find all versions of the php package octopus-llm/php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download octopus-llm/php
More information about octopus-llm/php
Files in octopus-llm/php
Package php
Short Description OpenAI-compatible AI gateway with multi-key rotation, circuit breaker, and zero-cost free tier management.
License MIT
Informations about the package php
Octopus LLM PHP Gateway
OpenAI-compatible AI gateway with multi-key rotation, circuit breaker, and zero-cost free tier management for production usage.
Overview
Octopus-LLM is a robust PHP gateway that acts as a wrapper around the openai-php/client library. It automatically handles API key rotation using least-recently-used (LRU) patterns across multiple AI providers (like Groq, Cerebras, and OpenRouter), falls back to secondary providers if primary keys fail, protects your application using a configurable circuit breaker, and exposes events for recovery monitoring – all without needing a complicated infrastructure database.
Zero-Cost Free Tier Strategy
Octopus-LLM is designed to maximize free tier API quotas across providers. With enough keys, you can run production AI workloads at zero cost:
| Provider | Free Limit | Keys needed for ~1k req/day |
|---|---|---|
| Groq | 14,400 req/day | 1 |
| Cerebras | ~14,400 req/day | 1 |
| OpenRouter | Varies by model | 1–3 |
Register multiple free accounts → add all keys to the pool → Octopus-LLM handles rotation automatically.
Installation
You can install this package easily via Composer:
Quick Start
Configuration
The OctopusLLM constructor requires an array configuration.
API Reference
chat(array $messages, array $options = []): ChatResponse
Sends a chat request using the gateway configurations. Supports standard array options for overriding defaults (stream, maxTokens, temperature, forceProvider).
getStatus(): StatusResponse
Returns a unified DTO of all available providers, detailing active keys, inactive keys, and total stats.
ping(string $providerId, int $keyIndex): bool
Checks if a specific inactive key logic has recovered by pinging the configured baseURL/models endpoint. Returns boolean success.
runRecovery(): RecoveryReport
A utility method to scan all inactive keys that passed the cooldown timeframe. Automatically checks if they are recovered and re-activates them if successful.
on(string $event, callable $callback): self
Attach event listeners such as when fallback happens or a key goes bad.
Streaming
You can enable native streaming via the options array, passing the onChunk callback:
Error Handling
Octopus-LLM uses explicit granular exceptions under OctopusLLM\Gateway\Exceptions\* namespace:
InputTooLongException: Sent payload exceeds configuredmaxInputTokens.GatewayExhaustedException: Out of all active operational keys and Fallbacks.RateLimitException: Handled natively by circuit breaker, but internally emitted.AuthenticationException: Handled natively when key goes rogue.CircuitOpenException: Prevented access due to open circuit limits.ProviderException: Base exception layer interface.
Events
You can hook into real-time health events using $llm->on(string $event, callable $callback):
key.deactivated:($providerId, $keyIndex, $reason)-> Used for tracking broken API keys.key.recovered:($providerId, $keyIndex)-> Fires when a key successfully leaves the penalized box.provider.exhausted:($providerId)-> Triggered when an entire provider array has failed.fallback:($failedProviderId, $nextProviderId)-> When attempting automatic fallback to next priority.
CI4 Integration
If you intend to use this package with CodeIgniter 4, follow these steps:
-
Register the Service: Add an
octopus()method toapp/Config/Services.php: -
Register the Recovery Command: CI4 does not auto-discover commands from vendor packages. Create a wrapper at
app/Commands/OctopusRecover.php: -
Schedule Recovery: Run via CI4 Tasks or crontab every minute:
- Usage:
Custom Storage
OctopusLLM exposes OctopusLLM\Gateway\Contracts\StorageInterface which requires two methods:
load(): array and save(array $state): void.
Implement your own persistent storage logic (e.g. Redis, MySQL) for horizontal web-scaling deployments.
Non-Goals
This version 1.x library explicitly does NOT aim to support:
- Audio/Vision multi-modal data processing.
- Persistent complex conversation thread management (Send full context history array manually).
- Custom non-chat completion endpoints (such as
embeddings/ormoderation/). - Gemini native API support (use Gemini via OpenRouter instead).