SpyBara
Go Premium

Documentation 2026-08-12 23:59 UTC to 2026-08-13 22:00 UTC

14 files changed +71 −69. View all changes and history on the product overview
2026
Mon 31 20:58 Tue 25 22:58 Fri 21 18:57 Thu 20 15:58 Wed 19 18:02 Tue 18 04:01 Thu 13 22:00 Wed 12 23:59 Tue 11 20:57 Sat 8 23:00 Fri 7 17:57 Thu 6 20:01 Mon 3 23:00 Sat 1 01:59
Details

127# Image generation127# Image generation

128image_req = client.image.prepare(128image_req = client.image.prepare(

129 prompt="A sleek modern laptop on a minimalist desk",129 prompt="A sleek modern laptop on a minimalist desk",

130 model="grok-imagine-image-quality",130 model="grok-imagine-image",

131 batch_request_id="img_001",131 batch_request_id="img_001",

132)132)

133batch_requests.append(image_req)133batch_requests.append(image_req)


135# Image edit135# Image edit

136image_edit_req = client.image.prepare(136image_edit_req = client.image.prepare(

137 prompt="Add a rainbow in the background",137 prompt="Add a rainbow in the background",

138 model="grok-imagine-image-quality",138 model="grok-imagine-image",

139 image_url="https://picsum.photos/800",139 image_url="https://picsum.photos/800",

140 batch_request_id="img_edit_001",140 batch_request_id="img_edit_001",

141)141)


240 batch_request: {240 batch_request: {

241 image_generation: {241 image_generation: {

242 prompt: "A sleek modern laptop on a minimalist desk",242 prompt: "A sleek modern laptop on a minimalist desk",

243 model: "grok-imagine-image-quality",243 model: "grok-imagine-image",

244 },244 },

245 },245 },

246});246});


251 batch_request: {251 batch_request: {

252 image_edit: {252 image_edit: {

253 prompt: "Add a rainbow in the background",253 prompt: "Add a rainbow in the background",

254 model: "grok-imagine-image-quality",254 model: "grok-imagine-image",

255 image: { url: "https://picsum.photos/800", type: "image_url" },255 image: { url: "https://picsum.photos/800", type: "image_url" },

256 },256 },

257 },257 },


870{"custom_id": "chat-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "grok-4.3", "messages": [{"role": "user", "content": "Classify this as positive, negative, or neutral: The product exceeded my expectations!"}]}}870{"custom_id": "chat-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "grok-4.3", "messages": [{"role": "user", "content": "Classify this as positive, negative, or neutral: The product exceeded my expectations!"}]}}

871{"custom_id": "search-1", "method": "POST", "url": "/v1/responses", "body": {"model": "grok-4.3", "tools": [{"type": "web_search"}, {"type": "x_search"}], "input": [{"role": "user", "content": "What are the latest SpaceX launches?"}]}}871{"custom_id": "search-1", "method": "POST", "url": "/v1/responses", "body": {"model": "grok-4.3", "tools": [{"type": "web_search"}, {"type": "x_search"}], "input": [{"role": "user", "content": "What are the latest SpaceX launches?"}]}}

872{"custom_id": "mcp-1", "method": "POST", "url": "/v1/responses", "body": {"model": "grok-4.3", "tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp"}], "input": [{"role": "user", "content": "What does the xai-sdk-python repo do?"}]}}872{"custom_id": "mcp-1", "method": "POST", "url": "/v1/responses", "body": {"model": "grok-4.3", "tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp"}], "input": [{"role": "user", "content": "What does the xai-sdk-python repo do?"}]}}

873{"custom_id": "img-1", "method": "POST", "url": "/v1/images/generations", "body": {"model": "grok-imagine-image-quality", "prompt": "A futuristic city skyline at sunset"}}873{"custom_id": "img-1", "method": "POST", "url": "/v1/images/generations", "body": {"model": "grok-imagine-image", "prompt": "A futuristic city skyline at sunset"}}

874{"custom_id": "img-edit-1", "method": "POST", "url": "/v1/images/edits", "body": {"model": "grok-imagine-image-quality", "prompt": "Add a rainbow", "image": {"url": "https://picsum.photos/800"}}}874{"custom_id": "img-edit-1", "method": "POST", "url": "/v1/images/edits", "body": {"model": "grok-imagine-image", "prompt": "Add a rainbow", "image": {"url": "https://picsum.photos/800"}}}

