Skip to content

Batch API

The Batch API runs requests you do not need answered right now. You upload a JSONL file with one request per line, start a batch, and come back for the results. Nothing streams and nothing blocks: siema_ai runs the lines when the model is warm anyway, or when the queue is big enough (or its deadline near enough) to be worth starting it, and every line is metered and charged like any other request.

Use it for work where a few hours is fine: classifying or summarising a backlog, generating embeddings for a corpus, back-filling a dataset, running an evaluation. Use chat completions when someone is waiting for the answer. A batch has a 24-hour completion window and no promise of being faster; most of the time it is, but plan for the full day.

The API is OpenAI’s Batch API, so the official SDKs work unchanged: point base_url at https://api.siema-ai.pl/v1 and use your siema_ai key. Two kinds of request are supported, /v1/chat/completions and /v1/embeddings.

  1. Upload the JSONL file with purpose="batch". Every line is validated before anything is stored; a bad line rejects the whole upload and names the line.
  2. Create a batch from the uploaded file.
  3. Poll the batch until its status is final.
  4. Download the results file, and join each result to your request with custom_id.
import os, time
from openai import OpenAI
client = OpenAI(base_url="https://api.siema-ai.pl/v1", api_key=os.environ["SIEMA_API_KEY"])
# 1. upload
uploaded = client.files.create(file=open("requests.jsonl", "rb"), purpose="batch")
# 2. create
batch = client.batches.create(
input_file_id=uploaded.id,
endpoint="/v1/chat/completions",
completion_window="24h",
metadata={"job": "ticket-triage"}, # optional, strings only, up to 16 keys
)
# 3. poll
while batch.status not in ("completed", "failed", "expired", "cancelled"):
time.sleep(60)
batch = client.batches.retrieve(batch.id)
print(batch.status, batch.request_counts)
# 4. download
if batch.output_file_id:
results = client.files.content(batch.output_file_id).text
for line in results.splitlines():
... # one JSON object per line, see "Results" below
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.siema-ai.pl/v1",
apiKey: process.env.SIEMA_API_KEY,
});
// 1. upload
const uploaded = await client.files.create({
file: fs.createReadStream("requests.jsonl"),
purpose: "batch",
});
// 2. create
let batch = await client.batches.create({
input_file_id: uploaded.id,
endpoint: "/v1/chat/completions",
completion_window: "24h",
});
// 3. poll
const final = ["completed", "failed", "expired", "cancelled"];
while (!final.includes(batch.status)) {
await new Promise((r) => setTimeout(r, 60_000));
batch = await client.batches.retrieve(batch.id);
}
// 4. download
if (batch.output_file_id) {
const text = await (await client.files.content(batch.output_file_id)).text();
for (const line of text.split("\n").filter(Boolean)) {
const result = JSON.parse(line); // see "Results" below
}
}

One JSON object per line (UTF-8, \n or \r\n line endings; blank lines are ignored), one endpoint per file:

{"custom_id": "ticket-1041", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "speakleash/bielik-minitron-7b-v3.0-instruct", "messages": [{"role": "user", "content": "Sklasyfikuj zgłoszenie: ..."}], "max_tokens": 100}}
Field Rule
custom_id A string of 1 to 64 characters, unique in the file. It is your join key: results come back in completion order, not the order of the file.
method "POST".
url /v1/chat/completions or /v1/embeddings; the same on every line of a file, and the same as the endpoint you give when creating the batch.
body The same JSON the synchronous route accepts. model must be an available model id that supports the endpoint. stream must be absent or false. The chat and embeddings limits apply: n at most 8, no best_of, max_tokens at least 1, embeddings input up to 2048 items.

Any other field on the line is rejected. A rejected upload is a 400 whose message names the line number and the reason, for example line 12: body.stream is not supported in a batch, and never quotes your content.

The results file is JSONL too, one line per request in your file, in the order the requests finished. Each line has an id, your custom_id, and either a response or an error:

