Skip to content

Batch jobs

A batch job sends up to 50,000 chat requests to the provider’s batch API in one go, typically at half the price of interactive calls, with results within the completion window (24 hours by default). It is the same governed surface as chat: model access for the workspace, limits, data residency, input guardrails on every request and output guardrails on every result.

The User Portal Batch Jobs page: New Job and Refresh buttons, a status filter, and the batch processing explainer with 50% cost savings, up to 50,000 requests, and any provider.

Pick a model whose catalog entry has capabilities.supports_batch: true; any other answers 400 “Model ‘…’ does not support batch processing”.

Terminal window
curl -s http://localhost:8100/v1/proxy/batch/jobs \
-H "Content-Type: application/json" \
-H "X-Tenant-ID: default" \
-H "Authorization: Bearer $JWT" \
-H "X-Gateway-Authorization: Bearer $JWT" \
-H "X-Resource-Group: group-01M61N376V2RR6J2TV7Q7EVRET" \
-d '{
"model": "gpt-5.4-mini",
"description": "Summarise October complaints",
"requests": [
{"custom_id": "complaint-0001", "body": {"messages": [{"role": "system", "content": "Summarise in one sentence."}, {"role": "user", "content": "My card was charged twice for ..."}], "max_tokens": 200}},
{"custom_id": "complaint-0002", "body": {"messages": [{"role": "system", "content": "Summarise in one sentence."}, {"role": "user", "content": "The app logged me out during ..."}], "max_tokens": 200}}
]
}'

Response 201:

{
"id": "btj-01jz8r6m0c4v7b2n5k8h1g3f9d",
"status": "created",
"total_requests": 2,
"endpoint": "/v1/chat/completions",
"completion_window": "24h",
"created_at": "2026-10-28T17:20:44.512Z"
}
Field Example Rule
model or model_id gpt-5.4-mini One is required
requests[].custom_id complaint-0001 Your key for matching results back
requests[].body {"messages": [...], "max_tokens": 200} A chat-completions body without model
endpoint /v1/chat/completions Default /v1/chat/completions
completion_window 24h Default 24h
description Summarise October complaints Shown in the job list and the completion notification
metadata {"source": "crm-export"} Optional, free-form

At least one and at most 50,000 requests. Images go in a request body as OpenAI image_url content parts with a data: URL; the shipped portal sends other attachments as extracted text, as in chat.

  1. List the user’s jobs, newest first: GET /v1/proxy/batch/jobs?status=in_progress&page=1&page_size=20 (page_size at most 100; limit/offset also accepted).

    {
    "jobs": [
    {
    "id": "btj-01jz8r6m0c4v7b2n5k8h1g3f9d",
    "provider": "openai",
    "model": "gpt-5.4-mini",
    "endpoint": "/v1/chat/completions",
    "status": "in_progress",
    "total_requests": 2,
    "completed_requests": 1,
    "failed_requests": 0,
    "progress_percent": 50.0,
    "total_input_tokens": 212,
    "total_output_tokens": 38,
    "estimated_cost_usd": 0.0002,
    "description": "Summarise October complaints",
    "error_message": null,
    "created_at": "2026-10-28T17:20:44Z",
    "completed_at": null
    }
    ],
    "total": 1, "limit": 20, "offset": 0, "page": 1, "page_size": 20
    }
  2. Open one: GET /v1/proxy/batch/jobs/{batch_job_id} returns {"job": {...}} with the fields above plus completion_window, provider_batch_id, error_type, resource_group_name, submitted_at, cancelled_at and cancelled_by.

  3. Wait for a terminal status. The gateway submits the job within about 10 seconds and polls the provider. Statuses run created → validating → in_progress → finalizing → completed, or end in failed, expired, cancelling → cancelled. When the job finishes, the user gets a batch_job_completed or batch_job_failed notification, so you can stop polling once the list is on screen and refresh on the notification instead.

GET /v1/proxy/batch/jobs/{batch_job_id}/results?page=1&page_size=50:

{
"batch_job_id": "btj-01jz8r6m0c4v7b2n5k8h1g3f9d",
"status": "completed",
"requests": [
{
"custom_id": "complaint-0001",
"status": "completed",
"response_status_code": 200,
"response_body": {"id": "chatcmpl-...", "choices": [{"index": 0, "message": {"role": "assistant", "content": "The customer was charged twice for one purchase."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 106, "completion_tokens": 19, "total_tokens": 125}},
"input_tokens": 106,
"output_tokens": 19,
"error_message": null
},
{
"custom_id": "complaint-0002",
"status": "blocked",
"response_status_code": 403,
"response_body": {"error": {"type": "guardrail_blocked", "message": "Response withheld: output guardrail violation"}},
"input_tokens": 98,
"output_tokens": 22,
"error_message": null
}
],
"total": 2,
"page": 1,
"page_size": 50
}

Output guardrails run when results are read: a blocked item comes back with status: "blocked" and its content withheld, while the other items are unaffected. Match results to inputs by custom_id, never by position.

Terminal window
curl -s -X POST http://localhost:8100/v1/proxy/batch/jobs/btj-01jz8r6m0c4v7b2n5k8h1g3f9d/cancel \
-H "Content-Type: application/json" -H "X-Tenant-ID: default" \
-H "Authorization: Bearer $JWT" -H "X-Gateway-Authorization: Bearer $JWT" \
-d '{"reason": "Wrong prompt"}'
{
"batch_job_id": "btj-01jz8r6m0c4v7b2n5k8h1g3f9d",
"status": "cancelling",
"message": "Cancel request submitted. The proxy will cancel with the provider on its next poll."
}

A job already in a terminal status answers 409 “Batch job is already in terminal status ‘completed’”.