875{"custom_id": "vid-1", "method": "POST", "url": "/v1/videos/generations", "body": {"model": "grok-imagine-video", "prompt": "A rocket launching from Mars", "duration": 8}}875{"custom_id": "vid-1", "method": "POST", "url": "/v1/videos/generations", "body": {"model": "grok-imagine-video", "prompt": "A rocket launching from Mars", "duration": 8}}

876{"custom_id": "vid-edit-1", "method": "POST", "url": "/v1/videos/edits", "body": {"model": "grok-imagine-video", "prompt": "Make it slow motion", "video": {"url": "https://lorem.video/cat_360p_3s"}}}876{"custom_id": "vid-edit-1", "method": "POST", "url": "/v1/videos/edits", "body": {"model": "grok-imagine-video", "prompt": "Make it slow motion", "video": {"url": "https://lorem.video/cat_360p_3s"}}}

877{"custom_id": "vid-ext-1", "method": "POST", "url": "/v1/videos/extensions", "body": {"model": "grok-imagine-video", "prompt": "The camera slowly pans to reveal a sunset", "video": {"url": "https://lorem.video/cat_360p_3s"}, "duration": 6}}877{"custom_id": "vid-ext-1", "method": "POST", "url": "/v1/videos/extensions", "body": {"model": "grok-imagine-video", "prompt": "The camera slowly pans to reveal a sunset", "video": {"url": "https://lorem.video/cat_360p_3s"}, "duration": 6}}


891| `/v1/videos/edits` | [Video editing](/developers/model-capabilities/video/editing) |891| `/v1/videos/edits` | [Video editing](/developers/model-capabilities/video/editing) |

892| `/v1/videos/extensions` | [Video extension](/developers/model-capabilities/video/extension) |892| `/v1/videos/extensions` | [Video extension](/developers/model-capabilities/video/extension) |

893 893 

894Only batch-enabled models are accepted. Image and video requests currently support `grok-imagine-image` and `grok-imagine-video`; other Imagine models (including `grok-imagine-image-2.0` and `grok-imagine-video-1.5`) are rejected with "not supported for batch processing".

895 

894Upload the file via the [Files API](/developers/files), then create a batch referencing it:896Upload the file via the [Files API](/developers/files), then create a batch referencing it:

895 897 

896```pythonXAI898```pythonXAI

community.md +1 −1

Details

72import { experimental_generateImage as generateImage } from 'ai';72import { experimental_generateImage as generateImage } from 'ai';

73 73 

74const { image } = await generateImage({74const { image } = await generateImage({

75 model: xai.image('grok-imagine-image-quality'),75 model: xai.image('grok-imagine-image-2.0'),

76 prompt: 'A cat in a tree',76 prompt: 'A cat in a tree',

77});77});

78```78```

Details

300 -H "Authorization: Bearer $XAI_API_KEY" \300 -H "Authorization: Bearer $XAI_API_KEY" \

301 -H "Content-Type: application/json" \301 -H "Content-Type: application/json" \

302 -d '{302 -d '{

303 "model": "grok-imagine-image-quality",303 "model": "grok-imagine-image-2.0",

304 "prompt": "A cat on a rocket"304 "prompt": "A cat on a rocket"

305 }' | jq '.usage.cost_in_usd_ticks'305 }' | jq '.usage.cost_in_usd_ticks'

306# => 200000000 ($0.02)306# => 200000000 ($0.02)


314 314 

315# Image generation315# Image generation

316image = client.image.sample(316image = client.image.sample(

317 model="grok-imagine-image-quality",317 model="grok-imagine-image-2.0",

318 prompt="A cat on a rocket",318 prompt="A cat on a rocket",

319)319)

320print(f"Image cost: ${image.cost_usd:.4f}")320print(f"Image cost: ${image.cost_usd:.4f}")


337)337)

338 338 

339response = client.images.generate(339response = client.images.generate(

340 model="grok-imagine-image-quality",340 model="grok-imagine-image-2.0",

341 prompt="A cat on a rocket",341 prompt="A cat on a rocket",

342)342)

343 343 

Details

133 133 

134| Model | Description |134| Model | Description |

135|-------|-------------|135|-------|-------------|

136| `grok-voice-latest` | Alias for `grok-voice-think-fast-2.0`. |136| `grok-voice-latest` | Alias for `grok-voice-think-fast-2.0` |

137| `grok-voice-think-fast-2.0` | Flagship voice model |137| `grok-voice-think-fast-2.0` | Flagship voice model |

138| `grok-voice-think-fast-1.0` | Previous-generation voice model |138| `grok-voice-think-fast-1.0` | Previous-generation voice model |

