PHPackages                             gemini-api-php/laravel - 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. gemini-api-php/laravel

ActiveLibrary[API Development](/categories/api)

gemini-api-php/laravel
======================

Gemini API client for Laravel

v0.3.0(2y ago)8915.7k↑16.7%13[8 issues](https://github.com/gemini-api-php/laravel/issues)[1 PRs](https://github.com/gemini-api-php/laravel/pulls)MITPHPPHP ^8.1

Since Dec 24Pushed 1y ago2 watchersCompare

[ Source](https://github.com/gemini-api-php/laravel)[ Packagist](https://packagist.org/packages/gemini-api-php/laravel)[ RSS](/packages/gemini-api-php-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (5)Used By (0)

 [![Gemini API Client for Laravel - Examples](https://raw.githubusercontent.com/gemini-api-php/laravel/main/assets/example.png)](https://raw.githubusercontent.com/gemini-api-php/laravel/main/assets/example.png)

 [![Total Downloads](https://camo.githubusercontent.com/d2809759f5d534724cafb566962e0a603c110810c148eab6555ea536830b9c49/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67656d696e692d6170692d7068702f6c61726176656c)](https://packagist.org/packages/gemini-api-php/laravel) [![Latest Version](https://camo.githubusercontent.com/11adb02f4c80804f5bf5be22b09497d521bf4fb5a0908934de0f09430ff9f776/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67656d696e692d6170692d7068702f6c61726176656c)](https://packagist.org/packages/gemini-api-php/laravel) [![License](https://camo.githubusercontent.com/f51098e4fb9e5d534df926cbd4839af611d0801535d232ee9a3f392c87c8b910/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f67656d696e692d6170692d7068702f6c61726176656c)](https://packagist.org/packages/gemini-api-php/laravel)

Gemini API Client for Laravel
=============================

[](#gemini-api-client-for-laravel)

Gemini API Client for Laravel allows you to use the Google's generative AI models, like Gemini Pro and Gemini Pro Vision in your Laravel application.

Supports PHP 8.1 and Laravel v9, v10.

*This library is not developed or endorsed by Google.*

- Erdem Köse - **[github.com/erdemkose](https://github.com/erdemkose)**

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [How to use](#how-to-use)
    - [Text Generation](#text-generation)
    - [Text Generation using Image File](#text-generation-using-image-file)
    - [Text Generation using Image Data](#text-generation-using-image-data)
    - [Chat Session (Multi-Turn Conversations)](#chat-session-multi-turn-conversations)
    - [Chat Session with History](#chat-session-with-history)
    - [Text Embeddings](#text-embeddings)
    - [Tokens counting](#tokens-counting)
    - [Listing models](#listing-models)
    - [Accessing the underlying Gemini API client](#accessing-the-underlying-gemini-api-client)
- [Credits](#credits)

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

[](#installation)

> You need an API key to gain access to Google's Gemini API. Visit [Google AI Studio](https://makersuite.google.com/) to get an API key.

First step is to install the Gemini API Client for Laravel with Composer.

```
composer require gemini-api-php/laravel
```

Configuration
-------------

[](#configuration)

There are two ways to configure the client.

### Environment variables

[](#environment-variables)

You can set the `GEMINI_API_KEY` environment variable with the API key you obtained from Google AI studio.

Add the following line into your `.env` file.

```
GEMINI_API_KEY='YOUR_GEMINI_API_KEY'
```

### Configuration file

[](#configuration-file)

You can also run the following command to create a configuration file in your applications config folder.

```
php artisan vendor:publish --provider=GeminiAPI\Laravel\ServiceProvider
```

Now you can edit the `config/gemini.php` file to configure the Gemini API client.

How to use
----------

[](#how-to-use)

### Text Generation

[](#text-generation)

```
use GeminiAPI\Laravel\Facades\Gemini;

print Gemini::generateText('PHP in less than 100 chars');
// PHP: A server-side scripting language used to create dynamic web applications.
// Easy to learn, widely used, and open-source.
```

### Text Generation Using Image File

[](#text-generation-using-image-file)

```
use GeminiAPI\Laravel\Facades\Gemini;

print Gemini::generateTextUsingImageFile(
    'image/jpeg',
    'elephpant.jpg',
    'Explain what is in the image',
);
// The image shows an elephant standing on the Earth.
// The elephant is made of metal and has a glowing symbol on its forehead.
// The Earth is surrounded by a network of glowing lines.
// The image is set against a starry background.
```

### Text Generation Using Image Data

[](#text-generation-using-image-data)

```
use GeminiAPI\Laravel\Facades\Gemini;

print Gemini::generateTextUsingImage(
    'image/jpeg',
    base64_encode(file_get_contents('elephpant.jpg')),
    'Explain what is in the image',
);
// The image shows an elephant standing on the Earth.
// The elephant is made of metal and has a glowing symbol on its forehead.
// The Earth is surrounded by a network of glowing lines.
// The image is set against a starry background.
```

### Chat Session (Multi-Turn Conversations)

[](#chat-session-multi-turn-conversations)

```
use GeminiAPI\Laravel\Facades\Gemini;

$chat = Gemini::startChat();

print $chat->sendMessage('Hello World in PHP');
// echo "Hello World!";
// This code will print "Hello World!" to the standard output.

print $chat->sendMessage('in Go');
// fmt.Println("Hello World!")
// This code will print "Hello World!" to the standard output.
```

### Chat Session with History

[](#chat-session-with-history)

```
use GeminiAPI\Laravel\Facades\Gemini;

$history = [
    [
        'message' => 'Hello World in PHP',
        'role' => 'user',
    ],
    [
        'message' =>  'model',
    ],
];
$chat = Gemini::startChat($history);

print $chat->sendMessage('in Go');
// fmt.Println("Hello World!")
// This code will print "Hello World!" to the standard output.
```

### Text Embeddings

[](#text-embeddings)

```
use GeminiAPI\Laravel\Facades\Gemini;

print_r(Gemini::embedText('PHP in less than 100 chars'));
// [
//    [0] => 0.041395925
//    [1] => -0.017692696
//    ...
// ]
```

### Tokens counting

[](#tokens-counting)

```
use GeminiAPI\Laravel\Facades\Gemini;

print Gemini::countTokens('PHP in less than 100 chars');
// 10
```

### Listing models

[](#listing-models)

```
use GeminiAPI\Laravel\Facades\Gemini;

print_r(Gemini::listModels());
//[
//  [0] => GeminiAPI\Resources\Model Object
//    (
//      [name] => models/gemini-pro
//      [displayName] => Gemini Pro
//      [description] => The best model for scaling across a wide range of tasks
//      ...
//    )
//  [1] => GeminiAPI\Resources\Model Object
//    (
//      [name] => models/gemini-pro-vision
//      [displayName] => Gemini Pro Vision
//      [description] => The best image understanding model to handle a broad range of applications
//      ...
//    )
//]
```

### Accessing the underlying Gemini API client

[](#accessing-the-underlying-gemini-api-client)

```
use GeminiAPI\Laravel\Facades\Gemini;

$client = Gemini::client();
```

Credits
-------

[](#credits)

This project was inspired by the great work of [OpenAI PHP for Laravel](https://github.com/openai-php/laravel) and [OpenAI PHP client](https://github.com/openai-php/client).

We gratefully acknowledge the contributions of [OpenAI PHP](https://github.com/openai-php) and its team.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity44

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 ~1 days

Total

3

Last Release

874d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6873cd99f242c9ab4180cf48309b8cd50c09b1d7086b755f49271ca2fd60cac3?d=identicon)[erdemkose](/maintainers/erdemkose)

---

Top Contributors

[![erdemkose](https://avatars.githubusercontent.com/u/4168527?v=4)](https://github.com/erdemkose "erdemkose (8 commits)")

---

Tags

geminigemini-apigoogle-geminigoogle-generative-ailaravellaravel-packagephpapiclientlaravelsdkgoogleaiGeminigemini-progemini pro vision

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gemini-api-php-laravel/health.svg)

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

###  Alternatives

[gemini-api-php/client

API client for Google's Gemini API

216221.4k5](/packages/gemini-api-php-client)[google-gemini-php/client

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

402986.7k21](/packages/google-gemini-php-client)[google-gemini-php/laravel

Google Gemini PHP for Laravel is a supercharged PHP API client that allows you to interact with the Google Gemini AI API

614397.1k4](/packages/google-gemini-php-laravel)[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[hosseinhezami/laravel-gemini

A production-ready Laravel package to integrate with the Google Gemini API. Supports text, image, video, audio, long-context, structured output, files, caching, function-calling and understanding capabilities.

14010.8k1](/packages/hosseinhezami-laravel-gemini)

PHPackages © 2026

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