gRPC API
Batch Management
xai_api.BatchMgmt
An API service for processing batch requests asynchronously at lower priority than chat service.
Methods: xai_api.BatchMgmt
CreateBatchunaryCreates a new batch.
GetBatchunaryRetrieves an individual batch.
ListBatchesunaryRetrieves a list of all batches owned by the team.
CancelBatchunaryStops processing of all outstanding requests in the batch.
AddBatchRequestsunaryAdds requests to a batch.
ListBatchRequestMetadataunaryLists metadata about individual requests in a batch.
ListBatchResultsunaryLists processing results of a batch.
GetBatchRequestResultunaryRetrieves an individual request in a batch.
Create a batch and add requests
import os
import xai_sdk
from xai_sdk.chat import user
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
# Create a batch
batch = client.batch.create("my_batch")
print(f"Batch ID: {batch.batch_id}")
# Add chat requests to the batch
chats = []
for country in ["UK", "USA", "Egypt"]:
chat = client.chat.create(
model="grok-4.7",
batch_request_id=f"capital_{country.lower()}",
)
chat.append(user(f"What is the capital of {country}?"))
chats.append(chat)
client.batch.add(batch.batch_id, chats)
List batches and get results
import os
import xai_sdk
client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))
# List all batches
batches = client.batch.list(limit=10)
for b in batches.batches:
print(f"{b.name}: {b.batch_id}")
# Get results for a specific batch
results = client.batch.list_batch_results("BATCH_ID")
for r in results.results:
print(f"{r.batch_request_id}: {r.response}")
Last updated:September 2, 2026