For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs. Agents can also search and read this documentation through its MCP server.
Skip to content

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.

Action
Endpoint

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

The older inline format (a requests array in the body, Anthropic models only) still works. New integrations should use the file-based flow on this page.


How a batch works

  1. Write the file. Put one request per line in a JSONL file. Every line uses the same model and sets max_tokens.

  2. Upload it with purpose=batch. You get a file ID.

  3. Create the batch with that file ID. The answer comes at once, with the status validating.

  4. 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.

  5. The batch ends. The results are collected (finalizing), and the batch ends as completed, expired, cancelled or failed. You are charged once, for what ran, and the rest of the reservation is released.

  6. Read the results from the output file and the error file. Poll the batch, or pass a webhook_url to 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.

Provider
Models
Batch price

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

Google

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:

Field
Rule

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_tokens or max_completion_tokens is required on every line. The reservation for the batch is priced from it (see Billing), so a line without one fails with max_tokens_required.

  • Text and function tools only. messages takes the roles system, developer, user, assistant and tool, with content as a string or an array of text parts, plus name, tool_calls and tool_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 (type function), tool_choice, parallel_tool_calls and user. stream may only be false and n only 1. cache_control is 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

post
Body
filestring · binaryRequired

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.

purposestring · enumRequired

Only batch can be uploaded.

Possible values:
Responses
200

OK

application/json

A file of the Batch API.

idstringRequired

File ID.

Example: file-3f2b8c1e-7a4d-4e0b-9c55-1d2e3f4a5b6c
objectstring · enumRequired

Always file.

Possible values:
bytesintegerRequired

Size of the file in bytes.

Example: 1874
created_atintegerRequired

Unix time (seconds) when the file was created.

Example: 1794585600
expires_atinteger · nullableRequired

Unix 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.

filenamestringRequired

File name.

Example: requests.jsonl
purposestring · enumRequired

batch for an input file you uploaded, batch_output for an output or error file of a batch.

Possible values:
statusstring · enumRequired

Deprecated OpenAI field. Always processed.

Possible values:
status_detailsany · nullableRequired

Deprecated OpenAI field. Always null.

200

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
}
Code Example (Python)
Response

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:

  1. POST /v1/uploads with filename, purpose: "batch", bytes (the total size) and, optionally, mime_type. The upload stays open for 1 hour.

  2. For each part, POST /v1/uploads/{upload_id}/parts with {"part_number": n} (from 1). The answer carries a url.

  3. PUT the part's bytes to that url and keep the ETag header of the answer. Every part except the last must be at least 5 MiB.

  4. POST /v1/uploads/{upload_id}/complete with {"parts": [{"part_number": 1, "etag": "..."}, ...]}. The answer's file is the uploaded file; use its id as input_file_id.

POST /v1/uploads/{upload_id}/cancel abandons an upload. You can have up to 20 uploads open at a time.

Code Example: upload in parts (Python)

Create a batch

post
Header parameters
Idempotency-Keystring · max: 255Optional

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.

Body
input_file_idstringRequired

ID of a file uploaded with purpose=batch.

Example: <REPLACE_WITH_YOUR_FILE_ID>
endpointstring · enumRequired

The endpoint every line calls. Only /v1/chat/completions is supported.

Possible values:
completion_windowstring · enumRequired

The time the batch has to finish. Only 24h is supported.

Possible values:
webhook_urlstring · uri · max: 2048Optional

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.

Responses
200

OK

application/json

A batch.

idstringRequired

Batch ID. Starts with batch_.

Example: batch_V1StGXR8Z5jdHi6BmyT8k
objectstring · enumRequiredPossible values:
endpointstringRequired

The endpoint every line calls.

Example: /v1/chat/completions
modelstringRequired

The model of the batch, as the lines name it.

Example: anthropic/claude-opus-5-5
input_file_idstringRequired

ID of the input file.

completion_windowstringRequired

Always 24h.

Example: 24h
statusstring · enumRequired

Current status of the batch.

Possible values:
output_file_idstring · nullableRequired

ID of the file with the successful results, once the batch has ended.

error_file_idstring · nullableRequired

ID of the file with the lines that failed, once the batch has ended.

created_atintegerRequired

Unix time (seconds) when the batch was created.

Example: 1794585600
in_progress_atinteger · nullableRequired

Unix time (seconds) when the provider accepted the batch.

expires_atintegerRequired

Unix time (seconds) when the 24-hour window ends.

Example: 1794672000
finalizing_atinteger · nullableRequired

Unix time (seconds) when the results started being collected.

completed_atinteger · nullableRequired

Unix time (seconds) when the batch completed.

failed_atinteger · nullableRequired

Unix time (seconds) when the batch failed.

expired_atinteger · nullableRequired

Unix time (seconds) when the batch expired.

cancelling_atinteger · nullableRequired

Unix time (seconds) when the cancellation started.

cancelled_atinteger · nullableRequired

