Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/openai-compatible/llms.txt
Use this file to discover all available pages before exploring further.
ImageRequestBuilder is a static utility called by provider adapters that speak the OpenAI-compatible /images/generations wire format. It converts a portable ImageRequest — carrying prompt text, image count, optional size or aspect ratio, seed, and per-provider options — into the array<string, mixed> body that is sent directly to the endpoint. The $options array makes the builder flexible enough to serve providers that diverge slightly from OpenAI’s own parameter names, so a single class eliminates the need for per-provider builder copies.
Namespace
Method
build()
ImageRequest into an OpenAI-compatible request body. The returned array always contains model, prompt, and n. Additional keys are added depending on the $options configuration and the fields present on $request.
Parameters
The model identifier to embed in the request body as
model. This is the
provider-specific model string, e.g. "dall-e-3" or
"grok-imagine-image-quality".The canonical provider name, e.g.
"openai" or "xai". Used to extract
$request->providerOptionsFor($providerName)['raw'] for the raw escape
hatch merge.The portable image generation request. The builder reads the following fields:
prompt— the text description of the image to generate.count— number of images to generate (n).size— explicit size string such as"1024x1024". WhennullandinferSizeFromAspectRatioistrue, the size is derived fromaspectRatio.aspectRatio— canonical ratio string such as"16:9"or"1:1".seed— optional integer seed for reproducible generation.providerOptions— provider-keyed map; the['raw']sub-key under$providerNameis merged last into the body.
Configuration array that controls how the body is assembled. All keys are
optional.
Request Body Keys
| Key | Always present | Description |
|---|---|---|
model | ✅ | Value of $modelId |
prompt | ✅ | Value of $request->prompt |
n | ✅ | Value of $request->count |
response_format | When includeResponseFormat is true (default) | Fixed value "b64_json" |
size / custom | When sizeParameter is non-null and a size can be resolved | Resolved size string |
aspect_ratio / custom | When aspectRatioParameter is non-null and $request->aspectRatio is non-null | The aspect ratio string |
seed / custom | When seedParameter is non-null and $request->seed is non-null | The integer seed |
| (raw keys) | When providerOptions contains a raw array for the provider | Merged last, can override any key above |
Aspect Ratio → Size Mapping
WheninferSizeFromAspectRatio is true and no explicit size is set, the
builder maps $request->aspectRatio to a fixed pixel dimension string using
the following table:
| Aspect ratio | Resolved size |
|---|---|
1:1 | 1024x1024 |
3:2 | 1536x1024 |
16:9 | 1536x1024 |
2:3 | 1024x1536 |
9:16 | 1024x1536 |
Raw Escape Hatch
Any array stored under$request->providerOptionsFor($providerName)['raw']
is merged into the body last using array_replace. This means raw keys
can override any key that the builder itself wrote, giving you full control
over the final payload without subclassing or forking the builder.
Examples
1 — Basic call with an explicit size
This example is drawn from the wire-format integration test. It passes an explicitsize and uses the raw escape hatch to add a provider-specific
background parameter.
2 — Aspect ratio inference (16:9 → 1536x1024)
Whensize is omitted, the builder derives it automatically from aspectRatio.
This keeps provider adapters free of hard-coded dimension strings.
3 — Provider-specific variant with aspect_ratio parameter and no size
Some providers — such as xAI’s image models — accept an aspect_ratio key
directly and do not want a size field at all. Pass aspectRatioParameter,
disable inferSizeFromAspectRatio, and set sizeParameter to null.