Download the PHP package google-gemini-api-php/client without Composer
On this page you can find all versions of the php package google-gemini-api-php/client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download google-gemini-api-php/client
More information about google-gemini-api-php/client
Files in google-gemini-api-php/client
Package client
Short Description PHP API client for Google's Gemini API
License MIT
Informations about the package client
Gemini API PHP Gemini
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.
- Usman IlamDin - github.com/usmanilamdin
Table of Contents
- Installation
- How to use
- Basic text generation
- Text generation using cached content and file uploaded
- Multimodal input
- Chat Session (Multi-Turn Conversations)
- Chat Session with history
- Streaming responses
- Streaming Chat Session
- Tokens counting
- Cached Content Resource
- create
- delete
- get
- list
- patch
- File Resource
- delete
- get
- list
- Media Resource
- upload
- 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
Text generation using cached content and file uploaded
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
Embed Content
Cached Content Resource
create
Creates CachedContent resource.
This example uses the Sherlock Jr. movie video used in documentation. File was first uploaded with media upload
Generate Content with a Cached Content
The timeout for `generateContent` is set to 60s, request timeout to 120s. If your request is still exceeding these limits you may propose an increase.delete
Deletes CachedContent resource.
get
Reads CachedContent resource.
list
Lists CachedContents.
patch
Updates CachedContent resource (only expiration is updatable).
File Resource
delete
Deletes the File
.
get
Gets the metadata for the given File
.
list
Lists the metadata for File
s owned by the requesting project.
Media Resource
upload
Creates a File
.
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.
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 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