139 139 

Details

136```json136```json

137{137{

138 "text": "The balance is $167,983.15.",138 "text": "The balance is $167,983.15.",

139 "language": "English",139 "language": "en",

140 "duration": 3.45,140 "duration": 3.45,

141 "words": [141 "words": [

142 { "text": "The", "start": 0.24, "end": 0.48 },142 { "text": "The", "start": 0.24, "end": 0.48 },


150| Field | Type | Description |150| Field | Type | Description |

151|-------|------|-------------|151|-------|------|-------------|

152| `text` | string | Full transcript text. |152| `text` | string | Full transcript text. |

153| `language` | string | Detected language name (e.g. `"English"`, `"French"`). |153| `language` | string | Detected language as a BCP-47 code (e.g. `en`, `es-mx`). |

154| `duration` | number | Audio duration in seconds (2 d.p.). |154| `duration` | number | Audio duration in seconds (2 d.p.). |

155| `words` | array | Word-level segments with `text`, `start`, `end`, and `speaker` (integer, only when `diarize=true`). |155| `words` | array | Word-level segments with `text`, `start`, `end`, and `speaker` (integer, only when `diarize=true`). |

156| `channels` | array | Per-channel transcripts (only when `multichannel=true`). Each entry has `index`, `text`, and `words`. |156| `channels` | array | Per-channel transcripts (only when `multichannel=true`). Each entry has `index`, `text`, and `words`. |

Details

22 22 

23response = client.image.sample(23response = client.image.sample(

24 prompt="Render this as a pencil sketch with detailed shading",24 prompt="Render this as a pencil sketch with detailed shading",

25 model="grok-imagine-image-quality",25 model="grok-imagine-image-2.0",

26 image_url=f"data:image/png;base64,{image_data}",26 image_url=f"data:image/png;base64,{image_data}",

27)27)

28 28 


35 -H "Content-Type: application/json" \35 -H "Content-Type: application/json" \

36 -H "Authorization: Bearer $XAI_API_KEY" \36 -H "Authorization: Bearer $XAI_API_KEY" \

37 -d '{37 -d '{

38 "model": "grok-imagine-image-quality",38 "model": "grok-imagine-image-2.0",

39 "prompt": "Render this as a pencil sketch with detailed shading",39 "prompt": "Render this as a pencil sketch with detailed shading",

40 "image": {40 "image": {

41 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",41 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",


54const base64Image = imageBuffer.toString("base64");54const base64Image = imageBuffer.toString("base64");

55 55 

56const { image } = await generateImage({56const { image } = await generateImage({

57 model: xai.image("grok-imagine-image-quality"),57 model: xai.image("grok-imagine-image-2.0"),

58 prompt: {58 prompt: {

59 text: "Render this as a pencil sketch with detailed shading",59 text: "Render this as a pencil sketch with detailed shading",

60 images: [`data:image/png;base64,${base64Image}`],60 images: [`data:image/png;base64,${base64Image}`],


76 76 

77## Style transfer77## Style transfer

78 78 

79The `grok-imagine-image-quality` model supports a wide range of visual styles, from ultra-realistic photography to anime, oil paintings, and pencil sketches. Transform existing images by describing the desired aesthetic in your prompt.79The `grok-imagine-image-2.0` model supports a wide range of visual styles, from ultra-realistic photography to anime, oil paintings, and pencil sketches. Transform existing images by describing the desired aesthetic in your prompt.

80 80 

81## Related81## Related

82 82 

Details

15 15 

16response = client.image.sample(16response = client.image.sample(

17 prompt="A collage of London landmarks in a stenciled street‑art style",17 prompt="A collage of London landmarks in a stenciled street‑art style",

18 model="grok-imagine-image-quality",18 model="grok-imagine-image-2.0",

19)19)

20 20 

21print(response.url)21print(response.url)


26 -H "Content-Type: application/json" \26 -H "Content-Type: application/json" \

27 -H "Authorization: Bearer $XAI_API_KEY" \27 -H "Authorization: Bearer $XAI_API_KEY" \

28 -d '{28 -d '{

29 "model": "grok-imagine-image-quality",29 "model": "grok-imagine-image-2.0",

30 "prompt": "A collage of London landmarks in a stenciled street‑art style"30 "prompt": "A collage of London landmarks in a stenciled street‑art style"

31 }'31 }'

32```32```


40)40)

41 41 

42response = client.images.generate(42response = client.images.generate(

43 model="grok-imagine-image-quality",43 model="grok-imagine-image-2.0",

44 prompt="A collage of London landmarks in a stenciled street‑art style",44 prompt="A collage of London landmarks in a stenciled street‑art style",

45)45)

46 46 


56});56});

57 57 

58const response = await client.images.generate({58const response = await client.images.generate({

59 model: "grok-imagine-image-quality",59 model: "grok-imagine-image-2.0",

60 prompt: "A collage of London landmarks in a stenciled street‑art style",60 prompt: "A collage of London landmarks in a stenciled street‑art style",

61});61});

62 62 


68import { generateImage } from "ai";68import { generateImage } from "ai";

69 69 

70const { image } = await generateImage({70const { image } = await generateImage({

71 model: xai.image("grok-imagine-image-quality"),71 model: xai.image("grok-imagine-image-2.0"),

72 prompt: "A collage of London landmarks in a stenciled street‑art style",72 prompt: "A collage of London landmarks in a stenciled street‑art style",

73});73});

74 74 


90 90 

91responses = client.image.sample_batch(91responses = client.image.sample_batch(

92 prompt="A futuristic city skyline at night",92 prompt="A futuristic city skyline at night",

93 model="grok-imagine-image-quality",93 model="grok-imagine-image-2.0",

94 n=4,94 n=4,

95)95)

96 96 


107)107)

108 108 

109response = client.images.generate(109response = client.images.generate(

110 model="grok-imagine-image-quality",110 model="grok-imagine-image-2.0",

111 prompt="A futuristic city skyline at night",111 prompt="A futuristic city skyline at night",

112 n=4,112 n=4,

113)113)


125});125});

126 126 

127const response = await client.images.generate({127const response = await client.images.generate({

128 model: "grok-imagine-image-quality",128 model: "grok-imagine-image-2.0",

129 prompt: "A futuristic city skyline at night",129 prompt: "A futuristic city skyline at night",

130 n: 4,130 n: 4,

131});131});


141import { generateImage } from "ai";141import { generateImage } from "ai";

142 142 

143const { images } = await generateImage({143const { images } = await generateImage({

144 model: xai.image("grok-imagine-image-quality"),144 model: xai.image("grok-imagine-image-2.0"),

145 prompt: "A futuristic city skyline at night",145 prompt: "A futuristic city skyline at night",

146 n: 4,146 n: 4,

147});147});


157 -H "Content-Type: application/json" \157 -H "Content-Type: application/json" \

158 -H "Authorization: Bearer $XAI_API_KEY" \158 -H "Authorization: Bearer $XAI_API_KEY" \

159 -d '{159 -d '{

160 "model": "grok-imagine-image-quality",160 "model": "grok-imagine-image-2.0",

161 "prompt": "A futuristic city skyline at night",161 "prompt": "A futuristic city skyline at night",

162 "n": 4162 "n": 4

163 }'163 }'


185 185 

186response = client.image.sample(186response = client.image.sample(

187 prompt="Mountain landscape at sunrise",187 prompt="Mountain landscape at sunrise",

188 model="grok-imagine-image-quality",188 model="grok-imagine-image-2.0",

189 aspect_ratio="16:9",189 aspect_ratio="16:9",

190)190)

191 191 


201)201)

