Download the PHP package alexandrevega/gemini-api-client without Composer
On this page you can find all versions of the php package alexandrevega/gemini-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexandrevega/gemini-api-client
More information about alexandrevega/gemini-api-client
Files in alexandrevega/gemini-api-client
Package gemini-api-client
Short Description API client for Google's Gemini API
License MIT
Informations about the package gemini-api-client
Gemini API PHP Client
This library is a fork of gemini-api-php/client adding system instructions and updating api to v1beta.
Gemini API PHP Client allows you to use the Google's generative AI models, like Gemini Pro and Gemini Pro Vision.
This library is not developed or endorsed by Google.
- Erdem Köse - github.com/erdemkose
- Alexandre Vega - github.com/alexandrevega
Table of Contents
- Installation
- How to use
- Basic text generation
- Multimodal input
- Chat Session (Multi-Turn Conversations)
- Chat Session with history
- Streaming responses
- Streaming Chat Session
- System Instruction
- Tokens counting
- Listing models
- Advanced Usages
- Safety Settings and Generation Configuration
- Using your own HTTP client
- Using your own HTTP client for streaming responses
Installation
You need an API key to gain access to Google's Gemini API. Visit Google AI Studio to get an API key.
First step is to install the Gemini API PHP client with Composer.
Gemini API PHP client does not come with an HTTP client.
If you are just testing or do not have an HTTP client library in your project,
you need to allow php-http/discovery
composer plugin or install a PSR-18 compatible client library.
How to use
Basic text generation
Multimodal input
Image input modality is only enabled for Gemini Pro Vision model
Chat Session (Multi-Turn Conversations)
Chat Session with history
Streaming responses
Requires
curl
extension to be enabled
In the streaming response, the callback function will be called whenever a response is returned from the server.
Long responses may be broken into separate responses, and you can start receiving responses faster using a content stream.
Streaming Chat Session
Requires
curl
extension to be enabled
System Instruction
You can add System Instructions to steer the behaviour of Gemini.
Embed Content
Tokens counting
Listing models
Advanced Usages
Safety Settings and Generation Configuration
Using your own HTTP client
Using your own HTTP client for streaming responses
Requires
curl
extension to be enabled
Since streaming responses are fetched using curl
extension, they cannot use the custom HTTP client passed to the Gemini Client.
You need to pass a CurlHandler
if you want to override connection options.
The following curl options will be overwritten by the Gemini Client.
CURLOPT_URL
CURLOPT_POST
CURLOPT_POSTFIELDS
CURLOPT_WRITEFUNCTION
You can also pass the headers you want to be used in the requests.
All versions of gemini-api-client with dependencies
php-http/discovery Version ^1.19
psr/http-client Version ^1.0
psr/http-client-implementation Version *
psr/http-factory Version ^1.0.2
psr/http-factory-implementation Version *
psr/http-message Version ^1.0.1 || ^2.0