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.
ChatRequestBuilder and ImageRequestBuilder are designed around the portable aisdk/core contract. They handle the fields that are meaningful across every OpenAI-compatible provider: model, messages, temperature, tools, reasoning effort, image size, and so on. But OpenAI-compatible providers are not identical — one may accept a seed parameter for reproducibility, another may need a background field for image transparency, and a third may use a non-standard resolution key that has no portable equivalent. Rather than forking the shared builder for each provider, both builders expose a single, well-defined escape hatch: the raw key inside a provider-namespaced options array.
How providerOptions Works
TextModelRequest and ImageRequest both accept a providerOptions array keyed by provider name. At build time, the builder calls $request->providerOptionsFor($providerName) to retrieve only the options scoped to the current provider, ignoring every other provider’s namespace entirely.
The raw Key
Within the provider namespace, theraw key is reserved for arbitrary body overrides. If providerOptions[$providerName]['raw'] is an array, it is merged into the request body using array_replace() as the very last operation — after every portably-built field has already been set.
ImageRequestBuilder::build():
array_replace() gives precedence to the second argument, any key in raw that matches a portably-set key will overwrite it.
Chat Example: temperature and seed
The test suite demonstrates injectingtemperature and seed into a chat request body via raw:
temperature is also a portable field that ChatRequestBuilder sets earlier in the build process. Because raw is merged last, the value 0.1 from raw overwrites whatever the portable $request->temperature was.
Image Example: transparent background
Provider-specific image parameters that have no portable equivalent are a natural fit forraw:
Provider-Specific Builder Options with raw: the xAI Example
ImageRequestBuilder::build() also accepts a fourth $options argument that lets provider packages configure the builder’s behavior (e.g., which parameter name to use for aspect ratio, whether to infer a size from the aspect ratio). The raw escape hatch works on top of whatever the builder produces from those options:
$options while still using raw for any fields that the builder itself will never handle.
When should I use raw vs. a new parameter?
When should I use raw vs. a new parameter?
Use
raw when:- The field is specific to one provider and has no meaningful equivalent across other providers.
- You need a quick workaround for a provider-specific quirk without changing shared package code.
- You are building a provider package and need to expose an advanced option to end users before it is part of the portable contract.
- Multiple OpenAI-compatible providers support the same semantic concept under the same or similar field names.
- The capability is something every caller of the PHP AI SDK would benefit from expressing portably (e.g., a new
topKparameter, or structured output schema support). - You want the value to be validated, documented, and tested at the SDK level rather than hidden in a raw map.
raw escape hatch is intentionally narrow — one key, merged last — to keep the boundary between portable and provider-specific behavior explicit and auditable.