TheDocumentation 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.
aisdk/google package is the official Google Gemini provider for the PHP AI SDK. It translates the SDK’s portable Generate::text() builder into the Gemini Responses API, handles authentication with your API key, and maps the raw JSON reply back to a consistent TextModelResponse object — so your application code stays the same regardless of which model you choose.
Basic Example
Pass a model created withGoogle::model() and a prompt string to produce a synchronous text response. The call blocks until the full response is received and returns a TextModelResponse.
Generate::text() as a shorthand:
System Instructions
Use->instructions() to supply a system-level instruction that shapes the model’s behaviour for the entire conversation. The string is sent as the system_instruction field in the request body and is applied before any user turn.
Generation Parameters
Three portable parameters map directly into Gemini’sgeneration_config object:
| Method | Request field | Default |
|---|---|---|
->maxTokens(int) | generation_config.max_output_tokens | 1024 |
->temperature(float) | generation_config.temperature | provider default |
->topP(float) | generation_config.top_p | provider default |
Reading the Response
->run() returns a TextModelResponse with the following properties:
Text output
Token usage
gemini-3.5-flash with reasoning enabled), the SDK tracks reasoning tokens separately:
Provider metadata
The raw Gemini response fieldsid, model, finish_reason, usage_metadata, and prompt_feedback are forwarded verbatim under the google key:
Finish reason
$result->finishReason is a FinishReason enum value normalised from whatever Gemini returns:
| Gemini value | SDK enum |
|---|---|
stop, stopped, end_turn | FinishReason::Stop |
max_tokens, max_output_tokens, length | FinishReason::Length |
safety, content_filter, blocked | FinishReason::ContentFilter |
| Any tool-call response | FinishReason::ToolCalls |
Multi-Turn Conversations
For conversational applications, build amessages array and pass it with ->messages(). Each entry uses a Message object with a role of user or assistant.
user_input, model_response, tool_result) before sending. Single-turn requests with one plain text user message are optimised to a bare string in the input field.
The SDK routes all text generation requests to
/interactions, not to the native Gemini generateContent endpoint. The default base URL is https://generativelanguage.googleapis.com/v1beta, making the full path https://generativelanguage.googleapis.com/v1beta/interactions. You can override baseUrl in Google::create() if you proxy requests through your own gateway.