Batch Processing
Run many chat completion requests asynchronously at a lower price: upload a JSONL file, create a batch, and download the results within 24 hours.
Batch processing runs many Chat Completions requests asynchronously. You write the requests to a JSONL file, upload it, create a batch from it, and download the results when the batch ends, within 24 hours. A request in a batch costs less than the same request sent on its own: see Models and prices.
The API follows OpenAI's Batch API. If you use the OpenAI SDK, change the base URL and the API key: files.create, files.content and every batches.* call work as they are, for input files up to 50 MiB.
Upload a file
POST /v1/files
List files
GET /v1/files
Get a file
GET /v1/files/{file_id}
Download a file's content
GET /v1/files/{file_id}/content
Delete a file
DELETE /v1/files/{file_id}
Create a batch
POST /v1/batches
Get a batch
GET /v1/batches/{batch_id}
List batches
GET /v1/batches
Cancel a batch
POST /v1/batches/{batch_id}/cancel
How a batch works
Write the file. Put one request per line in a JSONL file. Every line uses the same model and sets
max_tokens.Upload it with
purpose=batch. You get a file ID.Create the batch with that file ID. The answer comes at once, with the status
validating.Validation. Every line is checked, the worst-case cost of the batch is reserved on your balance, and the batch is sent to the model's provider. The status becomes
in_progress.The batch ends. The results are collected (
finalizing), and the batch ends ascompleted,expired,cancelledorfailed. You are charged once, for what ran, and the rest of the reservation is released.Read the results from the output file and the error file. Poll the batch, or pass a
webhook_urlto be notified when it ends.
Models and prices
A batch price is set per model. For most providers it is 50% of the provider's list price; for xAI it is 20% below the standard price. A batch runs at the model's own provider, with no fallback to another provider.
Anthropic
Claude Opus 4.5, 4.6, 4.7, 4.8, 5 and 5.5; Claude Sonnet 4.5, 4.6, 5 and 5.5; Claude Haiku 4.5 and 5.5; Claude Fable 5, 5.1 and 5.2
50% of list price
OpenAI
GPT-6 Astra, GPT-6 Sol, GPT-6 Luna, GPT-6.1 Sol, GPT-6.1 Terra, GPT-5.6 Sol, Terra and Luna, GPT-5.5, GPT-5.4, GPT-5.2, GPT-5.1, GPT-5, GPT-5 mini, GPT-5 nano, GPT-4.1, GPT-4.1 mini, GPT-4o, GPT-4o mini, o3
50% of list price
Gemini 2.5 Pro, Gemini 3.1 Pro Preview, Gemini 3 Flash Preview, Gemini 3.5 Flash, Gemini 3.7 Flash, Gemini 3.8 Flash, Gemini 3.1 Flash-Lite, Gemini 3.5 Flash-Lite
50% of list price
Alibaba Cloud
Qwen Max, Qwen3.8 Max, Qwen3.7 Plus, Qwen Plus
50% of list price
Mistral
Mistral Large (mistral-large-4-0)
50% of list price
xAI
Grok 4.3, Grok 4.5, Grok 4.6, Grok 4.7, Grok 4.20 (0309) reasoning and non-reasoning
20% below standard
The exact batch price of a model is in the model list: with ?include=pricing, a model that can run in a batch carries a pricing.batch block with its units and thresholds. A model without pricing.batch cannot run in a batch: creating one returns 400 model_not_supported_for_batch.
Use the model id exactly as the model list shows it with pricing.batch, for example openai/gpt-5-5 or gpt-5.5-2026-04-23. A few short aliases, such as gpt-5.5 and o3, are served by another provider and are refused in a batch with the same error.
Prepare the input file
The input file is JSONL: one JSON object per line. Each line is one Chat Completions request:
custom_id
Your ID of the request: 1 to 512 characters, unique in the file. Any text works, and you get it back unchanged with the result. All custom_ids of a file together are at most 16 MiB
method
POST
url
/v1/chat/completions
body
The Chat Completions request body, with the rules below
Rules for body:
One model per file. Every line names the same model ID, spelled the same way.
max_tokensormax_completion_tokensis required on every line. The reservation for the batch is priced from it (see Billing), so a line without one fails withmax_tokens_required.Text and function tools only.
messagestakes the rolessystem,developer,user,assistantandtool, withcontentas a string or an array oftextparts, plusname,tool_callsandtool_call_id. Images, audio, files and server tools (such as web search) are not supported.Supported fields:
model,messages,max_tokens,max_completion_tokens,temperature,top_p,stop,seed,frequency_penalty,presence_penalty,response_format(text,json_object,json_schema),tools(typefunction),tool_choice,parallel_tool_callsanduser.streammay only befalseandnonly1.cache_controlis accepted on messages, text parts and tools. Any other field fails the line, and the error names the field.Size. A line is at most 1 MiB. The file is at most 200 MiB, and at most the provider's own limit (see Limits).
Upload the file
The JSONL file with one request per line, up to 50 MiB. Use a .jsonl file name or a JSONL MIME type. For a larger file (up to 200 MiB), use the Uploads flow described on this page.
Only batch can be uploaded.
OK
A file of the Batch API.
File ID.
file-3f2b8c1e-7a4d-4e0b-9c55-1d2e3f4a5b6cAlways file.
Size of the file in bytes.
1874Unix time (seconds) when the file was created.
1794585600Unix time (seconds) when the file is deleted. Result files (batch_output) expire 30 days after they are created; null when the file has no expiry.
File name.
requests.jsonlbatch for an input file you uploaded, batch_output for an output or error file of a batch.
Deprecated OpenAI field. Always processed.
Deprecated OpenAI field. Always null.
OK
{
"id": "file-3f2b8c1e-7a4d-4e0b-9c55-1d2e3f4a5b6c",
"object": "file",
"bytes": 1874,
"created_at": 1794585600,
"expires_at": null,
"filename": "requests.jsonl",
"purpose": "batch",
"status": "processed",
"status_details": null
}Files over 50 MiB
POST /v1/files takes a file of up to 50 MiB in one request. For a file of up to 200 MiB, upload it in parts. This flow differs from OpenAI's: the bytes of each part go to a signed link, not in the body of the request, so the OpenAI SDK's uploads.* helpers do not work with it. Use plain HTTP:
POST /v1/uploadswithfilename,purpose: "batch",bytes(the total size) and, optionally,mime_type. The upload stays open for 1 hour.For each part,
POST /v1/uploads/{upload_id}/partswith{"part_number": n}(from 1). The answer carries aurl.PUTthe part's bytes to thaturland keep theETagheader of the answer. Every part except the last must be at least 5 MiB.POST /v1/uploads/{upload_id}/completewith{"parts": [{"part_number": 1, "etag": "..."}, ...]}. The answer'sfileis the uploaded file; use itsidasinput_file_id.
POST /v1/uploads/{upload_id}/cancel abandons an upload. You can have up to 20 uploads open at a time.
Create a batch
Optional. A repeat of the same request with the same key returns the batch the first one created instead of a new one. A different request with a key you already used returns 409 idempotency_key_reused.
ID of a file uploaded with purpose=batch.
<REPLACE_WITH_YOUR_FILE_ID>The endpoint every line calls. Only /v1/chat/completions is supported.
The time the batch has to finish. Only 24h is supported.
Optional. A public https address (port 443 or 8443, a host name rather than an IP address) that receives a signed batch.completed, batch.failed, batch.cancelled or batch.expired event when the batch ends. Your account needs a webhook signing secret first. See the Webhooks page.
OK
A batch.
Batch ID. Starts with batch_.
batch_V1StGXR8Z5jdHi6BmyT8kThe endpoint every line calls.
/v1/chat/completionsThe model of the batch, as the lines name it.
anthropic/claude-opus-5-5ID of the input file.
Always 24h.
24hCurrent status of the batch.
ID of the file with the successful results, once the batch has ended.
ID of the file with the lines that failed, once the batch has ended.
Unix time (seconds) when the batch was created.
1794585600Unix time (seconds) when the provider accepted the batch.
Unix time (seconds) when the 24-hour window ends.
1794672000Unix time (seconds) when the results started being collected.
Unix time (seconds) when the batch completed.
Unix time (seconds) when the batch failed.
Unix time (seconds) when the batch expired.
Unix time (seconds) when the cancellation started.
Unix time (seconds) when the batch was cancelled.
The request is invalid, for example unsupported_endpoint, invalid_file_purpose, empty_file, model_not_supported_for_batch or an invalid first line.
api_key_required: batches are created with an API key.
file_not_found: no such file for this API key.
idempotency_key_reused.
batch_limit_exceeded: too many batches in progress. See Retry-After.
{
"id": "batch_V1StGXR8Z5jdHi6BmyT8k",
"object": "batch",
"endpoint": "/v1/chat/completions",
"model": "anthropic/claude-opus-5-5",
"errors": {
"object": "list",
"data": [
{
"code": "text",
"message": "text",
"param": "text",
"line": 1
}
]
},
"input_file_id": "text",
"completion_window": "24h",
"status": "validating",
"output_file_id": "text",
"error_file_id": "text",
"created_at": 1794585600,
"in_progress_at": 1,
"expires_at": 1794672000,
"finalizing_at": 1,
"completed_at": 1,
"failed_at": 1,
"expired_at": 1,
"cancelling_at": 1,
"cancelled_at": 1,
"request_counts": {
"total": 1,
"completed": 1,
"failed": 1
},
"usage": {
"input_tokens": 1,
"input_tokens_details": {
"cached_tokens": 1
},
"output_tokens": 1,
"output_tokens_details": {
"reasoning_tokens": 1
},
"total_tokens": 1
},
"metadata": {
"ANY_ADDITIONAL_PROPERTY": "text"
}
}The answer comes at once, before the file is read to its end: the batch starts in validating. Problems found later, in the file or with the reservation, end the batch as failed and are listed in its errors.
Batches are created with an API key. To make a retry safe, send an Idempotency-Key header (up to 255 characters): the same request with the same key returns the batch the first request created, and a different request with a key you already used returns 409 idempotency_key_reused.
Statuses
validating
The file is being checked, the cost reserved and the batch sent to the provider
in_progress
The provider is running the batch. request_counts is updated while it runs
finalizing
The provider has finished, and the results are being collected and priced
completed
The batch ran to its end. This includes a batch whose lines all failed one by one: read request_counts and the error file
failed
The batch itself was refused: by the file check, by the reservation, or by the provider. errors says why
expired
The 24-hour window ended before every line ran. Lines that finished are in the output file and are charged; the others are in the error file with batch_expired
cancelling
A cancel was accepted and is in progress
cancelled
The batch was cancelled. Lines that finished before the cancel are in the output file and are charged
completed, failed, expired and cancelled are final. request_counts.failed counts lines that failed, expired or were cancelled.
Check a batch
The ID of the batch (starts with batch_).
<REPLACE_WITH_YOUR_BATCH_ID>OK
A batch.
Batch ID. Starts with batch_.
batch_V1StGXR8Z5jdHi6BmyT8kThe endpoint every line calls.
/v1/chat/completionsThe model of the batch, as the lines name it.
anthropic/claude-opus-5-5ID of the input file.
Always 24h.
24hCurrent status of the batch.
ID of the file with the successful results, once the batch has ended.
ID of the file with the lines that failed, once the batch has ended.
Unix time (seconds) when the batch was created.
1794585600Unix time (seconds) when the provider accepted the batch.
Unix time (seconds) when the 24-hour window ends.
1794672000Unix time (seconds) when the results started being collected.
Unix time (seconds) when the batch completed.
Unix time (seconds) when the batch failed.
Unix time (seconds) when the batch expired.
Unix time (seconds) when the cancellation started.
Unix time (seconds) when the batch was cancelled.
batch_not_found.
{
"id": "batch_V1StGXR8Z5jdHi6BmyT8k",
"object": "batch",
"endpoint": "/v1/chat/completions",
"model": "anthropic/claude-opus-5-5",
"errors": {
"object": "list",
"data": [
{
"code": "text",
"message": "text",
"param": "text",
"line": 1
}
]
},
"input_file_id": "text",
"completion_window": "24h",
"status": "validating",
"output_file_id": "text",
"error_file_id": "text",
"created_at": 1794585600,
"in_progress_at": 1,
"expires_at": 1794672000,
"finalizing_at": 1,
"completed_at": 1,
"failed_at": 1,
"expired_at": 1,
"cancelling_at": 1,
"cancelled_at": 1,
"request_counts": {
"total": 1,
"completed": 1,
"failed": 1
},
"usage": {
"input_tokens": 1,
"input_tokens_details": {
"cached_tokens": 1
},
"output_tokens": 1,
"output_tokens_details": {
"reasoning_tokens": 1
},
"total_tokens": 1
},
"metadata": {
"ANY_ADDITIONAL_PROPERTY": "text"
}
}Read the results
When a batch ends, output_file_id points to the results of the lines that succeeded, and error_file_id to the lines that failed. Either may be null when it has no lines. Download a file with GET /v1/files/{file_id}/content.
The ID of the file.
<REPLACE_WITH_YOUR_FILE_ID>A redirect to a signed link that serves the file's bytes for 5 minutes. HTTP clients and the OpenAI SDKs follow it on their own; the file itself is JSONL.
A redirect to a signed link that serves the file's bytes for 5 minutes. HTTP clients and the OpenAI SDKs follow it on their own; the file itself is JSONL.
No content
The endpoint answers with a 302 redirect to a signed link that works for 5 minutes. Most HTTP clients, and the OpenAI SDK's files.content, follow it on their own. Request the content again when you need a new link.
Each line of the output file is the result of one request, with your custom_id. The order of the lines is not guaranteed: match results to requests by custom_id. response.body is a Chat Completions response.
Each line of the error file has response: null and an error:
error.code
Meaning
batch_expired
The 24-hour window ended before the line ran
batch_cancelled
The batch was cancelled before the line ran
batch_line_missing
The provider returned no result for the line
batch_result_too_large
The results of the batch passed the 4 GiB limit, so this line was not stored. Split the file
Any other code
The provider refused or failed this line. error.status carries the HTTP status when the provider gave one
Lines in the error file are not charged. Output and error files are deleted 30 days after they are created: see the file's expires_at.
List batches
Number of batches per page.
20The last_id of the previous page.
Your batches, newest first.
ID of the first batch on this page.
ID of the last batch on this page. Pass it as after to get the next page.
Whether there are more batches after this page.
Your batches, newest first.
{
"object": "list",
"data": [
{
"id": "batch_V1StGXR8Z5jdHi6BmyT8k",
"object": "batch",
"endpoint": "/v1/chat/completions",
"model": "anthropic/claude-opus-5-5",
"errors": {
"object": "list",
"data": [
{
"code": "text",
"message": "text",
"param": "text",
"line": 1
}
]
},
"input_file_id": "text",
"completion_window": "24h",
"status": "validating",
"output_file_id": "text",
"error_file_id": "text",
"created_at": 1794585600,
"in_progress_at": 1,
"expires_at": 1794672000,
"finalizing_at": 1,
"completed_at": 1,
"failed_at": 1,
"expired_at": 1,
"cancelling_at": 1,
"cancelled_at": 1,
"request_counts": {
"total": 1,
"completed": 1,
"failed": 1
},
"usage": {
"input_tokens": 1,
"input_tokens_details": {
"cached_tokens": 1
},
"output_tokens": 1,
"output_tokens_details": {
"reasoning_tokens": 1
},
"total_tokens": 1
},
"metadata": {
"ANY_ADDITIONAL_PROPERTY": "text"
}
}
],
"first_id": "text",
"last_id": "text",
"has_more": true
}Returns your batches of the file-based format, newest first. Pass the last_id of a page as after to get the next one. A batch of the inline format is not listed; read it by its ID.
Cancel a batch
The ID of the batch (starts with batch_).
<REPLACE_WITH_YOUR_BATCH_ID>OK
A batch.
Batch ID. Starts with batch_.
batch_V1StGXR8Z5jdHi6BmyT8kThe endpoint every line calls.
/v1/chat/completionsThe model of the batch, as the lines name it.
anthropic/claude-opus-5-5ID of the input file.
Always 24h.
24hCurrent status of the batch.
ID of the file with the successful results, once the batch has ended.
ID of the file with the lines that failed, once the batch has ended.
Unix time (seconds) when the batch was created.
1794585600Unix time (seconds) when the provider accepted the batch.
Unix time (seconds) when the 24-hour window ends.
1794672000Unix time (seconds) when the results started being collected.
Unix time (seconds) when the batch completed.
Unix time (seconds) when the batch failed.
Unix time (seconds) when the batch expired.
Unix time (seconds) when the cancellation started.
Unix time (seconds) when the batch was cancelled.
batch_not_found.
cancel_failed: the provider did not accept the cancel. The batch keeps running; try again.
{
"id": "batch_V1StGXR8Z5jdHi6BmyT8k",
"object": "batch",
"endpoint": "/v1/chat/completions",
"model": "anthropic/claude-opus-5-5",
"errors": {
"object": "list",
"data": [
{
"code": "text",
"message": "text",
"param": "text",
"line": 1
}
]
},
"input_file_id": "text",
"completion_window": "24h",
"status": "validating",
"output_file_id": "text",
"error_file_id": "text",
"created_at": 1794585600,
"in_progress_at": 1,
"expires_at": 1794672000,
"finalizing_at": 1,
"completed_at": 1,
"failed_at": 1,
"expired_at": 1,
"cancelling_at": 1,
"cancelled_at": 1,
"request_counts": {
"total": 1,
"completed": 1,
"failed": 1
},
"usage": {
"input_tokens": 1,
"input_tokens_details": {
"cached_tokens": 1
},
"output_tokens": 1,
"output_tokens_details": {
"reasoning_tokens": 1
},
"total_tokens": 1
},
"metadata": {
"ANY_ADDITIONAL_PROPERTY": "text"
}
}Before the provider has the batch (validating)
The cancel is recorded, and the batch ends as cancelled without running. Nothing is charged, and any reservation is released
While the provider runs it (in_progress)
The provider is asked to stop, and the answer has the status cancelling. Lines that finished before the cancel are returned and charged
The provider refuses the cancel
502 cancel_failed. The batch keeps running and its reservation stays. Try again
The batch is already finishing or has ended
The answer is the batch as it is. Nothing changes: a batch whose results are already being collected ends as what it is
Get notified when a batch ends
Instead of polling, pass webhook_url when you create the batch. When the batch ends, a signed event is sent to that address: batch.completed, batch.failed, batch.cancelled or batch.expired.
The address must be a public
httpsURL on port 443 or 8443, with a host name rather than an IP address.Your account needs a webhook signing secret first. Without one, the request returns
400 webhook_secret_required.The event carries the batch's
status,request_counts,output_file_id,error_file_idand up to 10errors. Download the files as described above.
How to create the secret, verify the signature and handle retries: Webhooks.
Billing
Reservation. After the file is checked, the worst-case cost of the whole batch is reserved on your balance, before anything is sent to the provider. For each line the worst case is:
the input, counted as one token per 2 bytes of the line (plus 600 tokens for a line with
tools), at the batch input price;plus
max_tokens(ormax_completion_tokens) at the batch output price;on Gemini models, plus the reasoning budget sent with the line: half of its
max_tokens;on xAI reasoning models (Grok 4.3, 4.5, 4.6, 4.7 and 4.20 reasoning), plus three times its
max_tokensat the reasoning price, because their reasoning is not bounded bymax_tokens.
The reservation is held until the batch ends. A lower max_tokens lowers it.
Your balance stays usable. A batch whose reservation would take more than 80% of your available balance fails with batch_hold_over_balance_share, so that your other requests are not refused while it runs. Lower max_tokens, split the file, or top up.
Charge. You are charged once, when the batch ends, for the usage the provider reported on the lines that succeeded, at the batch price. A succeeded line with no reported usage is priced from an estimate. Failed, expired and cancelled lines are not charged. The rest of the reservation is released.
Refusals. If the reservation is refused, the batch ends as failed and nothing is charged. The error says how much the batch needed:
errors[].code
Meaning
insufficient_credits
Your balance does not cover the worst case of the batch
batch_hold_over_balance_share
The worst case would take more than 80% of your available balance
key_quota_exceeded
The API key's spend limit does not cover the worst case
tenant_spend_limit
The organization or workspace budget does not cover the worst case
account_spend_limit
The spend limit of a new account does not cover the worst case
The batch object shows token usage, not amounts of money.
Files
Who sees a file. A file belongs to the user who uploaded it, in the workspace of the API key used. A batch belongs to the user and workspace that created it, and so do its output and error files. Any other user, including another member of the same organization, and a key of another workspace get
404.Purposes. You can upload only
purpose=batch. Output and error files have the purposebatch_output. The Files API lists and serves only these two purposes.Retention. Output and error files are deleted 30 days after they are created.
Deleting an input file while a batch still uses it returns
409. The batch reads the file again while it runs and lets go of it when it ends.
List files
Only files of this purpose. Without it, both purposes are listed.
Number of files per page.
20The last_id of the previous page.
Newest first. asc is not supported.
descPossible values: OK
ID of the first file on this page.
ID of the last file on this page. Pass it as after to get the next page.
Whether there are more files after this page.
OK
{
"object": "list",
"data": [
{
"id": "file-3f2b8c1e-7a4d-4e0b-9c55-1d2e3f4a5b6c",
"object": "file",
"bytes": 1874,
"created_at": 1794585600,
"expires_at": null,
"filename": "requests.jsonl",
"purpose": "batch",
"status": "processed",
"status_details": null
}
],
"first_id": "text",
"last_id": "text",
"has_more": true
}Get a file
The ID of the file.
<REPLACE_WITH_YOUR_FILE_ID>OK
A file of the Batch API.
File ID.
file-3f2b8c1e-7a4d-4e0b-9c55-1d2e3f4a5b6cAlways file.
Size of the file in bytes.
1874Unix time (seconds) when the file was created.
1794585600Unix time (seconds) when the file is deleted. Result files (batch_output) expire 30 days after they are created; null when the file has no expiry.
File name.
requests.jsonlbatch for an input file you uploaded, batch_output for an output or error file of a batch.
Deprecated OpenAI field. Always processed.
Deprecated OpenAI field. Always null.
OK
{
"id": "file-3f2b8c1e-7a4d-4e0b-9c55-1d2e3f4a5b6c",
"object": "file",
"bytes": 1874,
"created_at": 1794585600,
"expires_at": null,
"filename": "requests.jsonl",
"purpose": "batch",
"status": "processed",
"status_details": null
}Delete a file
The ID of the file.
<REPLACE_WITH_YOUR_FILE_ID>The file is deleted.
ID of the deleted file.
The file is the input of a batch that has not ended yet. Delete it after the batch ends.
{
"id": "text",
"object": "file",
"deleted": true
}Limits
endpoint
/v1/chat/completions only
completion_window
24h only
Input file, POST /v1/files
50 MiB. A larger request returns 413
Input file, uploaded in parts
200 MiB
Uploads open at a time
20 per user. An upload expires 1 hour after it is created
Line
1 MiB
custom_id
512 characters; 16 MiB for all custom_ids of a file
metadata
16 keys; keys up to 64 characters, values up to 512
Batches in progress
3 per account (per organization, or per user without one). Creating a fourth returns 429 batch_limit_exceeded with Retry-After
Lines in progress
100,000 per account across its batches in progress. A batch that would go over it fails during validation with batch_limit_exceeded
Provider capacity
Shared by all accounts. When a provider's capacity is full, creating a batch returns 429 batch_limit_exceeded (Retry-After: 300), or the batch fails during validation
Validation
A batch still validating after 1 hour fails with validation_timeout
Results of one batch
4 GiB for the output and error files together. Lines past it fail with batch_result_too_large and are not charged
Each provider also limits the size of one batch:
Anthropic
100,000
256 MB
OpenAI
50,000
200 MB
100,000
1 GB
Alibaba Cloud
50,000
500 MB
Mistral
100,000
512 MB
xAI
50,000
50 MB
The 200 MiB limit on input files applies first. A file over a provider's limit fails with too_many_requests or file_too_large.
Errors
A request that is refused returns an OpenAI-style error body:
Status
code
Meaning
400
unsupported_endpoint
endpoint is not /v1/chat/completions
400
unsupported_completion_window
completion_window is not 24h
400
invalid_metadata
metadata breaks its limits
400
invalid_idempotency_key
Idempotency-Key is longer than 255 characters
400
invalid_file_purpose
The file was not uploaded with purpose=batch
400
empty_file
The file has no requests
400
invalid_json, invalid_line, line_too_large, max_tokens_required
The first line of the file is invalid. The message starts with Line 1:
400
model_not_supported_for_batch
The model has no batch price
400
model_not_allowed
The API key's model list does not include the model
400
invalid_limit, invalid_after
Invalid paging parameters of GET /v1/batches
403
api_key_required
Batches are created with an API key
404
file_not_found
No such file for this API key and workspace
404
batch_not_found
No such batch for this API key and workspace
409
idempotency_key_reused
The Idempotency-Key was used for a different request
429
batch_limit_exceeded
Too many batches in progress, or the provider's capacity is full. Wait for Retry-After seconds
502
cancel_failed
The provider did not accept the cancel. The batch keeps running
The first line is checked when the batch is created; the rest of the file during validation. Problems found during validation end the batch as failed, and the batch's errors.data lists them with line and param:
errors[].code
Meaning
invalid_json
The line is not valid JSON
invalid_line
The line breaks the line format, or uses a field that is not supported (named in the message)
line_too_large
The line is over 1 MiB
max_tokens_required
The line sets neither max_tokens nor max_completion_tokens
duplicate_custom_id
The custom_id is used more than once
mixed_models
The line names a different model than the first line
custom_ids_too_long
The custom_ids of the file add up to more than 16 MiB
too_many_requests, file_too_large
The file is over the provider's limit
batch_limit_exceeded
The batch would take your account or the provider over its lines in progress
validation_timeout
The file could not be checked within 1 hour
The reservation errors are listed under Billing. A batch that the provider itself refuses ends as failed with the provider's error.
Legacy inline format
The older format sends the requests in the body of POST /v1/batches, as a requests array in Anthropic's Message Batches shape. It works only with Claude models and keeps working as before. Its batches are not listed by GET /v1/batches, and it has no webhooks. For new integrations, use the file-based flow above. If a retirement date is announced, the answers of the inline format will carry a Deprecation header.
Create a message batch
POST /v1/batches with requests
Get status or results of a batch
GET /v1/batches?batch_id={batch_id} or GET /v1/batches/{batch_id}
Cancel a batch
POST /v1/batches/cancel/{batch_id} or POST /v1/batches/{batch_id}/cancel
Create a message batch
The legacy inline format (Anthropic models only). For new integrations, upload a JSONL file and create the batch with input_file_id instead.
Unique identifier of the batch.
kgTRCVoAz4GwrHWIOFZjgObject type.
message_batchCurrent processing status of the batch.
in_progressTimestamp when the batch finished processing, if completed.
Timestamp when the batch was created.
2026-05-04T17:27:37.468424+00:00Timestamp when the batch will expire if not completed.
2026-05-05T17:27:37.468424+00:00Timestamp when the batch was archived, if applicable.
Timestamp when cancellation was initiated, if applicable.
URL to download batch results once processing is complete.
{
"id": "kgTRCVoAz4GwrHWIOFZjg",
"type": "message_batch",
"processing_status": "in_progress",
"request_counts": {
"processing": 3,
"succeeded": 0,
"errored": 0,
"canceled": 0,
"expired": 0
},
"ended_at": "2026-01-01T00:00:00.000Z",
"created_at": "2026-05-04T17:27:37.468424+00:00",
"expires_at": "2026-05-05T17:27:37.468424+00:00",
"archived_at": "2026-01-01T00:00:00.000Z",
"cancel_initiated_at": "2026-01-01T00:00:00.000Z",
"results_url": "text"
}Get status or results of a batch
The ID of the batch to retrieve its status and results.
<REPLACE_WITH_YOUR_BATCH_ID>Unique identifier of the batch.
msgbatch_01McVJYhQd3Wiuqrac6y9PrXObject type.
message_batchCurrent processing status of the batch.
in_progressTimestamp when the batch finished processing, if completed.
Timestamp when the batch was created.
2025-10-24T13:49:11.902215+00:00Timestamp when the batch will expire if not completed.
2025-10-25T13:49:11.902215+00:00Timestamp when cancellation was initiated, if applicable.
URL to download batch results once processing is complete.
{
"id": "msgbatch_01McVJYhQd3Wiuqrac6y9PrX",
"type": "message_batch",
"processing_status": "in_progress",
"request_counts": {
"processing": 3,
"succeeded": 0,
"errored": 0,
"canceled": 0,
"expired": 0
},
"ended_at": "2026-01-01T00:00:00.000Z",
"created_at": "2025-10-24T13:49:11.902215+00:00",
"expires_at": "2025-10-25T13:49:11.902215+00:00",
"cancel_initiated_at": "2026-01-01T00:00:00.000Z",
"results_url": "text"
}Cancel a batch
The ID of the batch to cancel.
<REPLACE_WITH_YOUR_BATCH_ID>Unique identifier of the batch.
fe91QH0tkQwaJSXo0q77OFinal status of the batch after cancellation.
cancelledBatch output, if available.
Usage details for the batch.
{
"id": "fe91QH0tkQwaJSXo0q77O",
"status": "cancelled",
"output": null,
"usage": []
}Last updated
Was this helpful?