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-quality", 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",
138138 model="grok-imagine-image-quality", 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",
243243 model: "grok-imagine-image-quality", 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",
254254 model: "grok-imagine-image-quality", 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?"}]}}
873873{"custom_id": "img-1", "method": "POST", "url": "/v1/images/generations", "body": {"model": "grok-imagine-image-quality", "prompt": "A futuristic city skyline at sunset"}}{"custom_id": "img-1", "method": "POST", "url": "/v1/images/generations", "body": {"model": "grok-imagine-image", "prompt": "A futuristic city skyline at sunset"}}
874874{"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"}}}{"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