Download the PHP package ldkafka/yii2-google-gemini without Composer

On this page you can find all versions of the php package ldkafka/yii2-google-gemini. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-google-gemini

Yii2 Google Gemini Component (v2.0.0)

Native, strongly-typed Yii2 component for the Google Gemini REST API. No external SDKs – only yii\\httpclient. Provides generation (text & multimodal), streaming, embeddings, Files API, token counting, and flexible caching strategies.

What’s New in 2.0.0

Feature Summary

Area Capabilities
Generation Text, multimodal (image/audio/video/document via inline or file references)
Streaming SSE incremental output with user callback
Caching none, client (Yii cache history), server (Gemini CachedContent)
Embeddings Single + batch embeddings for RAG / similarity
Files Upload, list, get, delete (simplified direct PUT)
Models Enumerate models, inspect limits/capabilities
Tokens Pre-flight token counting for cost estimation
Helpers extractText, getFinishReason, getUsageMetadata

Requirements

Installation

Quick Start

Basic Configuration

Simple Text Generation

Usage Examples

1. Basic Text Generation

2. Streaming Responses

3. Multimodal (Text + Image)

4. Client-side Conversation Caching

5. Server-side Context Caching (Advanced)

6. System Instructions

7. File Uploads

8. Embeddings

9. Token Counting

10. Model Discovery

Caching Modes Deep Dive

Mode Purpose Storage Pros Cons
none Stateless requests None Simplicity No memory of prior turns
client Short/medium chats Yii cache (gem_chat_<id>) Fast, light, adjustable TTL History grows; prune for very long sessions
server Large domain context Gemini CachedContent Huge reusable context on provider side Requires ~32K+ tokens; creation often fails if too small

Server cache creation requires a very large system instruction document. Use countTokens() before attempting createServerCache().

Console Commands

Example test commands in console/controllers/TestController.php:

Configuration Options

Component Properties

Property Type Default Description
apiKey string required Your Gemini API key (Get one)
baseUrl string https://generativelanguage.googleapis.com/v1/ API base URL
generationConfig array [] Default generation parameters
safetySettings array [] Content safety filters
systemInstruction array|null null Default system instruction
cacheType string 'none' Cache mode: 'none', 'client', 'server'
cacheTtl int 3600 Cache TTL in seconds
cacheComponent string|null 'cache' Yii cache component name
httpConfig array [] Custom HTTP client configuration

Generation Config Options

Supported Models (Snapshot)

Model Description Context Window
gemini-2.5-pro Most powerful thinking model 2M tokens
gemini-2.5-flash Balanced, fast, 1M context 1M tokens
gemini-2.5-flash-lite Fastest, cost-efficient 1M tokens
text-embedding-004 Text embeddings for RAG N/A

See Gemini Models Documentation for full list.

Canonical Response Format

All methods return:

Helper Methods

Helper Methods

Cache Modes (Summary)

None (Stateless)

Client (Local Conversation History)

Server (Gemini Context Caching)

Note: Server caching requires minimum 32,000 tokens in cached content.

Error Handling Pattern

Advanced Usage

Custom HTTP Configuration

Multimodal with Multiple Images

Custom Safety Settings

Safety Settings Explained

safetySettings lets you tell Gemini which kinds of harmful content to filter and at what strictness. The value is an array of objects with a category and a threshold.

Example JSON payload as sent to the API:

Notes:

Testing

The package includes comprehensive test actions:

  1. actionGeminiNone - Test stateless generation
  2. actionGeminiClient - Test client-side conversation caching
  3. actionGeminiServer - Test server-side context caching

Troubleshooting

"API key not configured"

Ensure your API key is set in the component configuration or params.

"Failed to create server cache"

Server caching requires:

Use client-side caching for shorter conversations.

Streaming not working

Ensure your HTTP client supports Server-Sent Events (SSE). The default Yii2 HTTP client may need custom transport configuration.

Production Notes

Links

License

BSD-3-Clause (matches class header).

Support / Contributing

Open issues or PRs at: https://github.com/ldkafka/yii2-google-gemini

When reporting an issue, include:

  1. PHP / Yii versions
  2. Failing method and sample call
  3. Full response array (mask secrets)
  4. Expected vs actual behavior

Enjoy building with Gemini! Suggestions & improvements welcome.


All versions of yii2-google-gemini with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
yiisoft/yii2 Version ~2.0.14
yiisoft/yii2-httpclient Version ~2.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ldkafka/yii2-google-gemini contains the following files

Loading the files please wait ...