JSONL input format
The two shapes of a batch input file, Batchrouter Sectioned v1 and standard OpenAI Batch lines, how Batchrouter detects them, how to upload one with POST /v1/files, and the errors you can get back.
Not open yet
A batch is a list of requests. You send small batches inline as items in the request body; for anything larger you upload the requests as a JSONL file and pass its id as input_file_id. This page describes the file.
An input file takes one of two shapes:
| Shape | input_manifest_format | What a line is | Use it when |
|---|---|---|---|
| Batchrouter Sectioned v1 | batchrouter_sectioned_v1 | A header line, then sections; each section holds the model, endpoint and shared prompt once and is followed by its requests | Many requests share a system prompt, few-shot examples or settings |
| Standard OpenAI Batch lines | openai_batch_jsonl | One OpenAI Batch API request per line | You already have OpenAI Batch files, or each request is self-contained |
Both are first-class: they are uploaded, quoted, routed and priced the same way, and a request means the same thing in either shape. Pick the one that is easiest for you to write.
Native item JSONL is deprecated
A file of Batchrouter item objects, one per line (batchrouter_items_jsonl), is still accepted, but it is frozen: it gets no new features and may be removed in the future. Write new files as Sectioned v1 or standard OpenAI lines. The item object itself is still the shape of inline items; see Inline items.
Standard OpenAI Batch lines
Each line is one request in the shape of the OpenAI Batch API, so an existing OpenAI Batch file works once its model values are Batchrouter model ids:
{"custom_id":"triage-001","method":"POST","url":"/v1/chat/completions","body":{"model":"gpt-5.4-mini","messages":[{"role":"system","content":"You triage support tickets. Reply with one word: billing, shipping or other."},{"role":"user","content":"I was charged twice for order 48213."}],"temperature":0,"max_tokens":16}}
{"custom_id":"triage-002","method":"POST","url":"/v1/chat/completions","body":{"model":"gpt-5.4-mini","messages":[{"role":"system","content":"You triage support tickets. Reply with one word: billing, shipping or other."},{"role":"user","content":"My package has said 'in transit' for 9 days."}],"temperature":0,"max_tokens":16}}| Field | Required | Description |
|---|---|---|
custom_id | yes | Your id for the request, at most 128 characters. It comes back on the result as customer_item_id, so you can join outputs to inputs. Keep it unique within the batch. |
method | yes | POST. |
url | yes | /v1/chat/completions. |
body | yes | The request body. body.model is a Batchrouter model id: list real values with GET /v1/catalog/models. |
One request per line: no array, no trailing commas. Blank lines are skipped. Lines may name different models; see Mixed-model batches.
Batchrouter Sectioned v1
A sectioned file writes what a group of requests shares once, in a section, and lists the requests after it. The file starts with a header line:
{"type":"header","format":"batchrouter.sectioned.v1"}
{"type":"section","id":"s1","model":"gpt-5.4-mini","url":"/v1/chat/completions","prefix":[{"role":"system","content":"You triage support tickets. Reply with one word: billing, shipping or other."}],"body":{"temperature":0,"max_tokens":16}}
{"type":"request","section":"s1","custom_id":"triage-001","body":{"messages":[{"role":"user","content":"I was charged twice for order 48213."}]}}
{"type":"request","section":"s1","custom_id":"triage-002","body":{"messages":[{"role":"user","content":"My package has said 'in transit' for 9 days."}]}}This file holds exactly the two requests of the standard example above. The shared system prompt and settings are written once instead of on every line, so a file whose requests share a long prompt is much smaller.
The three kinds of line
Header (the first non-empty line, exactly once):
| Field | Required | Description |
|---|---|---|
type | yes | "header". |
format | yes | "batchrouter.sectioned.v1". |
section_count | no | The number of sections. When you send it, the upload checks it. |
request_count | no | The number of requests. When you send it, the upload checks it. |
Section:
| Field | Required | Description |
|---|---|---|
type | yes | "section". |
id | yes | Your id for the section, unique in the file. Requests name it in section. |
model | yes | A Batchrouter model id from GET /v1/catalog/models. Sections in one file may use different models. |
url | yes | /v1/chat/completions. |
prefix | no | The leading messages every request in the section shares, for example the system prompt and few-shot examples. |
body | no | The request fields every request in the section shares, for example temperature, max_tokens, response_format or tools. Never messages: shared messages go in prefix. |
route_override | no | A routing override for every request in the section (a request's own wins). |
Request:
| Field | Required | Description |
|---|---|---|
type | yes | "request". |
section | yes | The id of the section it belongs to. |
custom_id | yes | Your id for the request, at most 128 characters; returned as customer_item_id. Keep it unique within the batch. |
body | no | The request's own fields: its messages (added after the section's prefix), and any field it sets differently. |
route_override | no | A routing override for this request. |
A cache_key on a section is ignored.
How a request expands
Every request turns into exactly one standard OpenAI Batch request:
body = { model: section.model,
messages: [...section.prefix, ...request.body.messages],
...section.body,
...request.body }A field the request sets wins over the section's (a shallow merge), and the section's prefix comes before the request's own messages. So triage-001 above runs as:
{"custom_id":"triage-001","method":"POST","url":"/v1/chat/completions","body":{"model":"gpt-5.4-mini","messages":[{"role":"system","content":"You triage support tickets. Reply with one word: billing, shipping or other."},{"role":"user","content":"I was charged twice for order 48213."}],"temperature":0,"max_tokens":16}}Rules
- The header is the first non-empty line. A file holds one shape: sectioned lines and standard lines never mix.
- A section line comes before its requests, and its requests follow it directly. Once a new section starts, an earlier section's requests cannot come back: sort your requests by section first, or send standard lines instead.
- Every section has at least one request. Use each section
idonce. - Bodies never set
model,streamorstream_options; a sectionbodynever setsmessages. - A request cannot remove a field its section's
bodysets. If some requests need a different value, override the field in those requests; if they need it unset, put them in a section of their own. Two sections may share the sameprefix.
A section only groups requests that share a prompt; it never changes what a request asks for. Each request runs as its expanded standard request, and Batchrouter may still split a section's requests across providers or provider batches.
Providers receive sectioned files too, with a few extra rules on their side (one model per file, a cache_key on every section, Batchrouter's item ids as custom_id). That variant is described in the Provider API; customers do not need it.
How the shape is detected
The upload decides the shape once and stores it with the file, so you normally never set it. input_manifest_format takes these values:
| Value | Meaning |
|---|---|
auto (default) | Read from the first non-empty line: a Sectioned v1 header means batchrouter_sectioned_v1; an OpenAI Batch request (custom_id, method, url, body) means openai_batch_jsonl; anything else is read as a Batchrouter item. |
batchrouter_sectioned_v1 | Batchrouter Sectioned v1. A file without the header line is refused with reason missing_header. |
openai_batch_jsonl | Standard OpenAI Batch lines. |
batchrouter_items_jsonl | Deprecated. One Batchrouter item per line. Still accepted, no new features. |
Declare it with the X-BatchRouter-Input-Manifest-Format header on the upload. A sectioned file declared as openai_batch_jsonl or batchrouter_items_jsonl is refused with 400 input_manifest_format_mismatch. The upload response reports the shape it stored in file.manifest_format.
Upload a file
Send the raw JSONL to POST /v1/files with X-BatchRouter-Purpose: batch_input. The body is the raw file, not multipart form data:
| Header | Required | Value |
|---|---|---|
X-BatchRouter-Purpose | yes | batch_input. Without a purpose, a JSONL Content-Type is also read as batch_input, but send it explicitly. |
Content-Type | yes | application/x-ndjson (application/jsonl and application/jsonlines are also accepted). Any other type is a 415. |
Content-Length | yes | Exact body size in bytes. Leaving it out is a 411. |
X-BatchRouter-Item-Count | no | The number of requests in the file, when you know it. The upload counts them and refuses the file with 400 input_manifest_count_mismatch when the two differ. In a sectioned file only request lines count; in a line-per-request file every non-empty line counts. |
X-BatchRouter-Input-Manifest-Format | no | See How the shape is detected. Defaults to auto. |
X-Content-SHA256 | no | Hex SHA-256 digest of the body, stored with the file. |
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 201 with the file id, the detected shape and the number of requests, plus the fields to quote and create with:
{
"file_id": "file_abc123",
"file": {
"id": "file_abc123",
"kind": "input_manifest",
"purpose": "batch_input",
"content_type": "application/x-ndjson",
"size_bytes": 812,
"sha256": null,
"filename": null,
"media_kind": null,
"item_count": 3,
"manifest_format": "batchrouter_sectioned_v1",
"created_at": "2026-10-18T10:00:00Z"
},
"usage": {
"batch_create": {
"input_file_id": "file_abc123",
"input_item_count": 3,
"input_manifest_format": "batchrouter_sectioned_v1"
}
}
}POST /v1/batches/input-manifests is a deprecated alias of this upload: same checks, same file id, but the response says input_file_id and input_file instead of file_id and file. Move to POST /v1/files.
For when to upload rather than inline, and for a job too large for one upload, see Large batches.
Reference the file in a batch
Quote with POST /v1/quotes/model and create with POST /v1/batches, passing input_file_id instead of items. You still pass your quote_id on create. Include input_item_count so a file that is not the one you meant is caught before any credits are reserved:
{
"input_file_id": "file_abc123",
"input_item_count": 3,
"quote_id": "qlock_..."
}Provide either inline items or input_file_id on POST /v1/batches, not both. A file uploaded without the batch_input purpose is refused as input_file_id with 400 invalid_input_file.
Errors at upload
A file with a bad line is refused as a whole (with 400, or 413 for a line over the size limit), and nothing is stored. Fix the line and upload again. The refusal names the line in error.details.line and repeats the problem in error.details.preflight.
Sectioned v1 files are refused with 400 invalid_sectioned_input_manifest. error.details.line is the physical line of the file, counted from the top of the file with blank lines included, so it matches what your editor shows; error.details.reason says what is wrong:
{
"error": {
"code": "invalid_sectioned_input_manifest",
"message": "Input manifest line 5: request for section s1 must follow that section directly.",
"details": {
"line": 5,
"reason": "request_out_of_section"
}
}
}reason | What is wrong |
|---|---|
missing_header | The first non-empty line is not a batchrouter.sectioned.v1 header. |
invalid_json | The line is not a JSON object. |
unknown_record | type is not header, section or request. |
invalid_section_id | A section has no id. |
missing_model | A section has no model. |
unsupported_endpoint | A section's url is not /v1/chat/completions. |
invalid_prefix | prefix is not an array of messages. |
invalid_body | A body is not an object, or a section body sets messages. |
invalid_messages | messages in a body is not an array. |
forbidden_field | A body sets model, stream or stream_options. |
request_out_of_section | A request does not directly follow its section (another section came between them, or the section was never declared). |
invalid_custom_id | custom_id is missing or longer than 128 characters. |
empty_section | A section has no requests. |
count_mismatch | The header's section_count or request_count does not match the file. line is 0: it is about the whole file. |
The response also carries error.details.preflight, left out above. A request line that is well formed but does not expand into a valid request is refused with the codes a standard line gets (openai_batch_*, below), or invalid_input_manifest_item for an invalid route_override, also with its physical line.
Standard OpenAI lines and native items keep numbering by request: error.details.line counts non-empty lines. A line that is not JSON is 400 invalid_input_manifest_jsonl; an OpenAI request that is not valid is 400 openai_batch_* (for example openai_batch_missing_model or openai_batch_unsupported_endpoint); a native item that is not valid is 400 invalid_input_manifest_item.
In every shape, a request count that differs from X-BatchRouter-Item-Count (at upload) or input_item_count (at quote and create) is 400 input_manifest_count_mismatch.
Line too long. Each line may hold at most 1 MiB (1,048,576 bytes, counted in UTF-8 bytes). A longer line in any shape refuses the whole file with 413 input_line_too_large, naming the physical file line in error.details.line (counted from the top of the file, blank lines included) and the limit in error.details.max_line_bytes. The same refusal applies at quote and create when you pass input_file_id.
{
"error": {
"code": "input_line_too_large",
"message": "Input manifest line 7 is larger than 1048576 bytes, the limit for one line.",
"details": {
"line": 7,
"max_line_bytes": 1048576
}
}
}Results come back in your order
Whatever shape you upload, results list your requests in the order you sent them: for a sectioned file, the order of its request lines. Each result carries your custom_id as customer_item_id. How Batchrouter groups and splits the work inside never changes that order. See Results.
Uploading with the Batchrouter SDK or the dashboard
The SDK and the dashboard write the sectioned file for you: they upload Sectioned v1 by default, grouping requests that share a prompt, and the SDK falls back to plain lines on an API that does not accept the format yet. Results then follow the sectioned file, section by section, which differs from your original line order when your lines interleave prompts. Match results by custom_id, or pass sectioned: false to the SDK's submit, uploadManifest or submitMany to keep your line order.
Mixed-model batches
Requests in one file can target different models: each standard line names its own model, and each section names one. Batchrouter splits the work into model-specific internal lanes, routes and prices each lane independently, and reports everything under a single customer batch id. You poll, retrieve results and pay against that one batch.
To let Batchrouter pick the cheapest eligible model instead of pinning one per request, pass models[] at quote time. See Quote a batch.
Inline items
Small batches can skip the file: send up to 5,000 items in the body of POST /v1/quotes/model and POST /v1/batches. An inline item is a Batchrouter item object:
| Field | Required | Description |
|---|---|---|
customer_item_id | yes | Your stable id for this item, echoed back on every result. Must be unique within the batch. |
operation | yes | chat.completions, the only operation. |
model | yes | A model id. List real values with GET /v1/catalog/models. |
input | yes | The request body without model: a chat-style messages array of { role, content } with text content. |
{"customer_item_id":"item-1","operation": "chat.completions","model":"gpt-5.4-mini","input":{"messages":[{"role":"user","content":"Summarize: Batchrouter routes batch-AI workloads across providers."}]}}The same object, one per line, is the deprecated batchrouter_items_jsonl file shape. If you have such files today they keep working; for new files, use standard OpenAI lines (custom_id for customer_item_id, body.model for model, and the rest of the body for input) or Sectioned v1.
If validation fails at quote or create, the endpoints return 400 with error.details.preflight describing the problem (for example a context window exceeded). Fix the input and resubmit: no credits are spent on a rejected batch.
Next steps
Files & large batches
Upload a request file, then quote and create with input_file_id.
Quote a batch
Price your requests for free before you spend credits.
Submit a batch
Create the batch with inline items or input_file_id and an idempotency key.
API reference
Full schemas for /v1/files, /v1/batches and the item object.