TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/xai/llms.txt
Use this file to discover all available pages before exploring further.
aisdk/core abstraction covers the capabilities common to all providers — prompts, tools, schemas, reasoning effort, and so on. When you need to use an xAI-specific parameter that has no portable equivalent, providerOptions() gives you a direct escape hatch: values placed under the 'raw' key are merged into the JSON request body that is sent to the xAI API, after all portable fields have been set.
The providerOptions() Method
Call ->providerOptions() on any Generate builder, passing the provider name 'xai' as the first argument and an options array as the second. Put any parameters you want forwarded verbatim inside the 'raw' key:
'xai' namespace ensures these options are only applied when the request is processed by the xAI provider and are silently ignored by any other provider your code may be configured to use.
Example: Live Search Parameters
xAI’s Grok models support asearch_parameters field that controls real-time web search behaviour. Pass it through providerOptions() to enable or configure live search on a request:
'mode' => 'auto', Grok decides whether a web search is necessary to answer the question. Refer to the xAI API documentation for the full list of search_parameters options.
Example: Image Resolution
When generating images, xAI-specific generation parameters such asresolution can be forwarded the same way:
resolution key is merged directly into the /v1/images/generations request body, alongside the portable fields (model, prompt, n, response_format, etc.) that the SDK sets automatically.
How It Works
Internally, theChatRequestBuilder (and its image counterpart) checks $request->providerOptions('xai')['raw'] ?? [] and merges those entries into the final request array before it is JSON-encoded and dispatched. This means:
- Raw keys override any portable field with the same name if there is a collision.
- The merged body is sent as-is to the xAI API — no further transformation is applied.
- Other providers in the same application are unaffected because the options are scoped to
'xai'.