advanced-api-usage/batch-api.md +10 −10
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",
130130 model="grok-imagine-image", model="grok-imagine-image-2.0",
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",
138138 model="grok-imagine-image", model="grok-imagine-image-2.0",
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)
144# Video generation144# Video generation
145video_req = client.video.prepare(145video_req = client.video.prepare(
146 prompt="A product rotating on a turntable with dramatic lighting",146 prompt="A product rotating on a turntable with dramatic lighting",
147147 model="grok-imagine-video", model="grok-imagine-video-1.5",
148 batch_request_id="vid_001",148 batch_request_id="vid_001",
149)149)
150batch_requests.append(video_req)150batch_requests.append(video_req)
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",
243243 model: "grok-imagine-image", model: "grok-imagine-image-2.0",
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",
254254 model: "grok-imagine-image", model: "grok-imagine-image-2.0",
255 image: { url: "https://picsum.photos/800", type: "image_url" },255 image: { url: "https://picsum.photos/800", type: "image_url" },
256 },256 },
257 },257 },
263 batch_request: {263 batch_request: {
264 video_generation: {264 video_generation: {
265 prompt: "A product rotating on a turntable with dramatic lighting",265 prompt: "A product rotating on a turntable with dramatic lighting",
266266 model: "grok-imagine-video", model: "grok-imagine-video-1.5",
267 },267 },
268 },268 },
269});269});
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?"}]}}
873873{"custom_id": "img-1", "method": "POST", "url": "/v1/images/generations", "body": {"model": "grok-imagine-image", "prompt": "A futuristic city skyline at sunset"}}{"custom_id": "img-1", "method": "POST", "url": "/v1/images/generations", "body": {"model": "grok-imagine-image-2.0", "prompt": "A futuristic city skyline at sunset"}}
874874{"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"}}}{"custom_id": "img-edit-1", "method": "POST", "url": "/v1/images/edits", "body": {"model": "grok-imagine-image-2.0", "prompt": "Add a rainbow", "image": {"url": "https://picsum.photos/800"}}}
875875{"custom_id": "vid-1", "method": "POST", "url": "/v1/videos/generations", "body": {"model": "grok-imagine-video", "prompt": "A rocket launching from Mars", "duration": 8}}{"custom_id": "vid-1", "method": "POST", "url": "/v1/videos/generations", "body": {"model": "grok-imagine-video-1.5", "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}}
878```878```
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
894894Only 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".Only batch-enabled models are accepted. Refer to the relevant [model pages](/developers/models) for the most up-to-date information; models that are not batch-enabled are rejected with "not supported for batch processing".
895 895
896Upload 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:
897 897