Unix time (seconds) when the batch was cancelled.

{
  "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.

Code Example (Python)
Response

Statuses

Status
Meaning

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

get
Path parameters
batch_idstringRequired

The ID of the batch (starts with batch_).

Example: <REPLACE_WITH_YOUR_BATCH_ID>
Responses
200

OK

application/json

A batch.

idstringRequired

Batch ID. Starts with batch_.

Example: batch_V1StGXR8Z5jdHi6BmyT8k
objectstring · enumRequiredPossible values:
endpointstringRequired

The endpoint every line calls.

Example: /v1/chat/completions
modelstringRequired

The model of the batch, as the lines name it.

Example: anthropic/claude-opus-5-5
input_file_idstringRequired

ID of the input file.

completion_windowstringRequired

Always 24h.

Example: 24h
statusstring · enumRequired

Current status of the batch.

Possible values:
output_file_idstring · nullableRequired

ID of the file with the successful results, once the batch has ended.

error_file_idstring · nullableRequired

ID of the file with the lines that failed, once the batch has ended.

created_atintegerRequired

Unix time (seconds) when the batch was created.

Example: 1794585600
in_progress_atinteger · nullableRequired

Unix time (seconds) when the provider accepted the batch.

expires_atintegerRequired

Unix time (seconds) when the 24-hour window ends.

Example: 1794672000
finalizing_atinteger · nullableRequired

Unix time (seconds) when the results started being collected.

completed_atinteger · nullableRequired

Unix time (seconds) when the batch completed.

failed_atinteger · nullableRequired

Unix time (seconds) when the batch failed.

expired_atinteger · nullableRequired

Unix time (seconds) when the batch expired.

cancelling_atinteger · nullableRequired

Unix time (seconds) when the cancellation started.

cancelled_atinteger · nullableRequired

Unix time (seconds) when the batch was cancelled.

{
  "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"
  }
}
Code Example (Python)
Response (status: completed)

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.

get
Path parameters
file_idstringRequired

The ID of the file.

Example: <REPLACE_WITH_YOUR_FILE_ID>
Responses
302

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.

302

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.

Code Example (Python)

List batches

get
Query parameters
limitinteger · min: 1 · max: 100Optional

Number of batches per page.

Default: 20
afterstringOptional

The last_id of the previous page.

Responses
200

Your batches, newest first.

application/json
objectstring · enumRequiredPossible values:
first_idstring · nullableRequired

ID of the first batch on this page.

last_idstring · nullableRequired

ID of the last batch on this page. Pass it as after to get the next page.

has_morebooleanRequired

Whether there are more batches after this page.

200

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.

Code Example (Python)

Cancel a batch

post
Path parameters
batch_idstringRequired

The ID of the batch (starts with batch_).

Example: <REPLACE_WITH_YOUR_BATCH_ID>
Responses
200

OK

application/json

A batch.

idstringRequired

Batch ID. Starts with batch_.

Example: batch_V1StGXR8Z5jdHi6BmyT8k
objectstring · enumRequiredPossible values:
endpointstringRequired

The endpoint every line calls.

Example: /v1/chat/completions
modelstringRequired

The model of the batch, as the lines name it.

Example: anthropic/claude-opus-5-5
input_file_idstringRequired

ID of the input file.

completion_windowstringRequired

Always 24h.

Example: 24h
statusstring · enumRequired

Current status of the batch.

Possible values:
output_file_idstring · nullableRequired

ID of the file with the successful results, once the batch has ended.

error_file_idstring · nullableRequired

ID of the file with the lines that failed, once the batch has ended.

created_atintegerRequired

Unix time (seconds) when the batch was created.

Example: 1794585600
in_progress_atinteger · nullableRequired

Unix time (seconds) when the provider accepted the batch.

expires_atintegerRequired

Unix time (seconds) when the 24-hour window ends.

Example: 1794672000
finalizing_atinteger · nullableRequired

Unix time (seconds) when the results started being collected.

completed_atinteger · nullableRequired

Unix time (seconds) when the batch completed.

failed_atinteger · nullableRequired

Unix time (seconds) when the batch failed.

expired_atinteger · nullableRequired

Unix time (seconds) when the batch expired.

cancelling_atinteger · nullableRequired

Unix time (seconds) when the cancellation started.

cancelled_atinteger · nullableRequired

Unix time (seconds) when the batch was cancelled.

{
  "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"
  }
}
When you cancel
What happens

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

