PHPackages                             php-gemini/generative-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. php-gemini/generative-ai

ActiveLibrary

php-gemini/generative-ai
========================

Laravel-friendly PHP Package for Google Gemini Generative AI (including image &amp; text)

v1.1.0(10mo ago)0364↓100%MITPHPPHP &gt;=8.0CI passing

Since Jun 29Pushed 10mo agoCompare

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

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

🧠 Gemini PHP SDK for Google Generative AI
=========================================

[](#-gemini-php-sdk-for-google-generative-ai)

[![Packagist](https://camo.githubusercontent.com/1fb128958b833e6d88e06c9c0acbe75863ec3826dc83afc04672ff3ccd0e092c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d67656d696e692f67656e657261746976652d6169)](https://packagist.org/packages/php-gemini/generative-ai)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/aff0b1ebd8bae48ba12ef0b1128d6460084232cd88d6e102969df5f5eea3b35a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e302d626c75652e737667)](https://php.net)

A Laravel-friendly, lightweight PHP SDK to interact with [Google Gemini Generative AI](https://ai.google.dev/). Supports text generation, image input (vision), and is fully customizable for any PHP project.

---

✨ Features
----------

[](#-features)

- ✅ Gemini text generation (prompt → response)
- 🖼️ Image input support (base64 vision models)
- 🔐 Full OAuth2 authentication (refresh token supported)
- 🔧 Easy configuration via `.env` or constructor
- 🧪 PHPUnit + Testbench testing support
- 🎯 Laravel-ready (service provider + facade)
- 📦 Composer installable
- 📘 Full documentation included

---

🧪 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require php-gemini/generative-ai
```

### ⚙️ Configuration

[](#️-configuration)

For Laravel users, publish the configuration file:

```
php artisan vendor:publish --provider="PhpGemini\GenerativeAI\Providers\GeminiServiceProvider"
```

Then update your `.env` file with your API Key:

```
GEMINI_API_KEY=your_actual_api_key
GEMINI_MODEL=gemini-1.5-flash
```

> 🔐 **Using OAuth2?** See the section below on generating and using refresh tokens instead.

---

🔐 OAuth2 Support
----------------

[](#-oauth2-support)

This SDK supports Google OAuth2 access via a `refresh_token`, `client_id`, and `client_secret`.

### 🔧 Generate Refresh Token

[](#-generate-refresh-token)

To generate your credentials securely, use our standalone command-line script: **[Zero-Asif/oauth2\_refresh\_token\_generator](https://github.com/Zero-Asif/oauth2_refresh_token_generator)**

Follow the instructions in its `README` file. After running the script, add the output to your `.env` file:

```
GEMINI_OAUTH_CLIENT_ID=your_client_id
GEMINI_OAUTH_CLIENT_SECRET=your_client_secret
GEMINI_OAUTH_REFRESH_TOKEN=your_refresh_token
```

> ✅ The SDK will automatically use OAuth2 if an API key is not provided.

---

🚀 Usage
-------

[](#-usage)

### ✅ In Laravel

[](#-in-laravel)

```
use Gemini;

echo Gemini::generate("What's the future of AI?");
```

### ✅ In Plain PHP

[](#-in-plain-php)

Initialize with an **API Key**:

```
use PhpGemini\GenerativeAI\GeminiClient;

require 'vendor/autoload.php';

$gemini = new GeminiClient([
    'api_key' => 'your_api_key',
    'model' => 'gemini-1.5-flash',
]);

echo $gemini->generateContent("Tell me something interesting.");
```

Or initialize with **OAuth2**:

```
use PhpGemini\GenerativeAI\GeminiClient;
use PhpGemini\GenerativeAI\Services\OAuth2Service;

require 'vendor/autoload.php';

$oauth = new OAuth2Service([
    'client_id' => 'your_client_id',
    'client_secret' => 'your_client_secret',
    'refresh_token' => 'your_refresh_token',
]);

$gemini = new GeminiClient([
    'model' => 'gemini-1.5-flash',
    'oauth2' => $oauth
]);

echo $gemini->generateContent("Tell me something interesting.");
```

### 🖼️ Image Input (Vision Model)

[](#️-image-input-vision-model)

```
$response = $gemini->generateContentWithImage('path/to/image.jpg', 'What’s in this image?');
```

> ⚠️ **Note:** Only supported for models that accept image input, like `gemini-1.5-flash`.

---

🧪 Testing (PHPUnit)
-------------------

[](#-testing-phpunit)

To run the test suite:

```
composer test
```

To use Testbench for testing within a Laravel application, first install it:

```
composer require --dev orchestra/testbench
```

---

🛠️ Roadmap
----------

[](#️-roadmap)

- Text generation
- Laravel integration
- Image input (vision support)
- OAuth2 integration (refresh token support)
- Unit testing &amp; mocking (PHPUnit + Testbench)
- Streaming response support
- Online documentation site (mkdocs)

---

📘 Documentation
---------------

[](#-documentation)

Full documentation is available inside: `docs/index.md`

---

🤝 Contributing
--------------

[](#-contributing)

Pull requests, issues, and feature suggestions are welcome!

```
git clone [https://github.com/php-gemini/generative-ai.git](https://github.com/php-gemini/generative-ai.git)
cd generative-ai
composer install
```

---

📄 License
---------

[](#-license)

This project is open-sourced under the **MIT License**.

---

🔗 Useful Links
--------------

[](#-useful-links)

- **Packagist:** [php-gemini/generative-ai](https://packagist.org/packages/php-gemini/generative-ai)
- **Gemini API Docs:**
- **OAuth2 Refresh Token Tool:** [Zero-Asif/oauth2\_refresh\_token\_generator](https://github.com/Zero-Asif/oauth2_refresh_token_generator)
- **Google Cloud Console (OAuth Credentials):**
- **Project Homepage:**

---

🙋 Author
--------

[](#-author)

**Zero-Asif (Asifuzzaman Asif)**

- 📧 **Email:**
- 🔗 **GitHub:** [github.com/Zero-Asif](https://github.com/Zero-Asif)

✨ If this project helped you, please ⭐ the repo!

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance58

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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

Total

2

Last Release

305d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/310d8db92650f4e2148f441f07a46ad24f0c9241eed201c3d5154abd0689a937?d=identicon)[Zero-Asif](/maintainers/Zero-Asif)

---

Top Contributors

[![Zero-Asif](https://avatars.githubusercontent.com/u/171035883?v=4)](https://github.com/Zero-Asif "Zero-Asif (6 commits)")

---

Tags

phplaravelsdkgoogleaivisionGeminigenerative

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/php-gemini-generative-ai/health.svg)

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

###  Alternatives

[gemini-api-php/laravel

Gemini API client for Laravel

8915.7k](/packages/gemini-api-php-laravel)[gemini-api-php/client

API client for Google's Gemini API

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

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[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)
