1tomany/llm-sdk
Laravel-friendly PHP SDK for working with LLM providers. Provides a clean client API, request/response handling, and configurable drivers so you can send prompts, manage completions, and integrate AI features into your app with minimal boilerplate.
Strengths:
GenerateOutput before enabling search stores).HttpClient, Cache) for compatibility.Gaps:
AppServiceProvider.Http facade or Guzzle under the hood.AiRequestCompiled, AiResponseReceived).Cache facade to store compiled queries or responses.Embedding, GeneratedOutput) for persistence.Mock provider or PHPUnit’s createMock.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Provider Lock-in | Limited to 4 providers; future support unclear. | Fork the repo or build a custom adapter for unsupported providers. |
| Performance Overhead | Abstraction layer may add latency (~5–10ms per request). | Benchmark critical paths; use direct HTTP calls for latency-sensitive workflows. |
| Breaking Changes | Active development (last release: June 2026) but no major version history. | Pin to a stable minor version (e.g., ^0.8.0) and monitor changelogs. |
| Error Handling | Normalized exceptions but lacks Laravel-specific error formatting. | Extend BaseException or wrap SDK calls in try-catch blocks. |
| Cost Management | No built-in rate limiting or budget tracking. | Integrate with Laravel’s rate limiter or a custom middleware. |
| Multimodal Support | Limited file/image handling (e.g., no download/list APIs). | Use provider-specific SDKs for advanced use cases or extend the FileRequest class. |
Log facade or a dedicated table).new CustomClient()).Laravel Ecosystem:
AppServiceProvider:
$this->app->bind(ClientFactory::class, function ($app) {
return new ClientFactory([
'openai' => new OpenAIClient(config('services.openai.key')),
'gemini' => new GeminiClient(config('services.gemini.key')),
]);
});
config/services.php:
'llm-sdk' => [
'providers' => ['openai', 'gemini'],
'default' => env('LLM_PROVIDER', 'openai'),
],
event(new AiRequestCompiled($query, $provider));
GenerateOutputJob):
GenerateOutputJob::dispatch($query)->onQueue('ai');
Cache::remember("ai_query_{$hash}", now()->addHours(1), fn() => $client->processQuery($query));
Database:
GeneratedOutput):
class GeneratedOutput extends Model {
protected $casts = ['response' => 'array'];
}
Testing:
MockClient or use PHPUnit’s createMock:
$mockClient = $this->createMock(ClientInterface::class);
$mockClient->method('generateOutput')->willReturn(new GenerateOutputResponse(...));
Http tests to verify API endpoints calling the SDK.Phase 1: Proof of Concept (2–4 weeks)
composer require 1tomany/llm-sdk.MockClient).Phase 2: Core Integration (4–6 weeks)
ClientFactory in the service container.AiService):
class AiService {
public function __construct(private ClientFactory $factory) {}
public function generate(string $prompt, string $provider = null) {
$client = $this->factory->get($provider ?? config('llm-sdk.default'));
return $client->generateOutput(new GenerateOutputRequest($prompt));
}
}
AiRequestSent, AiResponseReceived).AiService with 2 providers and basic logging.Phase 3: Advanced Features (4–8 weeks)
How can I help you explore Laravel packages today?