Code Example (Python)

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 https URL 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_id and up to 10 errors. 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 (or max_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_tokens at the reasoning price, because their reasoning is not bounded by max_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 purpose batch_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

get
Query parameters
purposestring · enumOptional

Only files of this purpose. Without it, both purposes are listed.

Possible values:
limitinteger · min: 1 · max: 100Optional

Number of files per page.

Default: 20
afterstringOptional

The last_id of the previous page.

orderstring · enumOptional

Newest first. asc is not supported.

Default: descPossible values:
Responses
200

OK

application/json
objectstring · enumRequiredPossible values:
first_idstring · nullableRequired

ID of the first file on this page.

last_idstring · nullableRequired

ID of the last file on this page. Pass it as after to get the next page.

has_morebooleanRequired

Whether there are more files after this page.

200

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

get
Path parameters
file_idstringRequired

The ID of the file.

Example: <REPLACE_WITH_YOUR_FILE_ID>
Responses
200

OK

application/json

A file of the Batch API.

idstringRequired

File ID.

Example: file-3f2b8c1e-7a4d-4e0b-9c55-1d2e3f4a5b6c
objectstring · enumRequired

Always file.

Possible values:
bytesintegerRequired

Size of the file in bytes.

Example: 1874
created_atintegerRequired

Unix time (seconds) when the file was created.

Example: 1794585600
expires_atinteger · nullableRequired

Unix 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.

filenamestringRequired

File name.

Example: requests.jsonl
purposestring · enumRequired

batch for an input file you uploaded, batch_output for an output or error file of a batch.

Possible values:
statusstring · enumRequired

Deprecated OpenAI field. Always processed.

Possible values:
status_detailsany · nullableRequired

Deprecated OpenAI field. Always null.

200

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

delete
Path parameters
file_idstringRequired

The ID of the file.

Example: <REPLACE_WITH_YOUR_FILE_ID>
Responses
200

The file is deleted.

application/json
idstringRequired

ID of the deleted file.

objectstring · enumRequiredPossible values:
deletedboolean · enumRequiredPossible values:
{
  "id": "text",
  "object": "file",
  "deleted": true
}

Limits

Limit
Value

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:

Provider
Lines per file
File size

Anthropic

100,000

256 MB

OpenAI

50,000

200 MB

Google

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_webhook_url, webhook_secret_required

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.

Batches of the file-based format are always live. Sandbox mode does not cover them: a sandbox request with input_file_id returns 400 sandbox_unsupported.


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.

Action
Endpoint

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

post

The legacy inline format (Anthropic models only). For new integrations, upload a JSONL file and create the batch with input_file_id instead.

Body
Responses
200Success
application/json
idstringRequired

Unique identifier of the batch.

Example: kgTRCVoAz4GwrHWIOFZjg
typestringRequired

Object type.

Example: message_batch
processing_statusstringRequired

Current processing status of the batch.

Example: in_progress
ended_atstring · date-time · nullableOptional

Timestamp when the batch finished processing, if completed.

created_atstring · date-timeRequired

Timestamp when the batch was created.

Example: 2026-05-04T17:27:37.468424+00:00
expires_atstring · date-timeRequired

Timestamp when the batch will expire if not completed.

Example: 2026-05-05T17:27:37.468424+00:00
archived_atstring · date-time · nullableOptional

Timestamp when the batch was archived, if applicable.

cancel_initiated_atstring · date-time · nullableOptional

Timestamp when cancellation was initiated, if applicable.

results_urlstring · nullableOptional

URL to download batch results once processing is complete.

200Success
{
  "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"
}
Code Example (Python)
Response

Get status or results of a batch

get
Query parameters
batch_idstringRequired

The ID of the batch to retrieve its status and results.

Example: <REPLACE_WITH_YOUR_BATCH_ID>
Responses
200Success
application/json
idstringRequired

Unique identifier of the batch.

Example: msgbatch_01McVJYhQd3Wiuqrac6y9PrX
typestringRequired

Object type.

Example: message_batch
processing_statusstringRequired

Current processing status of the batch.

Example: in_progress
ended_atstring · date-time · nullableOptional

Timestamp when the batch finished processing, if completed.

created_atstring · date-timeRequired

Timestamp when the batch was created.

Example: 2025-10-24T13:49:11.902215+00:00
expires_atstring · date-timeRequired

Timestamp when the batch will expire if not completed.

Example: 2025-10-25T13:49:11.902215+00:00
cancel_initiated_atstring · date-time · nullableOptional

Timestamp when cancellation was initiated, if applicable.

results_urlstring · nullableOptional

URL to download batch results once processing is complete.

200Success
{
  "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"
}
Code Example (Python)

Cancel a batch

post
Path parameters
batch_idstringRequired

The ID of the batch to cancel.

Example: <REPLACE_WITH_YOUR_BATCH_ID>
Responses
200Success
application/json
idstringRequired

Unique identifier of the batch.

Example: fe91QH0tkQwaJSXo0q77O
statusstringRequired

Final status of the batch after cancellation.

Example: cancelled
outputany · nullableRequired

Batch output, if available.

usageobject[]Required

Usage details for the batch.

200Success
{
  "id": "fe91QH0tkQwaJSXo0q77O",
  "status": "cancelled",
  "output": null,
  "usage": []
}
Code Example (Python)

Last updated

Was this helpful?