Files & large batches
Upload a large JSONL request file with POST /v1/files (purpose batch_input) and reference it as input_file_id.
Not open yet
Most small batches submit their work inline as an array of items. When the request set is large, upload it first as a JSONL file with POST /v1/files (purpose batch_input) and pass the returned id as input_file_id.
| You upload | Purpose | You get | You use it as |
|---|---|---|---|
| A JSONL file of requests | batch_input | A file with kind: "input_manifest" | input_file_id on the quote and the batch |
This guide covers when to use a file versus inline items and how to upload and use one.
When to use a file
Use a file instead of inline items when the request set is large. Inline items are capped at 5,000 per request, and thousands of items in one JSON body are memory-heavy on both ends. Upload the requests as a JSONL file with purpose batch_input and pass its id as the batch's input_file_id. A batch takes its requests from either inline items or an input_file_id, not both.
Submit a large request set as a file
When the requests themselves are numerous, upload them as a JSONL file with purpose batch_input and pass the returned file_id to the quote and the create as input_file_id, instead of inline items. The 5,000-item cap applies to inline items only; the decision rule and the recipe for a job too large for one upload are in Large batches.
-
Build the JSONL in one of the two shapes on JSONL input format:
- Batchrouter Sectioned v1: a header line, then sections that hold the model, endpoint and shared prompt once, each followed by its requests. The smallest file when many requests share a prompt.
- Standard OpenAI Batch lines: one
{ custom_id, method, url, body }request per line, as for the OpenAI Batch API.
Mixed-model files are supported in both: Batchrouter keeps one customer batch and splits execution into model-specific lanes. A file of Batchrouter items, one per line, is still accepted but deprecated.
-
Upload it as a raw body to
POST /v1/fileswithX-BatchRouter-Purpose: batch_input.Content-Typemust beapplication/x-ndjson(orapplication/jsonl/application/jsonlines) andContent-Lengthis required. The shape is detected from the first line;X-BatchRouter-Item-Count(the number of requests) is optional but worth sending.curl -X POST https://api.batchrouter.com/v1/files \ -H "Authorization: Bearer $BATCHROUTER_API_KEY" \ -H "X-BatchRouter-Purpose: batch_input" \ -H "Content-Type: application/x-ndjson" \ -H "Content-Length: $(wc -c < requests.jsonl)" \ --data-binary @requests.jsonl # => { "file_id": "file_abc123", "file": { "kind": "input_manifest", ... } }Every line is checked while the file streams in. The response is
201with the file's id, the shape it detected and the number of requests it counted:{ "file_id": "file_abc123", "file": { "id": "file_abc123", "kind": "input_manifest", "purpose": "batch_input", "content_type": "application/x-ndjson", "size_bytes": 73400320, "sha256": null, "filename": null, "media_kind": null, "item_count": 10000, "manifest_format": "openai_batch_jsonl", "created_at": "2026-10-18T10:00:00Z" }, "usage": { "batch_create": { "input_file_id": "file_abc123", "input_item_count": 10000, "input_manifest_format": "openai_batch_jsonl" } } } -
Quote it with
POST /v1/quotes/model, sendinginput_file_idandinput_item_count(the fields inusage.batch_create) where you would otherwise senditems. The quote reads the file and prices every request. -
Create the batch with the same
input_file_id, thequote_idfrom the quote, and anIdempotency-Key, and noitemsfield:curl -X POST https://api.batchrouter.com/v1/batches \ -H "Authorization: Bearer $BATCHROUTER_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d '{ "quote_id": "qlock_abc123", "input_file_id": "file_abc123", "input_item_count": 10000, "sla_tier": "standard" }'
A file with a bad line is refused at upload with 400 and nothing is stored: a Sectioned v1 file with invalid_sectioned_input_manifest and the physical line in error.details.line (the reason in error.details.reason), a line-per-request file with the request number. The codes are listed under Errors at upload. A count that differs from X-BatchRouter-Item-Count or input_item_count is 400 input_manifest_count_mismatch. Nothing is reserved until the create succeeds.
Each line of the file may hold at most 1 MiB (1,048,576 bytes). A longer line refuses the file with 413 input_line_too_large, naming the line in error.details.line and the limit in error.details.max_line_bytes.
From there the flow is identical to inline submission: the batch returns 202 with a batch_... id, and you poll and fetch results as usual. Results list your requests in the order of your file, each under its custom_id as customer_item_id. If the Batchrouter SDK or the dashboard sectioned the file for you, that is the sectioned file's order, section by section; see Results come back in your order. See Submit a batch for the full lifecycle and Results for the result rows.
POST /v1/batches/input-manifests is a deprecated alias of the batch_input upload: same checks and the same file id, with input_file_id and input_file in the response instead of file_id and file. New code should use POST /v1/files.
Migrating from OpenAI Batch? Your existing JSONL works with the native upload above as standard OpenAI lines. There is also a drop-in compatibility surface with its own file endpoint: POST /v1/openai/v1/files takes a multipart file + purpose: "batch" with standard OpenAI lines and is consumed by POST /v1/openai/v1/batches. That's separate from the native /v1/files endpoint; pick one surface and stay on it. See OpenAI compatibility.