Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Llm Sdk Laravel Package

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.

View on GitHub
Deep Wiki
Context7

A single, unified, framework-independent library for integration with many popular AI platforms and large language models

Frequently asked questions about Llm Sdk
How do I integrate this SDK into a Laravel project with minimal setup?
Run `composer require 1tomany/llm-sdk`, then configure API keys in `.env` (e.g., `OPENAI_API_KEY`). Bind the `ClientFactory` to Laravel’s service container in `config/app.php` or use facades for simpler Blade/controller access. The SDK’s DI design aligns natively with Laravel’s dependency injection.
Does this SDK support Laravel’s queue system for async LLM calls?
No, the SDK lacks built-in queue support. For async workflows, wrap LLM calls in Laravel queues (e.g., `dispatch(new GeneratePromptJob($prompt))`) or use middleware like `spatie/queue-scheduler` to throttle requests. Stream responses via WebSockets if needed.
Which Laravel versions are officially supported?
The SDK is framework-agnostic but targets PHP 8.1+. For Laravel, ensure compatibility with your version (e.g., 10.x/11.x) by checking the [GitHub issues](https://github.com/1tomany/llm-sdk/issues) for version-specific notes. Test with your Laravel release’s PHP requirements.
Can I mock LLM responses for unit testing without hitting real APIs?
Yes, the SDK includes a `Mock` client. In tests, bind the `ClientFactory` to return the mock client (e.g., `app()->bind(MockClient::class)`) and use `MockClient::setResponse()` to simulate API calls. Works seamlessly with Laravel’s `Pest` or `PHPUnit`.
What happens if an LLM provider’s API changes (e.g., OpenAI updates their endpoint)?
The SDK may lag behind provider updates due to its abstraction layer. Monitor provider changelogs and fork the SDK if critical features break. For high-risk projects, consider direct API calls for provider-specific features or use middleware to log deprecation warnings.
How do I handle rate limits or API errors in Laravel?
The SDK throws custom exceptions (e.g., `RateLimitExceeded`). Wrap calls in a `try-catch` block and log errors via Laravel’s `Log::error()`. For retries, use `spatie/laravel-queue-retries` or implement exponential backoff in your service layer.
Are there performance differences compared to using provider SDKs directly (e.g., OpenAI’s PHP SDK)?
Yes, the abstraction layer adds minor latency. Benchmark against direct SDKs (e.g., `guzzlehttp/guzzle` + raw API calls) for your use case. For latency-sensitive apps, consider caching frequent prompts or using provider SDKs for critical paths.
Does this SDK support streaming responses (e.g., for chat apps)?
Streaming depends on the provider’s API. Check the [feature parity table](https://github.com/1tomany/llm-sdk) for supported providers. For Laravel, stream responses via `response()->stream()` or WebSockets (e.g., `beyondcode/laravel-websockets`).
How do I track LLM usage/costs in production?
Log token usage via Laravel events (e.g., `llm.tokens.used`) or middleware. Store metrics in a database table (e.g., `llm_calls`) with columns for `provider`, `prompt_length`, and `response_tokens`. Use `spatie/laravel-monitoring` for dashboards.
What if I need a feature not supported by this SDK (e.g., Anthropic’s batch cancellation)?
Fallback to the provider’s direct API or extend the SDK. Override the `ClientFactory` to inject custom logic (e.g., `app()->extend(AnthropicClient::class, fn() => new CustomAnthropicClient())`). Check the [GitHub issues](https://github.com/1tomany/llm-sdk/issues) for community workarounds.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity