PHPackages                             amrachraf6699/laravel-gemini-ai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. amrachraf6699/laravel-gemini-ai

ActiveLibrary[API Development](/categories/api)

amrachraf6699/laravel-gemini-ai
===============================

A Laravel package for integrating with Google's Gemini AI API

v1.1.0(6d ago)3115MITPHPPHP ^8.0

Since Mar 15Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/amrachraf6699/laravel-gemini-ai)[ Packagist](https://packagist.org/packages/amrachraf6699/laravel-gemini-ai)[ RSS](/packages/amrachraf6699-laravel-gemini-ai/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

Laravel Gemini AI
=================

[](#laravel-gemini-ai)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1b227f7180c47694a77111610210411d5b67f0e680476af2834bb5f1834be2b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d72616368726166363639392f6c61726176656c2d67656d696e692d61692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amrachraf6699/laravel-gemini-ai)[![Total Downloads](https://camo.githubusercontent.com/f16e207dc5dc6ecf16d65394ed4c4ca6da8145615dc1f887f9de4c7577ab4540/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d72616368726166363639392f6c61726176656c2d67656d696e692d61692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amrachraf6699/laravel-gemini-ai)

A Laravel package for easy integration with Google's Gemini API. It supports the Gemini Interactions API, text generation, structured JSON output, multi-turn chat, image generation and editing, image analysis, embeddings, token counting, and common Gemini tools.

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Laravel 8.0 through 12.x
- Google Gemini API key from [Google AI Studio](https://ai.google.dev/)

Installation
------------

[](#installation)

```
composer require amrachraf6699/laravel-gemini-ai
```

Publish the configuration file:

```
php artisan vendor:publish --tag=gemini-config
```

Add your API key to `.env`:

```
GEMINI_API_KEY=your-api-key-here
```

Optional model overrides:

```
GEMINI_TEXT_MODEL=gemini-3.5-flash
GEMINI_IMAGE_MODEL=gemini-3.1-flash-image
GEMINI_VISION_MODEL=gemini-3.5-flash
GEMINI_EMBEDDING_MODEL=gemini-embedding-2
```

Usage
-----

[](#usage)

### Interactions API

[](#interactions-api)

Use `interact()` for new Gemini features. It returns parsed helpers and the raw API response.

```
use Amrachraf6699\LaravelGeminiAi\Facades\GeminiAi;

$response = GeminiAi::interact('Write a welcome email for a SaaS trial user.', [
    'system_instruction' => 'You write concise, friendly product emails.',
    'generation_config' => [
        'temperature' => 0.6,
    ],
]);

echo $response['text'];

// Available helpers:
// $response['interaction_id']
// $response['text']
// $response['image']
// $response['images']
// $response['steps']
// $response['usage']
// $response['raw']
```

### Text Generation

[](#text-generation)

Existing text generation still works:

```
$response = GeminiAi::generateText('Tell me about black holes.');

$raw = GeminiAi::generateText('Write a short story about space exploration.', [
    'model' => 'gemini-3.5-flash',
    'raw' => true,
    'generationConfig' => [
        'temperature' => 0.7,
        'maxOutputTokens' => 1000,
    ],
]);
```

### Structured JSON

[](#structured-json)

```
$response = GeminiAi::generateJson(
    'Extract the customer name and requested plan from this sentence: Sarah wants Pro.',
    [
        'type' => 'object',
        'properties' => [
            'customer_name' => ['type' => 'string'],
            'plan' => ['type' => 'string'],
        ],
        'required' => ['customer_name', 'plan'],
    ]
);

$data = $response['json'];
```

If the model returns invalid JSON, `json` is `null`, `json_error` contains the decode error, and `text` contains the raw model output.

### Multi-turn Chat

[](#multi-turn-chat)

```
$first = GeminiAi::chat('My app is a Laravel CRM. Suggest a homepage headline.');

$second = GeminiAi::chat(
    'Make it shorter.',
    $first['interaction_id']
);

echo $second['text'];
```

### Tools

[](#tools)

```
$response = GeminiAi::interact('What changed in Laravel recently?', [
    'tools' => [
        GeminiAi::googleSearchTool(),
    ],
]);

$response = GeminiAi::interact('Summarize https://laravel.com/docs', [
    'tools' => [
        GeminiAi::urlContextTool(),
    ],
]);

$response = GeminiAi::interact('Calculate compound growth for 12% over 5 years.', [
    'tools' => [
        GeminiAi::codeExecutionTool(),
    ],
]);
```

### Image Generation and Editing

[](#image-generation-and-editing)

```
$response = GeminiAi::generateImage('A clean product mockup of a Laravel dashboard.', [
    'aspect_ratio' => '16:9',
    'image_size' => '2K',
]);

echo '';
```

Use reference images for edits or style transfer:

```
$response = GeminiAi::generateImage('Replace the background with a bright office.', [
    'image' => public_path('uploads/product-photo.png'),
    'mime_type' => 'image/png',
]);
```

### Image Analysis

[](#image-analysis)

```
$imageFile = $request->file('image');
$response = GeminiAi::processImageText('Describe this image in detail.', $imageFile);

$response = GeminiAi::processImageText('What is in this picture?', public_path('images/example.jpg'));

$imageContent = file_get_contents('path/to/image.jpg');
$response = GeminiAi::processImageText('Analyze this image.', $imageContent, [
    'mime_type' => 'image/jpeg',
]);
```

### Embeddings

[](#embeddings)

```
$vector = GeminiAi::embed('Laravel makes building web applications productive.');
```

Use `raw` to inspect the full embedding response:

```
$response = GeminiAi::embed('Semantic search input.', [
    'raw' => true,
]);
```

### Token Counting

[](#token-counting)

```
$tokens = GeminiAi::countTokens('Estimate this prompt before sending it.');

echo $tokens['totalTokens'] ?? 0;
```

Error Handling
--------------

[](#error-handling)

The package throws exceptions when errors occur:

```
try {
    $response = GeminiAi::generateText('Tell me a joke.');
} catch (\Exception $e) {
    Log::error('Gemini API Error: '.$e->getMessage());
}
```

Available Options
-----------------

[](#available-options)

Most methods support an `options` array.

OptionDescription`model`Custom model to use`raw`Return the full API response for methods that support raw output`generationConfig` / `generation_config`Generation settings such as temperature and token limits`system_instruction`System instruction for Interactions`response_format`Text, JSON Schema, or image response format`tools`Tool declarations such as Google Search, URL Context, and Code Execution`previous_interaction_id`Continue a server-side Interactions conversation`store`Store an interaction for later continuation`background`Request background execution when supported by the API`mime_type`Input image MIME type fallback`aspect_ratio`Image output aspect ratio`image_size`Image output sizeContributing
------------

[](#contributing)

Contributions are welcome. Please feel free to submit pull requests or open issues on GitHub.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance84

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~235 days

Total

3

Last Release

6d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/168471094?v=4)[Amr Achraf](/maintainers/amrachraf6699)[@amrachraf6699](https://github.com/amrachraf6699)

---

Top Contributors

[![amrachraf6699](https://avatars.githubusercontent.com/u/168471094?v=4)](https://github.com/amrachraf6699 "amrachraf6699 (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amrachraf6699-laravel-gemini-ai/health.svg)

```
[![Health](https://phpackages.com/badges/amrachraf6699-laravel-gemini-ai/health.svg)](https://phpackages.com/packages/amrachraf6699-laravel-gemini-ai)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1348.7k1](/packages/jasara-php-amzn-selling-partner-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
