- How do I install and set up this package in a Laravel 10+ project?
- Run `composer require hosseinhezami/laravel-gemini`, publish the config with `php artisan vendor:publish --tag=gemini-config`, and add your API key to `.env` under `GEMINI_API_KEY`. No migrations or schema changes are required for basic use.
- Which Laravel versions and PHP versions are officially supported?
- This package explicitly supports Laravel 10+ and PHP 8.1+. It follows Laravel’s version requirements and has been tested against the latest stable releases. Always check the package’s changelog for updates.
- Can I use this package for multimodal AI tasks like image or video processing?
- Yes, the package includes dedicated builders for images (`Gemini::image()`), videos (`Gemini::video()`), and audio (`Gemini::audio()`). It also supports file uploads for document analysis, making it ideal for advanced multimodal workflows.
- How does caching work, and can I configure it for cost optimization?
- The package leverages Laravel’s cache drivers (Redis, file, etc.) to cache responses. You can configure TTLs globally in `config/gemini.php` or per request using the `->cache()` method. This reduces API calls and costs for repeated prompts.
- Is there built-in support for streaming responses (e.g., real-time chat apps)?
- Yes, the package supports streaming via `->stream()`. You can configure chunk size and timeout in `config/gemini.php` under `stream`. However, ensure your server handles SSE (Server-Sent Events) properly to avoid memory leaks or disconnections.
- How do I handle API errors like quota limits or invalid prompts?
- The package includes retry logic (configurable in `retry_policy`) and surfaces errors via exceptions. You can catch these exceptions and implement fallback mechanisms, such as queueing retries or notifying admins for quota issues.
- Can I dynamically switch API keys for multi-tenancy or per-request security?
- Yes, use `Gemini::setApiKey('new-key')` to override the default `.env` key dynamically. This is useful for multi-tenant apps or rotating keys. Always ensure keys are securely managed (e.g., AWS Secrets Manager or Laravel Vault).
- Are there plans to add usage tracking or cost controls for Gemini’s token-based pricing?
- Currently, the package does not include built-in usage tracking, but you can log token usage via `response->usage()` and integrate with tools like Laravel Horizon or third-party monitoring. Consider implementing middleware for per-user quotas if cost control is critical.
- How do I handle large file uploads (e.g., videos) without timing out or crashing?
- For large files, use Laravel queues to offload uploads via `Gemini::files()->upload()` in a job. Validate file sizes early and monitor server resources. The package supports async processing, but ensure your queue worker handles long-running tasks efficiently.
- What alternatives exist if I need more control over the Gemini API or different features?
- For direct API access, use Google’s official [Gemini client libraries](https://ai.google.dev/gemini/api). If you need additional Laravel integrations, consider packages like `spatie/laravel-ai` (for broader AI support) or `filament/ai` (for UI-driven AI features). This package focuses on simplicity and Laravel-native abstractions.