202 202 

203response = client.images.generate(203response = client.images.generate(

204 model="grok-imagine-image-quality",204 model="grok-imagine-image-2.0",

205 prompt="Mountain landscape at sunrise",205 prompt="Mountain landscape at sunrise",

206 extra_body={"aspect_ratio": "16:9"},206 extra_body={"aspect_ratio": "16:9"},

207)207)


218});218});

219 219 

220const response = await client.images.generate({220const response = await client.images.generate({

221 model: "grok-imagine-image-quality",221 model: "grok-imagine-image-2.0",

222 prompt: "Mountain landscape at sunrise",222 prompt: "Mountain landscape at sunrise",

223 223 

224 aspect_ratio: "16:9",224 aspect_ratio: "16:9",


232import { generateImage } from "ai";232import { generateImage } from "ai";

233 233 

234const { image } = await generateImage({234const { image } = await generateImage({

235 model: xai.image("grok-imagine-image-quality"),235 model: xai.image("grok-imagine-image-2.0"),

236 prompt: "Mountain landscape at sunrise",236 prompt: "Mountain landscape at sunrise",

237 aspectRatio: "16:9",237 aspectRatio: "16:9",

238});238});


245 -H "Content-Type: application/json" \245 -H "Content-Type: application/json" \

246 -H "Authorization: Bearer $XAI_API_KEY" \246 -H "Authorization: Bearer $XAI_API_KEY" \

247 -d '{247 -d '{

248 "model": "grok-imagine-image-quality",248 "model": "grok-imagine-image-2.0",

249 "prompt": "Mountain landscape at sunrise",249 "prompt": "Mountain landscape at sunrise",

250 "aspect_ratio": "16:9"250 "aspect_ratio": "16:9"

251 }'251 }'


265 265 

266response = client.image.sample(266response = client.image.sample(

267 prompt="An astronaut performing EVA in LEO.",267 prompt="An astronaut performing EVA in LEO.",

268 model="grok-imagine-image-quality",268 model="grok-imagine-image-2.0",

269 resolution="2k"269 resolution="2k"

270)270)

271 271 


281)281)

282 282 

283response = client.images.generate(283response = client.images.generate(

284 model="grok-imagine-image-quality",284 model="grok-imagine-image-2.0",

285 prompt="An astronaut performing EVA in LEO.",285 prompt="An astronaut performing EVA in LEO.",

286 extra_body={"resolution": "2k"},286 extra_body={"resolution": "2k"},

287)287)


298});298});

