The request builders are the translation layer between PHP AI SDK request objects and the raw JSON bodies sent to the Gemini API.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.
GoogleRequestBuilder handles text generation requests, and GoogleImageRequestBuilder handles image generation requests. You do not call these classes directly in normal usage — GoogleTextModel and GoogleImageModel call them internally — but understanding their output is valuable when you need to pass providerOptions('google')['raw'] overrides or debug unexpected API errors.
GoogleRequestBuilder
Namespace: AiSdk\Google\Support\GoogleRequestBuilder
Converts a TextModelRequest into a Gemini-compatible JSON body for both synchronous and streaming calls.
build() Signature
The Gemini model identifier. Placed verbatim in the
model key of the output body.The provider name string (
'google'). Used to look up providerOptions('google')['raw'] from the request.The SDK request object containing messages, system prompt, generation parameters, output format, and provider-specific options.
When
true, adds "stream": true to the top-level body. GoogleTextModel passes false for generate() and true for stream().Output Body Structure
The
$modelId passed to build().When the request contains exactly one user message with a single text part, this is a plain string shortcut. In all other cases it is an array of step objects — one per message — each with
type and content keys.Generation parameters. See generation_config keys below.
Present only when
$request->system is a non-empty string.Present only when
$stream is true.input — Single-Message Shortcut vs. Step Array
When there is exactly one message, the role is user, and that message contains a single text part, build() collapses input to a plain string:
input becomes an array of step objects:
type value is derived from the message role:
| Role | Step type |
|---|---|
user | user_input |
assistant | model_response |
tool | tool_result |
Content Parts
Eachcontent array contains one or more part objects. The shape depends on the content type:
Text part:
SDK Content::TYPE_* | Part type |
|---|---|
TYPE_IMAGE | image |
TYPE_AUDIO | audio |
TYPE_FILE | document |
generation_config Keys
Mapped from
$request->maxTokens. Always present (may be null).Mapped from
$request->temperature. Always present (may be null).Mapped from
$request->topP. Only included when topP is non-null.Mapped from
$request->reasoning->effort. Only included when reasoning effort is set.Set to
'application/json' when $request->output is an Output of kind object. Only included when structured output is requested.The JSON Schema array from
$request->output->schema->jsonSchema(). Only included when a schema is provided alongside response_mime_type.Raw Passthrough (Shallow Merge)
After the body is assembled,build() applies any raw provider overrides using a shallow array_replace:
$raw replace keys in the built body outright. If you pass 'generation_config' inside $raw, it replaces the entire generation_config array rather than merging individual keys. Use this to pass Gemini-specific parameters that have no SDK equivalent.
GoogleImageRequestBuilder
Namespace: AiSdk\Google\Support\GoogleImageRequestBuilder
Converts an ImageRequest into a Gemini generateContent JSON body for image generation.
build() Signature
The provider name string (
'google'). Used to look up providerOptions('google')['raw'] from the request.The SDK image request object. Must have
count === 1 and seed === null; otherwise an InvalidArgumentException is thrown immediately.Output Body Structure
The text prompt from
$request->prompt. This is the only input content sent for image generation.Always
['TEXT', 'IMAGE']. Required by the Gemini image generation API to signal that image output is expected.Passed through from
$request->aspectRatio when set (e.g. '16:9', '1:1', '9:16').Derived from
$request->size (a 'widthxheight' string) by taking the longest edge. Values larger than 1024 map to '2K'; values of 1024 or smaller map to '1K'.Size Mapping
The image size string (e.g.'1920x1080') is converted to a Gemini size tier:
| Longest edge | Gemini image_size |
|---|---|
| > 1024 px | '2K' |
| ≤ 1024 px | '1K' |
Raw Passthrough (Recursive Merge)
After the body is assembled,build() applies raw provider overrides using a recursive array_replace_recursive:
The merge strategy differs between the two builders:
GoogleRequestBuilder(text) usesarray_replace— a shallow merge. Top-level keys in$rawreplace top-level keys in the body. Passing'generation_config'replaces the entire generation config object.GoogleImageRequestBuilder(image) usesarray_replace_recursive— a deep merge. Nested arrays are merged key-by-key, so you can add a single field insidegeneration_config.image_configwithout replacing the whole structure.
$raw payload shape accordingly to avoid inadvertently deleting required fields.