{"id": "batch_req_0192a1b2-...", "custom_id": "ticket-1041", "response": {"status_code": 200, "request_id": "0192a1b2-...", "body": {"object": "chat.completion", "choices": ["..."], "usage": {"prompt_tokens": 61, "completion_tokens": 12, "total_tokens": 73, "cost_micro_pln": 146}}}, "error": null}
{"id": "batch_req_0192a1b3-...", "custom_id": "ticket-1042", "response": null, "error": {"code": "expired", "message": "the batch expired before this request ran"}}
  • response.body is exactly the JSON the synchronous route would have returned, and response.status_code its status. Its usage.cost_micro_pln is priced at the batch price when the model has one. A request the model server rejected, for example with a 400, still has a response, so look at the status code, not only at whether error is empty.
  • error appears for a request that never produced an answer. Its code is one of the codes on the errors page, or expired, cancelled, api_key_revoked, org_suspended or storage_lost when the batch ended before the request ran, or connection_error (the model server could not be reached after every retry), response_too_large (the answer exceeded 32 MiB), unreadable_line or internal_error for our own failures on that line. Unlike OpenAI there is no separate error file: failed requests are lines of the results file, and error_file_id is always null.
  • Download the file with files.content; it is an attachment named output.jsonl.
Status Meaning
in_progress Accepted; lines are waiting or running.
finalizing Every line is done; the results file is being sealed.
completed Finished within the window. request_counts says how many lines succeeded and how many failed.
expired The 24-hour window ran out. Lines that had not run are in the results as expired errors and are not charged; the lines that did run are there too.
cancelling, cancelled You cancelled it with batches.cancel. Lines already running finish; the rest become cancelled errors.
failed The API key that created the batch was revoked, or the organisation was suspended (remaining lines are api_key_revoked or org_suspended errors), or our stored copy of the batch’s files was lost (storage_lost: there is no results file, finished lines were charged, unfinished lines were not (except a line already being processed when the loss was found, which may be charged without a result), and you resubmit the lines that did not finish).

request_counts.failed counts every line that did not succeed, including lines that expired or were cancelled before they ran; those are not charged.

output_file_id is set once the batch is in a final status, including expired, cancelled and failed, so you can collect what did run. The one exception is a failed batch whose errors code is storage_lost: its output_file_id stays null. GET /v1/batches lists your organisation’s batches, newest first. The console has a Zadania wsadowe page that lists them with their status, progress and cost, downloads results and cancels a running batch; creating a batch is API only.

Defaults today; they can change, and the API tells you when you hit one:

Limit Value
File size 100 MiB
Requests per file 10 000
One request line 20 MiB
One result line 32 MiB
Stored batch files per organisation 500 MiB
Unfinished batches per organisation 20
Uploads per organisation 10 per minute
Completion window 24 hours, the only accepted value

A request whose answer is larger than 32 MiB (for example a very large embeddings input in one line) is recorded as an error with the code response_too_large, and that line is charged, because the model did the work. Split the input of large embeddings jobs across several lines.

Uploading or creating a batch needs a positive balance (402 insufficient_quota otherwise). Nothing is charged for queueing. If your balance runs out while the batch is running, its lines wait, and resume once you top up, for as long as the window allows. An upload that is not attached to a batch within 24 hours is deleted. When batch storage on our side is temporarily full you get 503 storage_unavailable; retry later.

While no model server is up (a cold start) a line waits and is tried again every couple of minutes until the window ends; a line that never got a server expires and is not charged.

Batch requests do not count against your rate limits.

Each line is charged when it runs, for its own tokens, like a synchronous request: the batch price per model on GET /v1/models (the batch_input_micro_pln_per_1m and batch_output_micro_pln_per_1m fields of pricing), or the sync price until one is set for that model. The price applied is the one in effect when the line started. A line that fails before a model server produced anything costs nothing, as described on the errors page; see Billing for the cost formula.

Batch is the one place siema_ai keeps the content of your requests, because the requests have to wait their turn. In plain words:

  • Your input file and the results are encrypted on disk, each file with its own key. The keys are wrapped by a master key held only in the batch service’s environment, never in a database, and the files are not part of our backups.
  • The input file is deleted as soon as the batch finishes. The results file is deleted 7 days after that, or sooner if you delete it yourself with files.delete. Download what you need within the week.
  • An input file you uploaded but never used is deleted after 24 hours. You can delete it yourself, but not while a batch is using it; cancel the batch instead.
  • Nothing from your requests or results is written to logs or traces. The model server sees each request while it runs, exactly as for a synchronous request.
  • A short record of the batch (counts, status and times) outlives the files for a little while. It holds no request or result content, but it does include the optional metadata strings you attached to the batch, stored as you gave them, so keep personal data and secrets out of them.

See Data handling and retention for everything else we store.