299 299 

300const response = await client.images.generate({300const response = await client.images.generate({

301 model: "grok-imagine-image-quality",301 model: "grok-imagine-image-2.0",

302 prompt: "An astronaut performing EVA in LEO.",302 prompt: "An astronaut performing EVA in LEO.",

303 303 

304 resolution: "2k",304 resolution: "2k",


312import { generateImage } from "ai";312import { generateImage } from "ai";

313 313 

314const { image } = await generateImage({314const { image } = await generateImage({

315 model: xai.image("grok-imagine-image-quality"),315 model: xai.image("grok-imagine-image-2.0"),

316 prompt: "An astronaut performing EVA in LEO.",316 prompt: "An astronaut performing EVA in LEO.",

317 providerOptions: {317 providerOptions: {

318 xai: { resolution: "2k" },318 xai: { resolution: "2k" },


327-H "Content-Type: application/json" \327-H "Content-Type: application/json" \

328-H "Authorization: Bearer $XAI_API_KEY" \328-H "Authorization: Bearer $XAI_API_KEY" \

329-d '{329-d '{

330 "model": "grok-imagine-image-quality",330 "model": "grok-imagine-image-2.0",

331 "prompt": "An astronaut performing EVA in LEO.",331 "prompt": "An astronaut performing EVA in LEO.",

332 "resolution": "2k"332 "resolution": "2k"

333}'333}'


348 348 

349response = client.image.sample(349response = client.image.sample(

350 prompt="A serene Japanese garden",350 prompt="A serene Japanese garden",

351 model="grok-imagine-image-quality",351 model="grok-imagine-image-2.0",

352 image_format="base64",352 image_format="base64",

353)353)

354 354 


367)367)

368 368 

369response = client.images.generate(369response = client.images.generate(

370 model="grok-imagine-image-quality",370 model="grok-imagine-image-2.0",

371 prompt="A serene Japanese garden",371 prompt="A serene Japanese garden",

372 response_format="b64_json",372 response_format="b64_json",

373)373)


388});388});

389 389 

390const response = await client.images.generate({390const response = await client.images.generate({

391 model: "grok-imagine-image-quality",391 model: "grok-imagine-image-2.0",

392 prompt: "A serene Japanese garden",392 prompt: "A serene Japanese garden",

393 response_format: "b64_json",393 response_format: "b64_json",

394});394});


404import fs from "fs";404import fs from "fs";

405 405 

406const { image } = await generateImage({406const { image } = await generateImage({

407 model: xai.image("grok-imagine-image-quality"),407 model: xai.image("grok-imagine-image-2.0"),

408 prompt: "A serene Japanese garden",408 prompt: "A serene Japanese garden",

409});409});

410 410 


418 -H "Content-Type: application/json" \418 -H "Content-Type: application/json" \

419 -H "Authorization: Bearer $XAI_API_KEY" \419 -H "Authorization: Bearer $XAI_API_KEY" \

420 -d '{420 -d '{

421 "model": "grok-imagine-image-quality",421 "model": "grok-imagine-image-2.0",

422 "prompt": "A serene Japanese garden",422 "prompt": "A serene Japanese garden",

423 "response_format": "b64_json"423 "response_format": "b64_json"

424 }'424 }'


470 tasks = [470 tasks = [

471 client.image.sample(471 client.image.sample(

472 prompt=prompt,472 prompt=prompt,

473 model="grok-imagine-image-quality",473 model="grok-imagine-image-2.0",

474 )474 )

475 for prompt in prompts475 for prompt in prompts

476 ]476 ]

Details

19 19 

20response = client.image.sample(20response = client.image.sample(

21 prompt="A collage of London landmarks in a stenciled street‑art style",21 prompt="A collage of London landmarks in a stenciled street‑art style",

22 model="grok-imagine-image-quality",22 model="grok-imagine-image-2.0",

23)23)

24 24 

25print(response.url)25print(response.url)


30 -H "Content-Type: application/json" \30 -H "Content-Type: application/json" \

31 -H "Authorization: Bearer $XAI_API_KEY" \31 -H "Authorization: Bearer $XAI_API_KEY" \

32 -d '{32 -d '{

33 "model": "grok-imagine-image-quality",33 "model": "grok-imagine-image-2.0",

34 "prompt": "A collage of London landmarks in a stenciled street‑art style"34 "prompt": "A collage of London landmarks in a stenciled street‑art style"

35 }'35 }'

36```36```


44)44)

45 45 

46response = client.images.generate(46response = client.images.generate(

47 model="grok-imagine-image-quality",47 model="grok-imagine-image-2.0",

48 prompt="A collage of London landmarks in a stenciled street‑art style",48 prompt="A collage of London landmarks in a stenciled street‑art style",

49)49)

50 50 


56import { generateImage } from "ai";56import { generateImage } from "ai";

57 57 

58const { image } = await generateImage({58const { image } = await generateImage({

59 model: xai.image("grok-imagine-image-quality"),59 model: xai.image("grok-imagine-image-2.0"),

60 prompt: "A collage of London landmarks in a stenciled street‑art style",60 prompt: "A collage of London landmarks in a stenciled street‑art style",

61});61});

62 62 


79 79 

80response = client.image.sample(80response = client.image.sample(

81 prompt="Render this as a pencil sketch with detailed shading",81 prompt="Render this as a pencil sketch with detailed shading",

82 model="grok-imagine-image-quality",82 model="grok-imagine-image-2.0",

83 image_url=f"data:image/png;base64,{image_data}",83 image_url=f"data:image/png;base64,{image_data}",

84)84)

85 85 


92 -H "Content-Type: application/json" \92 -H "Content-Type: application/json" \

93 -H "Authorization: Bearer $XAI_API_KEY" \93 -H "Authorization: Bearer $XAI_API_KEY" \

94 -d '{94 -d '{

95 "model": "grok-imagine-image-quality",95 "model": "grok-imagine-image-2.0",

96 "prompt": "Render this as a pencil sketch with detailed shading",96 "prompt": "Render this as a pencil sketch with detailed shading",

97 "image": {97 "image": {

98 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",98 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",


111const base64Image = imageBuffer.toString("base64");111const base64Image = imageBuffer.toString("base64");

112 112 

113const { image } = await generateImage({113const { image } = await generateImage({

114 model: xai.image("grok-imagine-image-quality"),114 model: xai.image("grok-imagine-image-2.0"),

115 prompt: {115 prompt: {

116 text: "Render this as a pencil sketch with detailed shading",116 text: "Render this as a pencil sketch with detailed shading",

117 images: [`data:image/png;base64,${base64Image}`],117 images: [`data:image/png;base64,${base64Image}`],

quickstart.md +5 −5

Details

127 127 

128response = client.image.sample(128response = client.image.sample(

129 prompt="A futuristic city skyline at sunset",129 prompt="A futuristic city skyline at sunset",

130 model="grok-imagine-image-quality",130 model="grok-imagine-image-2.0",

131)131)

132 132 

133print(response.url)133print(response.url)


143)143)

144 144 

145response = client.images.generate(145response = client.images.generate(

146 model="grok-imagine-image-quality",146 model="grok-imagine-image-2.0",

147 prompt="A futuristic city skyline at sunset",147 prompt="A futuristic city skyline at sunset",

148)148)

149 149 


155import { generateImage } from 'ai';155import { generateImage } from 'ai';

156 156 

157const { image } = await generateImage({157const { image } = await generateImage({

158 model: xai.image('grok-imagine-image-quality'),158 model: xai.image('grok-imagine-image-2.0'),

159 prompt: 'A futuristic city skyline at sunset',159 prompt: 'A futuristic city skyline at sunset',

160});160});

161 161 


171});171});

172 172 

173const response = await client.images.generate({173const response = await client.images.generate({

174 model: 'grok-imagine-image-quality',174 model: 'grok-imagine-image-2.0',

175 prompt: 'A futuristic city skyline at sunset',175 prompt: 'A futuristic city skyline at sunset',

176});176});

177 177 


183 -H "Content-Type: application/json" \183 -H "Content-Type: application/json" \

184 -H "Authorization: Bearer $XAI_API_KEY" \184 -H "Authorization: Bearer $XAI_API_KEY" \

185 -d '{185 -d '{

186 "model": "grok-imagine-image-quality",186 "model": "grok-imagine-image-2.0",

187 "prompt": "A futuristic city skyline at sunset"187 "prompt": "A futuristic city skyline at sunset"

188 }'188 }'

189```189```

rate-limits.md +1 −1

Details

41| grok-build-0.1 | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |41| grok-build-0.1 | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |

42| grok-4.20-multi-agent-0309 | T0: 9, T1: 12, T2: 18, T3: 31, T4: 56 | T0: 2.5M, T1: 3.7M, T2: 6.2M, T3: 11M, T4: 21M |42| grok-4.20-multi-agent-0309 | T0: 9, T1: 12, T2: 18, T3: 31, T4: 56 | T0: 2.5M, T1: 3.7M, T2: 6.2M, T3: 11M, T4: 21M |

43| grok-imagine-image | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |43| grok-imagine-image | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |

44| grok-imagine-image-quality | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |

44| grok-imagine-image-2.0 | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |45| grok-imagine-image-2.0 | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |

45| grok-imagine-image-quality | 5 | — |

46| grok-imagine-video-1.5 | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |46| grok-imagine-video-1.5 | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |

47| grok-imagine-video | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |47| grok-imagine-video | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |

48 48 

Details

105 -H "Content-Type: application/json" \105 -H "Content-Type: application/json" \

106 -H "Authorization: Bearer $XAI_API_KEY" \106 -H "Authorization: Bearer $XAI_API_KEY" \

107 -d '{107 -d '{

108 "model": "grok-imagine-image-quality",108 "model": "grok-imagine-image-2.0",

109 "prompt": "A collage of London landmarks in a stenciled street‑art style"109 "prompt": "A collage of London landmarks in a stenciled street‑art style"

110 }'110 }'

111```111```


121)121)

122 122 

123response = client.images.generate(123response = client.images.generate(

124 model="grok-imagine-image-quality",124 model="grok-imagine-image-2.0",

125 prompt="A collage of London landmarks in a stenciled street‑art style",125 prompt="A collage of London landmarks in a stenciled street‑art style",

126)126)

127 127 


137});137});

