Skip to main content

Variable: xai

const xai: (modelId, config?) => ModelConfig & object

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

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.

Type Declaration

models

models: (config?) => Promise<ModelInfo[]>

List the xAI (Grok) models the configured key can see, newest-first.

Parameters

config?

ProviderConfig

Returns

Promise<ModelInfo[]>

Param

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

Param

Optional configuration (provider settings + reasoning).

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' })
});