Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/google/llms.txt

Use this file to discover all available pages before exploring further.

Getting aisdk/google into your project takes a single Composer command. The package requires PHP 8.3 or later and the aisdk/core SDK at ^0.2, both of which Composer resolves automatically. Once the package is installed, you only need to expose your Gemini API key as an environment variable and the provider is ready to use without any further bootstrapping code.
Requirements: PHP ^8.3 and aisdk/core ^0.2. Both are declared as hard requirements in composer.json and will be installed automatically.
1

Require the package

Run the following command in your project root to add aisdk/google to your composer.json and download it:
composer require aisdk/google
Composer will pull in aisdk/core and any transitive dependencies at the same time.
2

Set your Gemini API key

The provider resolves your API key from the environment at runtime. Export it before running your application, or add it to your .env file if you use a library such as vlucas/phpdotenv.The primary variable is GOOGLE_GENERATIVE_AI_API_KEY. If that variable is absent the provider automatically falls back to GEMINI_API_KEY:
# Primary — recommended
export GOOGLE_GENERATIVE_AI_API_KEY=your-api-key-here

# Fallback (also accepted)
export GEMINI_API_KEY=your-api-key-here
Both variables are checked automatically — you never need to change your code when switching between them. See the Authentication guide for programmatic configuration options such as passing the key directly via Google::create().
3

Verify the installation

Create a small smoke-test script to confirm the provider initialises correctly and the API key is reachable:
<?php

require __DIR__ . '/vendor/autoload.php';

use AiSdk\Google;

// Explicit configuration (useful in tests or CI)
Google::create([
    'apiKey' => getenv('GOOGLE_GENERATIVE_AI_API_KEY'),
]);

// Confirm the provider name resolves
var_dump(Google::default()->name()); // string(6) "google"
If you see string(6) "google" printed without an exception, the package is installed and your API key is valid.
For full details on programmatic configuration — including custom base URLs, additional HTTP headers, and custom PSR-18 HTTP clients — see the Authentication & Configuration guide.

Build docs developers (and LLMs) love