138 138 

139const response = await client.images.generate({139const response = await client.images.generate({

140 model: "grok-imagine-image-quality",140 model: "grok-imagine-image-2.0",

141 prompt: "A collage of London landmarks in a stenciled street‑art style",141 prompt: "A collage of London landmarks in a stenciled street‑art style",

142});142});

143 143 


284 -H "Content-Type: application/json" \284 -H "Content-Type: application/json" \

285 -H "Authorization: Bearer $XAI_API_KEY" \285 -H "Authorization: Bearer $XAI_API_KEY" \

286 -d '{286 -d '{

287 "model": "grok-imagine-image-quality",287 "model": "grok-imagine-image-2.0",

288 "prompt": "Render this as a pencil sketch with detailed shading",288 "prompt": "Render this as a pencil sketch with detailed shading",

289 "image": {289 "image": {

290 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",290 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",


301 "Content-Type": "application/json",301 "Content-Type": "application/json",

302 },302 },

303 body: JSON.stringify({303 body: JSON.stringify({

304 model: "grok-imagine-image-quality",304 model: "grok-imagine-image-2.0",

305 prompt: "Render this as a pencil sketch with detailed shading",305 prompt: "Render this as a pencil sketch with detailed shading",

306 image: {306 image: {

307 url: "https://docs.x.ai/assets/api-examples/images/style-realistic.png",307 url: "https://docs.x.ai/assets/api-examples/images/style-realistic.png",


326 "Content-Type": "application/json",326 "Content-Type": "application/json",

327 },327 },

328 json={328 json={

329 "model": "grok-imagine-image-quality",329 "model": "grok-imagine-image-2.0",

330 "prompt": "Render this as a pencil sketch with detailed shading",330 "prompt": "Render this as a pencil sketch with detailed shading",

331 "image": {331 "image": {

332 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",332 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",

Details

38 38 

39* `text` (string, required) — Full transcript text. For multichannel requests, this is a merged transcript across all channels (words interleaved by timestamp).39* `text` (string, required) — Full transcript text. For multichannel requests, this is a merged transcript across all channels (words interleaved by timestamp).

40 40 

41* `language` (string, required) — Detected language code (ISO 639-1, e.g. \`en\`). Currently empty — language detection is not yet enabled.41* `language` (string, required) — Detected language as a BCP-47 code (e.g. \`en\`, \`es-mx\`).

42 42 

43* `duration` (number, required) — Audio duration in seconds (rounded to 2 decimal places).43* `duration` (number, required) — Audio duration in seconds (rounded to 2 decimal places).

44 44 


58 58 

59 * `index` (integer, required) — Zero-based channel index in the source audio.59 * `index` (integer, required) — Zero-based channel index in the source audio.

60 60 

61 * `language` (string) — Detected language code for this channel. Currently empty.61 * `language` (string) — Detected language as a BCP-47 code for this channel (e.g. \`en\`, \`es-mx\`).

62 62 

63 * `text` (string, required) — Full transcript text for this channel.63 * `text` (string, required) — Full transcript text for this channel.

64 64 


79```json79```json

80{80{

81 "text": "The balance is $167,983.15. That is $23.4 kilograms.",81 "text": "The balance is $167,983.15. That is $23.4 kilograms.",

82 "language": "",82 "language": "en",

83 "duration": 8.4,83 "duration": 8.4,

84 "words": [84 "words": [

85 {85 {

Details

956 956 

957* `text` (string, required) — Full transcript text. For multichannel requests, this is a merged transcript across all channels (words interleaved by timestamp).957* `text` (string, required) — Full transcript text. For multichannel requests, this is a merged transcript across all channels (words interleaved by timestamp).

958 958 

959* `language` (string, required) — Detected language code (ISO 639-1, e.g. \`en\`). Currently empty — language detection is not yet enabled.959* `language` (string, required) — Detected language as a BCP-47 code (e.g. \`en\`, \`es-mx\`).

960 960 

961* `duration` (number, required) — Audio duration in seconds (rounded to 2 decimal places).961* `duration` (number, required) — Audio duration in seconds (rounded to 2 decimal places).

962 962 


976 976 

977 * `index` (integer, required) — Zero-based channel index in the source audio.977 * `index` (integer, required) — Zero-based channel index in the source audio.

978 978 

979 * `language` (string) — Detected language code for this channel. Currently empty.979 * `language` (string) — Detected language as a BCP-47 code for this channel (e.g. \`en\`, \`es-mx\`).

980 980 

981 * `text` (string, required) — Full transcript text for this channel.981 * `text` (string, required) — Full transcript text for this channel.

982 982 


997```json997```json

998{998{

999 "text": "The balance is $167,983.15. That is $23.4 kilograms.",999 "text": "The balance is $167,983.15. That is $23.4 kilograms.",

1000 "language": "",1000 "language": "en",

1001 "duration": 8.4,1001 "duration": 8.4,

1002 "words": [1002 "words": [

1003 {1003 {

Details

2 2 

3# Image Generation Tool3# Image Generation Tool

4 4 

5The image generation tool lets Grok create and edit images with [Grok Imagine](/developers/model-capabilities/images/generation) as part of a conversation. It uses the latest Imagine image models (`grok-imagine-image-quality`). You hand the model the tool; it decides when to call it, writes the image prompt, picks an aspect ratio, and returns the finished image alongside its text response. Because the tool runs server-side, the model can also chain calls—generating an image and then editing it—within a single request.5The image generation tool lets Grok create and edit images with [Grok Imagine](/developers/model-capabilities/images/generation) as part of a conversation. It uses the latest Imagine image models (`grok-imagine-image-2.0`). You hand the model the tool; it decides when to call it, writes the image prompt, picks an aspect ratio, and returns the finished image alongside its text response. Because the tool runs server-side, the model can also chain calls—generating an image and then editing it—within a single request.

6 6 

7If you already have the exact prompt and want direct control over aspect ratio and resolution, call the [image generation](/developers/model-capabilities/images/generation) and [image editing](/developers/model-capabilities/images/editing) endpoints instead. Reach for the tool when image creation is one step in a larger conversational or agentic workflow.7If you already have the exact prompt and want direct control over aspect ratio and resolution, call the [image generation](/developers/model-capabilities/images/generation) and [image editing](/developers/model-capabilities/images/editing) endpoints instead. Reach for the tool when image creation is one step in a larger conversational or agentic workflow.

8 8