API / get-batch-api-results

Get Batch API results

Results are available as soon as individual requests finish. You do not have to wait for the whole batch. Poll status with GET /v1/batches/{batch_id} until state.num_pending is 0, then page results. Create / add path: Run a Batch API job. JSONL upload: Add Batch API requests from a JSONL file.

Poll status

curl "https://api.x.ai/v1/batches/$BATCH_ID" \
  -H "Authorization: Bearer $XAI_API_KEY"

Counters on state: num_requests, num_pending, num_success, num_error, num_cancelled. Per-request metadata: GET /v1/batches/{batch_id}/requests (pending, succeeded, failed, cancelled).

Page results

curl "https://api.x.ai/v1/batches/$BATCH_ID/results?limit=100" \
  -H "Authorization: Bearer $XAI_API_KEY"
# next page: &pagination_token=...
import os
from xai_sdk import Client

client = Client(api_key=os.getenv("XAI_API_KEY"))
all_ok, all_fail = [], []
token = None
while True:
    page = client.batch.list_batch_results(
        batch_id=batch.batch_id, limit=100, pagination_token=token
    )
    all_ok.extend(page.succeeded)
    all_fail.extend(page.failed)
    if page.pagination_token is None:
        break
    token = page.pagination_token

for result in all_ok:
    rid = result.batch_request_id
    resp = result.proto.response
    if resp.HasField("completion_response"):
        print(rid, result.response.content[:120])
    elif resp.HasField("image_response"):
        print(rid, result.image_response.url)
    elif resp.HasField("video_response"):
        print(rid, result.video_response.url)
for result in all_fail:
    print("FAIL", result.batch_request_id, result.error_message)

Match rows with the batch_request_id (or JSONL custom_id) you set when adding requests.

Cost

Batch cost_breakdown.total_cost_usd_ticks is in ticks (1e-10 USD). Divide by 1e10 for dollars. Per-result chat usage may also expose cost_in_usd_ticks. Pricing table: docs.x.ai/developers/pricing.

Pitfalls

  • Image and video result URLs expire after 1 hour. Download promptly.
  • pagination_token null means the last page.
  • Completion within 24 hours is best effort only.
  • Console API credits are a separate bill from SuperGrok's weekly pool on grok.com.