Download the PHP package hosseinhezami/laravel-gemini without Composer

On this page you can find all versions of the php package hosseinhezami/laravel-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 laravel-gemini

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.

Version Downloads Star License Laravel Compatible

Features

Installation

Publish the configuration file:

Add your Gemini API key to your .env file:

Configuration (detailed)

Configuration lives in config/gemini.php. Below are the most important keys and recommended defaults:

Key Description Default
api_key Your Gemini API key. env('GEMINI_API_KEY')
base_uri Base API endpoint. https://generativelanguage.googleapis.com/v1beta/
default_provider Which provider config to use by default. gemini
timeout Request timeout in seconds. 30
retry_policy.max_retries Retry attempts for failed requests. 30
retry_policy.retry_delay Delay between retries in ms. 1000
logging Log requests/responses (useful for debugging). false
stream.chunk_size Stream buffer chunk size. 1024
stream.timeout Stream timeout (ms). 1000
caching.default_ttl Default TTL for cache expiration (e.g., '3600s'). '3600s'
caching.default_page_size Default page size for listing caches. 50

Providers / models / methods

The providers array lets you map capability types to models and HTTP methods the provider uses:

Provider Capability Config key Default model Default method
gemini text providers.gemini.models.text gemini-2.5-flash-lite generateContent
gemini image providers.gemini.models.image gemini-2.5-flash-image-preview generateContent or predict
gemini video providers.gemini.models.video veo-3.0-fast-generate-001 predictLongRunning
gemini audio providers.gemini.models.audio gemini-2.5-flash-preview-tts generateContent
gemini embeddings providers.gemini.models.embedding gemini-embedding-001 n/a (embeddings endpoint)

Speech config (providers.gemini.default_speech_config) example:

Dynamic API Key Configuration

By default, Laravel Gemini reads the API key from your .env file (GEMINI_API_KEY).

However, you can now set the API key dynamically at runtime using the new setApiKey() method.
This is useful when you want to switch between multiple keys (e.g. per-user or per-request).

Example:

`

If setApiKey() is not called, the package will automatically use the default key from .env.

ApiKey priority order:

  1. Manually set key via Gemini::setApiKey()
  2. Config value (config/gemini.php)
  3. .env variable (GEMINI_API_KEY)

Builder APIs — full method reference

This package exposes a set of builder-style facades: Gemini::text(), Gemini::image(), Gemini::video(), Gemini::audio(), Gemini::embeddings(), Gemini::files() and Gemini::caches().

Below is a concise reference of commonly available chainable methods and what they do. Method availability depends on the builder.

Common response helpers (Response object)

When you call ->generate() (or a polling save on long-running jobs) you typically get a response object with these helpers:


Gemini::

TextBuilder (Gemini::text())

Use for: chat-like generation, long-context text, structured output, and multimodal understanding (text responses after uploading files).

Common methods:

Method Args Description
model(string) model id Choose model to use.
prompt(string/array) user prompt or parts Main prompt(s).
system(string) system instruction System-level instruction.
history(array) chat history Conversation history array (role/parts structure).
structuredSchema(array) JSON Schema Ask model to produce structured JSON (schema validation).
temperature(float) 0.0-1.0 Sampling temperature.
maxTokens(int) token limit Max tokens for generation.
safetySettings(array) array Safety thresholds from config.
method(string) provider method Override provider method name (e.g., generateContent).
upload(string $type, string $path) (type, local-file-path) Attach a file (image/document/audio/video) to the request.
cache(array $tools = [], array $toolConfig = [], string $displayName = null, string $ttl = null, string $expireTime = null) optional params Create a cache from current builder params and return cache name.
getCache(string $name) cache name Get details of a cached content.
cachedContent(string $name) cache name Use a cached content for generation.
stream(callable) callback Stream chunks (SSE / server events).
generate() Execute request and return a Response object.

Notes on history structure
History entries follow a role + parts format:

Text

Streaming Responses

Document Understanding

Structured output


ImageBuilder (Gemini::image())

Use for image generation.

Method Args Description
model(string) model id Model for image generation.
prompt(string) prompt text Image description.
method(string) e.g. predict Provider method (predict / generateContent).
cache(array $tools = [], array $toolConfig = [], string $displayName = null, string $ttl = null, string $expireTime = null) optional params Create a cache from current builder params and return cache name.
getCache(string $name) cache name Get details of a cached content.
cachedContent(string $name) cache name Use a cached content for generation.
generate() Run generation.
save($path) local path Save image bytes to disk.

Image


VideoBuilder (Gemini::video())

Use for short or long-running video generation.

Method Args Description
model(string) model id Video model.
prompt(string) prompt Describe the video.
cache(array $tools = [], array $toolConfig = [], string $displayName = null, string $ttl = null, string $expireTime = null) optional params Create a cache from current builder params and return cache name.
getCache(string $name) cache name Get details of a cached content.
cachedContent(string $name) cache name Use a cached content for generation.
generate() Initiates video creation (may be long-running).
save($path) local path Polls provider and saves final video file.

Note: long-running video generation typically uses predictLongRunning or similar. The package abstracts polling & saving.


AudioBuilder (Gemini::audio())

Use for TTS generation.

Method Args Description
model(string) model id TTS model.
prompt(string) text-to-speak Audio file description
voiceName(string) voice id Select a voice (e.g. Kore).
speakerVoices(array) speakers array Speakers (e.g. [['speaker' => 'Joe', 'voiceName' => 'Kore'], ['speaker' => 'Jane', 'voiceName' => 'Puck']]).
cache(array $tools = [], array $toolConfig = [], string $displayName = null, string $ttl = null, string $expireTime = null) optional params Create a cache from current builder params and return cache name.
getCache(string $name) cache name Get details of a cached content.
cachedContent(string $name) cache name Use a cached content for generation.
generate() Generate audio bytes.
save($path) local path Save generated audio (wav/mp3).

Embeddings (Gemini::embeddings())

Accepts a payload array. Typical shape:

Return value is the raw embeddings structure (provider-specific). Use these vectors for semantic search, similarity, clustering, etc.


Files API (Gemini::files())

High level file manager for uploads used by the "understanding" endpoints.

Method Args Description
upload(string $type, string $localPath) type in [document,image,video,audio] Upload a local file and return a provider uri or file id.
list() Return a list of uploaded files (metadata).
get(string $id) file id Get file metadata (name, uri, state, mimeType, displayName).
delete(string $id) file id Delete a previously uploaded file.

Files

Supported file types & MIME

Category Extension MIME type
image png image/png
image jpeg image/jpeg
image jpg image/jpeg
image webp image/webp
image heic image/heic
image heif image/heif
video mp4 video/mp4
video mpeg video/mpeg
video mov video/mov
video avi video/avi
video flv video/x-flv
video mpg video/mpg
video webm video/webm
video wmv video/wmv
video 3gpp video/3gpp
audio wav audio/wav
audio mp3 audio/mp3
audio aiff audio/aiff
audio aac audio/aac
audio ogg audio/ogg
audio flac audio/flac
document pdf application/pdf
document txt text/plain
document md text/markdown

Caching API (Gemini::caches())

High-level cache manager for pre-processing and storing content (prompts, system instructions, history, files) to reuse in generation requests, reducing latency and costs. Caches are model-specific and temporary.

Method Args Description
create(string $model, array $contents, ?string $systemInstruction = null, array $tools = [], array $toolConfig = [], ?string $displayName = null, ?string $ttl = null, ?string $expireTime = null) required/optional params Create a cached content and return CacheResponse.
list(?int $pageSize = null, ?string $pageToken = null) optional params List cached contents (supports pagination).
get(string $name) cache name Get details of a cached content.
update(string $name, ?string $ttl = null, ?string $expireTime = null) cache name and expiration Update cache expiration (TTL or expireTime).
delete(string $name) cache name Delete a cached content.

Caching

CacheResponse Methods

Caching in Generation Builders

Caching is also integrated into text, image, video, and audio builders for seamless use:

For more details, refer to the Gemini API Caching Documentation.


Streaming (Server-Sent Events)

The stream route uses Content-Type: text/event-stream. Connect from a browser or SSE client and consume data: <json> messages per chunk.


Streaming behaviour


Tips, error handling & best practices


Artisan Commands

The package includes helpful Artisan commands:

Command Description
php artisan gemini:models List available models.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-gemini with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2|^8.3|^8.4|^8.5
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.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 hosseinhezami/laravel-gemini contains the following files

Loading the files please wait ...