new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Providers · all subjects

xai/models

25 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

xAI language model instantiation

Create xAI language models using `xai('model-id')`. For example: `const model = xai('grok-4.20-non-reasoning');`

xAI text generation example

Example of using xAI language models with generateText: ```ts import { xai } from '@ai-sdk/xai'; import { generateText } from 'ai'; const { text } = await generateText({ model: xai('grok-4.20-non-reasoning'), prompt: 'Write a vegetarian lasagna recipe for 4 people.', }); ```

xAI Realtime API models

Create realtime models using `.experimental_realtime('grok-voice-latest')` factory method. Realtime sessions run in the browser and require a short-lived token created on the server with `xai.experimental_realtime.getToken({ model: 'grok-voice-latest' })`.

xAI Responses API instantiation

Create Responses API models using `xai.responses('model-id')` or use `xai(modelId)` which defaults to Responses API since AI SDK 7. This enables autonomous tool orchestration and research on xAI's servers.

xAI language model capabilities table

xAI language model capabilities: grok-4.5 (image input ✓, object generation ✓, tool usage ✓, tool streaming ✓, reasoning ✓), grok-4.20-reasoning (image ✓, objects ✓, tools ✓, streaming ✓, reasoning ✓), grok-4.20-non-reasoning (image ✓, objects ✓, tools ✓, streaming ✓, reasoning ✗), grok-4-1-fast-reasoning (image ✓, objects ✓, tools ✓, streaming ✓, reasoning ✓), grok-4-1-fast-non-reasoning (image ✓, objects ✓, tools ✓, streaming ✓, reasoning ✗), grok-4-1 (image ✗, objects ✓, tools ✓, streaming ✓, reasoning ✗), grok-4-fast-reasoning (image ✓, objects ✓, tools ✓, streaming ✓, reasoning ✓), grok-4-fast-non-reasoning (image ✓, objects ✓, tools ✓, streaming ✓, reasoning ✗), grok-code-fast-1 (image ✗, objects ✓, tools ✓, streaming ✓, reasoning ✓), grok-3 (image ✗, objects ✓, tools ✓, streaming ✓, reasoning ✗), grok-3-mini (image ✗, objects ✓, tools ✓, streaming ✓, reasoning ✓).

xAI speech model instantiation

Create speech models using `.speech()` factory method: `const model = xai.speech();`. The xAI text-to-speech endpoint does not require a model identifier.

xAI text-to-speech example

Example of using xAI speech models with generateSpeech: ```ts import { xai } from '@ai-sdk/xai'; import { generateSpeech } from 'ai'; const result = await generateSpeech({ model: xai.speech(), text: 'Hello from the AI SDK!', voice: 'ara', language: 'en', outputFormat: 'mp3', speed: 1.1, }); ```

xAI transcription model instantiation

Create transcription models using `.transcription()` factory method: `const model = xai.transcription();`. The xAI batch transcription endpoint does not require a model identifier.

xAI transcription example

Example of using xAI transcription models with transcribe: ```ts import { xai } from '@ai-sdk/xai'; import { transcribe } from 'ai'; import { readFile } from 'fs/promises'; const result = await transcribe({ model: xai.transcription(), audio: await readFile('meeting.mp3'), }); ```

xAI text-to-image example

Example of xAI text-to-image with generateImage: ```ts import { xai } from '@ai-sdk/xai'; import { generateImage } from 'ai'; const { image } = await generateImage({ model: xai.image('grok-imagine-image'), prompt: 'A futuristic cityscape at sunset', }); ```

xAI image editing basic example

Example of basic image editing: ```ts import { xai } from '@ai-sdk/xai'; import { generateImage } from 'ai'; import { readFileSync } from 'fs'; const imageBuffer = readFileSync('./input-image.png'); const { images } = await generateImage({ model: xai.image('grok-imagine-image'), prompt: { text: 'Turn the cat into a golden retriever dog', images: [imageBuffer], }, }); ```

xAI multi-image editing example

Example of multi-image editing: ```ts import { xai } from '@ai-sdk/xai'; import { generateImage } from 'ai'; import { readFileSync } from 'fs'; const cat = readFileSync('./cat.png'); const dog = readFileSync('./dog.png'); const { images } = await generateImage({ model: xai.image('grok-imagine-image'), prompt: { text: 'Combine these two animals into a group photo', images: [cat, dog], }, }); ```

xAI style transfer example

Example of style transfer: ```ts const imageBuffer = readFileSync('./input-image.png'); const { images } = await generateImage({ model: xai.image('grok-imagine-image'), prompt: { text: 'Transform this into a watercolor painting style', images: [imageBuffer], }, aspectRatio: '1:1', }); ```

xAI image model capabilities

xAI image model capabilities: grok-imagine-image-pro (resolution: 1k, 2k; aspect ratios: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, auto; image editing: ✓), grok-imagine-image (resolution: 1k; aspect ratios: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, auto; image editing: ✓).

xAI text-to-video example

Example of text-to-video generation: ```ts import { xai, type XaiVideoModelOptions } from '@ai-sdk/xai'; import { experimental_generateVideo as generateVideo } from 'ai'; const { video } = await generateVideo({ model: xai.video('grok-imagine-video'), prompt: 'A chicken flying into the sunset in the style of 90s anime.', aspectRatio: '16:9', duration: 5, providerOptions: { xai: { user: 'user-123', pollTimeoutMs: 600000, } satisfies XaiVideoModelOptions, }, }); ```

