Weave 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

Client Laravel Package

google-gemini-php/client

Community-maintained PHP API client for Google's Gemini AI API. Send text, image, video, and audio prompts, hold multi-turn chats, stream responses, call functions, generate images and speech, and manage files and cached content.

View on GitHub
Deep Wiki
Context7

Gemini API is a supercharged PHP API client that allows you to interact with the Gemini API

Frequently asked questions about Client
How do I install and configure google-gemini-php/client in a Laravel 10 project?
Run `composer require google-gemini-php/client` to install. Configure your API key in `.env` under `GEMINI_API_KEY`. Register the service provider in `config/app.php` and bind the client to Laravel’s container for dependency injection. Use `GeminiClient::generate()` in your code with your desired model and prompt.
Can I use Laravel queues to handle long-running Gemini API calls asynchronously?
Yes. Dispatch a job (e.g., `GeminiJob`) that uses the client to generate content. Laravel’s queue system will process it in the background, avoiding timeouts. Use `GeminiJob::dispatch()` in your controller or command. For streaming responses, ensure your job handles chunked data appropriately.
What Laravel versions and PHP versions does this package support?
The package supports Laravel 9+ (PHP 8.1+) and Laravel 10 (PHP 8.2+). It’s fully compatible with Laravel’s latest features, including dependency injection and HTTP client abstractions. Check the package’s `composer.json` for exact PHP version requirements, which align with Laravel’s supported versions.
How can I test my Laravel app’s Gemini integration without hitting real API costs?
Use Laravel’s Mockery or Pest to mock the `GeminiClient` interface. Stub API responses in your tests with `GeminiClient::shouldReceive('generate')->andReturn($mockResponse)`. For HTTP contract testing, use tools like `vcr` or Pest’s HTTP testing to record and replay Gemini API calls deterministically.
Does this package support streaming responses from Gemini, and how do I handle them in Laravel?
Yes, the package supports streaming responses. Use the `stream()` method on the client to receive chunks incrementally. In Laravel, you can process each chunk in real-time (e.g., for chat apps) or buffer them for later use. For async processing, dispatch a job to handle the streamed data as it arrives.
How can I enforce API rate limits and avoid hitting Gemini’s usage quotas in production?
Implement Laravel’s retry helper with exponential backoff for failed requests. Use middleware like `GeminiRateLimitMiddleware` to throttle requests based on your quota. Log API usage in a database table (e.g., `gemini_calls`) and set up alerts via Laravel Nova or a custom notification system when approaching limits.
Can I integrate Gemini with Laravel Scout for semantic search or vector embeddings?
While the package primarily focuses on text and multimodal generation, you can use Gemini to generate embeddings for custom search logic. Store embeddings in a vector database (e.g., Pinecone, Weaviate) and query them separately. For Laravel Scout, you’d need to extend its engine to work with your custom embedding storage.
What are some alternatives to this package if I need more advanced AI features or better Laravel integration?
Consider `laravel-ai` for a higher-level Laravel wrapper around multiple AI providers, or `php-ai` for a broader set of AI tools. For Gemini-specific features, check community forks or custom wrappers that extend this package. If you need fine-tuned control, use Laravel’s HTTP client directly with Gemini’s API endpoints.
How do I handle authentication dynamically, such as using different API keys per user or fetching keys from AWS Secrets Manager?
Store API keys in Laravel’s `.env` or a secrets manager like AWS Secrets Manager. Use Laravel’s `config()` helper or the `env()` function to fetch keys dynamically. For per-user keys, extend the `GeminiClient` to accept a key parameter or use Laravel’s `Auth` facade to resolve keys based on the authenticated user.
Are there any security concerns I should address when using Gemini in Laravel, such as prompt injection or data leakage?
Sanitize user inputs before passing them to Gemini using Laravel’s `Str::of()` or `Validator`. Avoid logging raw prompts or responses if they contain sensitive data. For regulated environments (e.g., HIPAA), implement audit logging via Laravel’s `Log` facade or a dedicated table to track all Gemini interactions. Use Laravel’s encryption for sensitive prompts.
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.
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource