Batch API at half price: file format, flow and trade-offs

Run a JSONL file of chat, embedding or Responses requests as a batch within 24 hours at half the catalog price: line format, curl flow and cancel rule.

Checked 2026-11-22

·All posts·Models

A batch is a file of requests run within 24 hours at half the catalog price on every line, through the same routes and against the same key budget as a live request; here is how to build the file, what the discount applies to, and when a batch beats a loop of live calls. The routes are OpenAI's /v1/files and /v1/batches shapes at https://api.uplinkswitch.com/v1, so the OpenAI SDK's batch helpers work unchanged, and everything below is read from the route descriptions in the OpenAPI document.

What the discount applies to

The POST /v1/batches description is the source: a batch "runs every line of an uploaded file within 24 hours, through the same routes as a direct request with the key that creates the batch: priced at the catalog rates less the batch discount of 50% on every line". Three things follow from that sentence.

  • Every line, every model. The discount is on the catalog rate of whatever model the line names. A frontier id and a fast id in the same file each bill at half their own rate; there is no separate batch price list to look up.
  • Same accounting. Each line is held against the balance, the key's budget and the key's limits as it runs, so a key with monthly_cap_usd or budget_usd cannot overspend through a batch any more than through a loop. The receipt and the console's Usage page show the discounted charge per line.
  • Same price lock. A batch runs on your organization's own rates, so a 30-day price lock from a top-up applies to batch lines as it does to live requests.

One of our own feature summaries still describes batches at the normal catalog price; this page follows the route description quoted above, and each line's receipt shows the charge actually taken.

A line that fails bills nothing; its error goes to the error file. Lines not run by the end of the window go there too, with the code batch_expired, and are not charged.

The line format

The input is JSONL: one JSON object per line, no commas between lines. The POST /v1/files description sets the shape and the limits. Each line is { custom_id, method: "POST", url, body }; custom_id must be unique in the file, url must be the batch's endpoint, and body is exactly the request you would send live.

jsonl
{"custom_id": "ticket-1041", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "deepseek-v4.1-flash", "max_tokens": 200, "messages": [{"role": "system", "content": "Classify the support ticket as billing, bug or question. Answer with one word."}, {"role": "user", "content": "I was charged twice for March."}]}}
{"custom_id": "ticket-1042", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "deepseek-v4.1-flash", "max_tokens": 200, "messages": [{"role": "system", "content": "Classify the support ticket as billing, bug or question. Answer with one word."}, {"role": "user", "content": "The export button does nothing on Safari."}]}}
{"custom_id": "ticket-1043", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "claude-sonnet-5-5", "max_tokens": 400, "messages": [{"role": "user", "content": "Draft a two-sentence apology for a duplicate charge, no discount offered."}]}}

The file may be up to 50 MB and 50,000 lines. Every line is checked on upload, and the first bad one is named in the error, so a malformed file fails before any line runs. The allowed url values are /v1/chat/completions, /v1/completions, /v1/embeddings, /v1/responses and /v1/moderations; one batch has one endpoint, and every line's url must match it. Uploaded files are kept 30 days.

Use max_tokens on every line. It caps the output and sizes the hold taken from the balance while the line runs; without it the hold assumes a large output on every line, which on a long file ties up balance you will not spend.

The flow in curl

1. Upload the file with purpose set to batch. The answer is a file object whose id starts with file-.

bash
curl https://api.uplinkswitch.com/v1/files \
  -H "Authorization: Bearer $UPLINK_API_KEY" \
  -F purpose=batch \
  -F file=@tickets.jsonl

2. Create the batch. completion_window takes only 24h. metadata is optional: up to 16 string values, returned with the batch, useful for a job name or a ticket range.

bash
curl https://api.uplinkswitch.com/v1/batches \
  -H "Authorization: Bearer $UPLINK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input_file_id": "file-...", "endpoint": "/v1/chat/completions", "completion_window": "24h", "metadata": {"job": "ticket-triage-nightly"}}'

3. Poll the batch. status moves through validating, in_progress, finalizing and completed (or failed, expired, cancelling, cancelled), and request_counts reports total, completed and failed as lines finish. Lines run a few at a time per organization, so a long file takes a while even when every line is quick.

bash
curl https://api.uplinkswitch.com/v1/batches/batch_... \
  -H "Authorization: Bearer $UPLINK_API_KEY"

4. Read the output. When the batch finishes, output_file_id is set if any line answered 2xx and error_file_id if any line failed or expired. Each is JSONL again: one line per request, { id, custom_id, response: { status_code, request_id, body }, error }. Match on custom_id, since the order is not the input order. The request_id on each line is the same id a live request carries in its response headers, so each line can be looked up in the Usage page like any other request.

bash
curl https://api.uplinkswitch.com/v1/files/file-.../content \
  -H "Authorization: Bearer $UPLINK_API_KEY" > results.jsonl

5. Cancel if you must. Lines not started are left out; lines already answered stay in the output file and are billed. The batch reads cancelling until its running lines finish, then cancelled.

bash
curl -X POST https://api.uplinkswitch.com/v1/batches/batch_.../cancel \
  -H "Authorization: Bearer $UPLINK_API_KEY"

GET /v1/batches lists your batches newest first (limit up to 100, after a batch id to page), and GET /v1/files lists input, output and error files with purpose as the filter.

The same flow in Python

The OpenAI SDK's file and batch methods map one to one onto the routes above.

python
from openai import OpenAI
client = OpenAI(base_url="https://api.uplinkswitch.com/v1", api_key="sk-uplink-live-...")

upload = client.files.create(file=open("tickets.jsonl", "rb"), purpose="batch")
batch = client.batches.create(
    input_file_id=upload.id,
    endpoint="/v1/chat/completions",
    completion_window="24h",
    metadata={"job": "ticket-triage-nightly"},
)
# later
batch = client.batches.retrieve(batch.id)
if batch.status == "completed" and batch.output_file_id:
    results = client.files.content(batch.output_file_id).text

Price the file before you upload it

POST /v1/estimate prices a messages array on every model, with output_tokens as a parameter and your organization's own rates when you send a key. Run it on one representative line, multiply by the line count, and halve it: that is the batch's expected charge before a byte is uploaded. Two reference points at live catalog rates, each for one 2,000-token-in, 200-token-out line; a batch line bills half of each:

ModelLive price per lineOur rate, in / out per 1MList
deepseek-v4.1-flash$0.0001$0.0564 / $0.1692$0.30 / $1.20
claude-sonnet-5-5$0.0029$1.164 / $2.91$2.00 / $10.00
gpt-6.1-sol$0.0017$0.582 / $2.91$2.00 / $10.00

After the run, the Usage page's CSV export filtered to the key shows the discounted charge per line for the reconciliation.

When a batch beats a loop of live calls

A batch wins when three things are true at once: nobody is waiting for the answer, the work is already a list, and the list is large enough that halving the bill matters more than finishing in the next minute. Nightly classification of the day's tickets, re-embedding a corpus after a chunking change, generating product descriptions for a catalog import, scoring a test set, and summarising a month of call transcripts all fit.

A loop of live calls wins when a user is waiting, when each request depends on the one before (an agent, a conversation), or when you need the answer inside the 24-hour window for certain. A batch is also the wrong tool for a handful of requests: the upload and poll steps cost more engineering than the discount returns until the file has hundreds of lines.

Two patterns combine them. First, run the live path for the user-facing request and queue the follow-up work (tagging, summarising, embedding) as a batch. Second, when a batch expires with lines unrun, replay only the batch_expired lines from the error file as a new batch or as live calls; custom_id makes the join trivial.

Which models and formats

The endpoint enum covers the OpenAI-format routes: chat completions, completions, embeddings, Responses and moderations. The Anthropic Messages route is not among them, so a batch line is written in the OpenAI shape. That is not a restriction on models: every chat model on the catalog answers the OpenAI format, Claude ids included, so any model you can call live on /v1/chat/completions can go in a batch line. Embedding ids go on /v1/embeddings lines the same way; the catalog's endpoints field on each model row says which routes take it. Fallback lists, presets and the auto router are body fields, so a line may carry "model": "auto" or a models list exactly as a live request would; the output line's body.model names the model that answered.

Questions and answers

To every line's charge: the OpenAPI description prices a batch at the catalog rates less the batch discount on every line, whatever model the line names, with the receipt and the usage log showing the discounted figure. Failed and expired lines bill nothing. The hold against the balance, the key's budget and the key's limits works as for a live request.

The completion window is 24 hours, the only value completion_window takes; lines run a few at a time per organization and lines unrun at the end go to the error file as batch_expired, unbilled. POST /v1/batches/{batch_id}/cancel stops lines not yet started; lines already answered stay in the output file and are billed.

A batch line is an OpenAI-format request to chat completions, completions, embeddings, Responses or moderations, and every chat model on the catalog answers the OpenAI format, so any model you can call live on those routes can be batched. The Anthropic Messages route is not a batch endpoint, so write the line in the OpenAI shape and keep the model id.
Join on Telegram
Help