Documentation 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.
XAIOptions lives in the AiSdk\XAI namespace and is a readonly value object that carries every piece of configuration that XAIProvider, XAITextModel, and XAIImageModel need to authenticate and communicate with the xAI API. Build one either through its constructor or, more conveniently, via the fromArray() static factory which resolves missing values from environment variables automatically.
Namespace and import
Constants
| Constant | Value |
|---|---|
XAIOptions::DEFAULT_BASE_URL | 'https://api.x.ai/v1' |
XAIOptions::PROVIDER_NAME | 'xai' |
Constructor parameters
Bearer token used to authenticate every request to the xAI API. When using
fromArray() without supplying this key, the value is loaded from the XAI_API_KEY environment variable. An exception is thrown if neither source provides a non-empty string.Root URL of the xAI API. Trailing slashes are stripped automatically. Override via the
XAI_BASE_URL environment variable or by passing baseUrl to fromArray(). You rarely need to change this unless you are pointing at a self-hosted or proxy endpoint.Extra HTTP headers merged into every outgoing request on top of the standard
Authorization header. Useful for request tracing, custom routing, or other middleware requirements.Optional PSR-18 HTTP client wrapper (
AiSdk\Support\Sdk). When null, the provider uses the default HTTP client bundled with the SDK. Pass a custom instance to control timeouts, proxies, or to inject a mock client in tests.fromArray()
XAIOptions instance from a plain associative array. Any key that is absent or null falls back to the corresponding environment variable, and then to the built-in default.
Accepted keys: apiKey, baseUrl, headers, sdk.
Associative array with any combination of the keys
apiKey, baseUrl, headers, and sdk. Missing keys are resolved from environment variables (XAI_API_KEY, XAI_BASE_URL) or built-in defaults.A fully resolved, immutable
XAIOptions instance.authHeaders()
Authorization: Bearer … header merged with any additional headers supplied in the headers constructor parameter. Keys from headers take precedence in case of collision.
Merged array of
Authorization and any extra headers. Safe to pass directly to an HTTP request builder.