4 4
5The Batch API lets you process large volumes of requests asynchronously with reduced pricing and higher rate limits. For pricing details, see [Batch API Pricing](/developers/pricing#batch-api-pricing). If you need lower latency on real-time requests instead, see [Priority Processing](/developers/advanced-api-usage/priority-processing).5The Batch API lets you process large volumes of requests asynchronously with reduced pricing and higher rate limits. For pricing details, see [Batch API Pricing](/developers/pricing#batch-api-pricing). If you need lower latency on real-time requests instead, see [Priority Processing](/developers/advanced-api-usage/priority-processing).
6 6
7> [!WARNING]
8> Model support
9>
10> `grok-4.5` is not currently supported for Batch API requests and will be rejected.
11
7## What is the Batch API?12## What is the Batch API?
8 13
9When you make a standard API call to Grok, you send a request and wait for an immediate response. This approach is perfect for interactive applications like chatbots, real-time assistants, or any use case where users are waiting for a response.14When you make a standard API call to Grok, you send a request and wait for an immediate response. This approach is perfect for interactive applications like chatbots, real-time assistants, or any use case where users are waiting for a response.
111 116
112# Chat completion with tools117# Chat completion with tools
113chat = client.chat.create(118chat = client.chat.create(
114119 model="grok-4.5", model="grok-4.3",
115 batch_request_id="chat_001",120 batch_request_id="chat_001",
116 tools=[web_search(), x_search()],121 tools=[web_search(), x_search()],
117)122)
165 170
166# Remote MCP171# Remote MCP
167mcp_chat = client.chat.create(172mcp_chat = client.chat.create(
168173 model="grok-4.5", model="grok-4.3",
169 batch_request_id="mcp_001",174 batch_request_id="mcp_001",
170 tools=[mcp(server_url="https://mcp.deepwiki.com/mcp")],175 tools=[mcp(server_url="https://mcp.deepwiki.com/mcp")],
171)176)
191 {"role": "system", "content": "Classify the sentiment as positive, negative, or neutral."},196 {"role": "system", "content": "Classify the sentiment as positive, negative, or neutral."},
192 {"role": "user", "content": "The product exceeded my expectations!"}197 {"role": "user", "content": "The product exceeded my expectations!"}
193 ],198 ],
194199 "model": "grok-4.5" "model": "grok-4.3"
195 }200 }
196 }201 }
197 },202 },
203 {"role": "system", "content": "Classify the sentiment as positive, negative, or neutral."},208 {"role": "system", "content": "Classify the sentiment as positive, negative, or neutral."},
204 {"role": "user", "content": "Shipping took way too long."}209 {"role": "user", "content": "Shipping took way too long."}
205 ],210 ],
206211 "model": "grok-4.5" "model": "grok-4.3"
207 }212 }
208 }213 }
209 }214 }
219 batch_request_id: "chat_001",224 batch_request_id: "chat_001",
220 batch_request: {225 batch_request: {
221 responses: {226 responses: {
222227 model: "grok-4.5", model: "grok-4.3",
223 tools: [{ type: "web_search" }, { type: "x_search" }],228 tools: [{ type: "web_search" }, { type: "x_search" }],
224 input: [229 input: [
225 { role: "system", content: "Analyze market sentiment from recent news and posts." },230 { role: "system", content: "Analyze market sentiment from recent news and posts." },
293 batch_request_id: "mcp_001",298 batch_request_id: "mcp_001",
294 batch_request: {299 batch_request: {
295 responses: {300 responses: {
296301 model: "grok-4.5", model: "grok-4.3",
297 tools: [{ type: "mcp", server_label: "deepwiki", server_url: "https://mcp.deepwiki.com/mcp" }],302 tools: [{ type: "mcp", server_label: "deepwiki", server_url: "https://mcp.deepwiki.com/mcp" }],
298 input: [{ role: "user", content: "What does the xai-sdk-python repo do?" }],303 input: [{ role: "user", content: "What does the xai-sdk-python repo do?" }],
299 },304 },
710batch_requests = []715batch_requests = []
711for item in feedback_data:716for item in feedback_data:
712 chat = client.chat.create(717 chat = client.chat.create(
713718 model="grok-4.5", model="grok-4.3",
714 batch_request_id=item["id"],719 batch_request_id=item["id"],
715 )720 )
716 chat.append(system(721 chat.append(system(
793 batch_request_id: item.id,798 batch_request_id: item.id,
794 batch_request: {799 batch_request: {
795 chat_get_completion: {800 chat_get_completion: {
796801 model: "grok-4.5", model: "grok-4.3",
797 messages: [802 messages: [
798 {803 {
799 role: "system",804 role: "system",