xAI image-to-video example

Example of image-to-video generation: ```ts import { xai, type XaiVideoModelOptions } from '@ai-sdk/xai'; import { experimental_generateVideo as generateVideo } from 'ai'; const { video } = await generateVideo({ model: xai.video('grok-imagine-video'), prompt: { image: 'https://example.com/start-frame.png', text: 'The cat slowly turns its head and blinks', }, duration: 5, providerOptions: { xai: { pollTimeoutMs: 600000, } satisfies XaiVideoModelOptions, }, }); ```

xAI video with frameImages example

Example of video with frameImages using first_frame role: ```ts import { xai, type XaiVideoModelOptions } from '@ai-sdk/xai'; import { experimental_generateVideo as generateVideo } from 'ai'; import fs from 'node:fs'; const { video } = await generateVideo({ model: xai.video('grok-imagine-video'), prompt: 'The cat slowly turns its head and blinks', frameImages: [ { image: fs.readFileSync('./start-frame.png'), frameType: 'first_frame', }, ], duration: 5, providerOptions: { xai: { pollTimeoutMs: 600000, } satisfies XaiVideoModelOptions, }, }); ```

xAI video editing example

Example of video editing: ```ts import { xai, type XaiVideoModelOptions } from '@ai-sdk/xai'; import { experimental_generateVideo as generateVideo } from 'ai'; const { video } = await generateVideo({ model: xai.video('grok-imagine-video'), prompt: 'Give the person sunglasses and a hat', providerOptions: { xai: { mode: 'edit-video', videoUrl: 'https://example.com/source-video.mp4', pollTimeoutMs: 600000, } satisfies XaiVideoModelOptions, }, }); ```

xAI video extension example

Example of video extension: ```ts import { xai, type XaiVideoModelOptions } from '@ai-sdk/xai'; import { experimental_generateVideo as generateVideo } from 'ai'; const source = await generateVideo({ model: xai.video('grok-imagine-video'), prompt: 'A cat sitting on a sunlit windowsill, tail gently swishing.', duration: 5, aspectRatio: '16:9', providerOptions: { xai: { pollTimeoutMs: 600000, } satisfies XaiVideoModelOptions, }, }); const sourceUrl = source.providerMetadata?.xai?.videoUrl as string; const extended = await generateVideo({ model: xai.video('grok-imagine-video'), prompt: 'The cat turns its head, notices a butterfly, and leaps off.', duration: 6, providerOptions: { xai: { mode: 'extend-video', videoUrl: sourceUrl, pollTimeoutMs: 600000, } satisfies XaiVideoModelOptions, }, }); ```

xAI reference-to-video R2V example

Example of reference-to-video generation: ```ts import { xai, type XaiVideoModelOptions } from '@ai-sdk/xai'; import { experimental_generateVideo as generateVideo } from 'ai'; const { video } = await generateVideo({ model: xai.video('grok-imagine-video'), prompt: 'The comic cat from <IMAGE_1> and the comic dog from <IMAGE_2> ' + 'are having a playful chase through a sunlit park. ' + 'Cinematic slow-motion, warm afternoon light.', duration: 8, aspectRatio: '16:9', providerOptions: { xai: { mode: 'reference-to-video', referenceImageUrls: [ 'https://example.com/comic-cat.png', 'https://example.com/comic-dog.png', ], pollTimeoutMs: 600000, } satisfies XaiVideoModelOptions, }, }); ```

xAI reference-to-video with inputReferences example

Example of reference-to-video using provider-agnostic inputReferences: ```ts import { xai, type XaiVideoModelOptions } from '@ai-sdk/xai'; import { experimental_generateVideo as generateVideo } from 'ai'; import fs from 'node:fs'; const { video } = await generateVideo({ model: xai.video('grok-imagine-video'), prompt: 'The comic cat and the comic dog are having a playful chase ' + 'through a sunlit park. Cinematic slow-motion, warm afternoon light.', inputReferences: [ fs.readFileSync('./comic-cat.png'), fs.readFileSync('./comic-dog.png'), ], duration: 8, aspectRatio: '16:9', providerOptions: { xai: { pollTimeoutMs: 600000, } satisfies XaiVideoModelOptions, }, }); ```

xAI video model capabilities

grok-imagine-video: Duration 1-15s, Aspect Ratios (1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3), Resolution (480p, 720p), Image-to-Video ✓, Editing ✓, Extension ✓, R2V ✓

xAI file search requirements

File search requires grok-4 family models (including grok-4.20) and the Responses API. Vector stores can be created using the xAI API.

xAI streaming text support

xAI language models can be used with the streamText function and support structured data generation with Output.

xAI model instantiation factory methods

Create xAI models using factory methods: Video models: Use the `.video()` factory method with the 'grok-imagine-video' model identifier: ``` const model = xai.video('grok-imagine-video'); ``` Image models: Use the `.image()` factory method with the 'grok-imagine-image' model identifier: ``` const model = xai.image('grok-imagine-image'); ```

Give your agent this brain