- 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.