PHPackages                             freshphp/gemini - 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. freshphp/gemini

AbandonedLibrary[API Development](/categories/api)

freshphp/gemini
===============

a package is an encapsulation of the gemini rest api

v0.0.1(1y ago)09MITPHPPHP ^8.1

Since Jul 31Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (11)Versions (2)Used By (0)

php-gemini-client
=================

[](#php-gemini-client)

使用PHP封装了部分[gemini rest api](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal)

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

[](#table-of-contents)

- [Get Started](#get-started)
- [Usage](#usage)
    - [countTokens](#counttokens)
    - [streamGenerateContent](#streamgeneratecontent)

Get Started
-----------

[](#get-started)

> **Requires [PHP 8.1+](https://php.net/releases/)**

First, install Gemini via the [Composer](https://getcomposer.org/) package manager:

```
composer require freshphp/gemini
```

Then, interact with Gemini's API:

```
$path = '/gcs.json';
$projectId = 'test';
$location = 'us-central1';
$model = 'gemini-1.5-pro-001';
$client = Client::instance('yotta-ai', 'us-central1', $path, $model);
```

Usage
-----

[](#usage)

### countTokens

[](#counttokens)

```
$data = [['text' => 'test']];
$model = 'gemini-1.5-flash-001';
$res = $client->withModelId($model)->countTokens($data);

echo json_encode($res->toArray());
// result: {"totalTokens":1,"totalBillableCharacters":4}
```

### streamGenerateContent

[](#streamgeneratecontent)

```
$payload = [
    'systemInstruction' => [
        'parts' => [
            [
                'text' => '你是一名英文翻译官，请把用户发送的内容翻译成英文。',
            ],
        ],
    ],
    'contents' => [
        [
            'role' => 'USER',
            'parts' => [
                [
                    'text' => '你叫什么名字？',
                ],
            ],
        ],
    ],
    'generationConfig' => [
        'temperature' => 1,
        'responseMimeType' => 'text/plain',
    ],
    'safetySettings' => [
        [
            'category' => 'HARM_CATEGORY_HATE_SPEECH',
            'threshold' => 'BLOCK_ONLY_HIGH',
        ],
        [
            'category' => 'HARM_CATEGORY_DANGEROUS_CONTENT',
            'threshold' => 'BLOCK_ONLY_HIGH',
        ],
        [
            'category' => 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
            'threshold' => 'BLOCK_ONLY_HIGH',
        ],
        [
            'category' => 'HARM_CATEGORY_HARASSMENT',
            'threshold' => 'BLOCK_ONLY_HIGH',
        ],
    ],
];
$response = $client->streamGenerateContent($payload);
/** @var \Fresh\Gemini\Response\Chat\ResponseChunk $responseItem */
foreach ($response as $responseItem) {
    echo json_encode($responseItem->toArray()).PHP_EOL.PHP_EOL;
}

// result:
// {"candidates":[{"content":{"role":"model","parts":[{"text":"What"}]}}]}

// {"candidates":[{"content":{"role":"model","parts":[{"text":"'s your name? \n"}]},"safetyRatings":[{"category":"HARM_CATEGORY_HATE_SPEECH","probability":"NEGLIGIBLE","probabilityScore":0.09947021,"severity":"HARM_SEVERITY_NEGLIGIBLE","severityScore":0.10502681},{"category":"HARM_CATEGORY_DANGEROUS_CONTENT","probability":"NEGLIGIBLE","probabilityScore":0.1317307,"severity":"HARM_SEVERITY_NEGLIGIBLE","severityScore":0.09073549},{"category":"HARM_CATEGORY_HARASSMENT","probability":"NEGLIGIBLE","probabilityScore":0.2155158,"severity":"HARM_SEVERITY_NEGLIGIBLE","severityScore":0.07821887},{"category":"HARM_CATEGORY_SEXUALLY_EXPLICIT","probability":"NEGLIGIBLE","probabilityScore":0.07544843,"severity":"HARM_SEVERITY_NEGLIGIBLE","severityScore":0.06791668}]}]}

// {"candidates":[{"content":{"role":"model","parts":[{"text":""}]},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":21,"candidatesTokenCount":8,"totalTokenCount":29}}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

655d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/49f87d642f60da07b4a8ecd8c53ece377b8be2a2283181db7e0d9c7a87a4631c?d=identicon)[fresh7849](/maintainers/fresh7849)

---

Top Contributors

[![fresh7849](https://avatars.githubusercontent.com/u/21075537?v=4)](https://github.com/fresh7849 "fresh7849 (9 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/freshphp-gemini/health.svg)

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

###  Alternatives

[googleads/googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP

67410.3M25](/packages/googleads-googleads-php-lib)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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