Skip to main content

Function: xai()

xai(modelId, config?): ModelConfig

Defined in: packages/core/src/providers/factories.ts:434

Configure xAI (Grok) provider explicitly.

xAI serves the Grok family at https://api.x.ai/v1 using an OpenAI Chat Completions-compatible wire format. Model IDs follow the grok-* prefix (grok-2, grok-2-vision, grok-3, grok-4, grok-code-fast-1, etc.). Auto-detection routes any grok-* model to this provider — the factory is for when you want explicit config (custom apiKey, baseUrl, reasoning, headers, fetch).

Multimedia: vision-tagged Grok variants accept images via the standard AI SDK content-part path. Audio and arbitrary file inputs are not currently supported by xAI.

Parameters

modelId

string

Grok model ID, e.g. 'grok-4'

config?

ProviderConfig & object

Optional configuration (provider settings + reasoning).

Returns

ModelConfig

Examples

const bot = new Baleybot({ model: xai('grok-4') });
const bot = new Baleybot({
model: xai('grok-4', { reasoning: { effort: 'high' } })
});
const bot = new Baleybot({
model: xai('grok-4', { apiKey: 'xai-...', baseUrl: 'https://my-proxy.example/v1' })
});