---
title: Batches (OpenAI-compatible)
description: Upload a JSONL file of chat or embedding requests with the OpenAI client, let SIE Serverless run it in the background, and download one output file when it finishes.
canonical_url: https://superlinked.com/docs/cloud/batches
last_updated: 2026-12-01
---

SIE Serverless serves OpenAI's Files and Batches API. You upload a JSONL file with one request per line, create a batch from it, and download an output file with one response per line when the batch finishes. It suits scheduled work such as a nightly classification run: submit, do something else, collect the results later.

The OpenAI client libraries work unchanged; only the base URL and the API key differ. A batch costs the same per-model prices as real-time calls of the same size. There is no batch discount.

## What a batch can run

| Endpoint in the file | Model | Requests per batch |
| --- | --- | --- |
| `/v1/chat/completions` | `Qwen/Qwen3.5-4B` | up to 384 |
| `/v1/embeddings` | `BAAI/bge-m3` | up to 100,000 |
| `/v1/embeddings` | `Snowflake/snowflake-arctic-embed-l-v2.0` | up to 100,000 |

Batches run on dedicated batch capacity. Every line in a file must use the same endpoint and model. Creating a batch for a model the batch capacity doesn't serve returns `400` with the code `BATCH_MODEL_NOT_SERVED`, or `INVALID_REQUEST` for a chat model served only through [SIE Relay](/docs/cloud/sie-relay/). Nothing runs or is charged. For other models, send real-time requests and cap your own concurrency as described in [Rate limits](/docs/cloud/rate-limits/#fan-out-workloads).

## Before you start

Your API key needs the **Batch jobs** scope. The new-key dialog selects **Inference** only, so also select **Batch jobs** under **Scopes** when you create the key on the **API keys** page. Without it, every `/v1/files` and `/v1/batches` call returns `403` with the code `INSUFFICIENT_SCOPE`.

## Write the input file

Each line is one request: a `custom_id` you choose, the `method`, the `url` (the endpoint) and the request `body`. The `custom_id` comes back on the matching output line, because output lines are not guaranteed to be in input order.

```jsonl
{"custom_id": "ticket-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "Qwen/Qwen3.5-4B", "messages": [{"role": "user", "content": "Classify as bug, question or request: The export button does nothing."}], "max_tokens": 16}}
{"custom_id": "ticket-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "Qwen/Qwen3.5-4B", "messages": [{"role": "user", "content": "Classify as bug, question or request: Can I invite a second admin?"}], "max_tokens": 16}}
```

An embeddings line has the same shape, with `"url": "/v1/embeddings"` and a body such as `{"model": "BAAI/bge-m3", "input": "first document"}`. Each line embeds one text: `input` is a string, or a list with one string.

A chat line's `body` takes `messages`, `max_tokens` (or `max_completion_tokens`), `temperature`, `top_p`, `top_k`, `stop`, `seed`, `frequency_penalty`, `presence_penalty`, `tools`, `tool_choice` and `parallel_tool_calls`. Other fields, such as `response_format`, `stream`, `n` or `logprobs`, fail that line: it goes to the error file and the rest of the batch runs.

Some problems fail the whole file, and creating the batch returns `400` with the line number: a line that isn't valid JSON, a missing or repeated `custom_id`, a `method` other than `POST`, a `url` that differs from the batch's `endpoint`, or lines that use different models.

The file can be up to 64 MiB.

## Run a batch

#### Python

```python
import os
import time

from openai import OpenAI

client = OpenAI(
    base_url="https://api.superlinked.com/v1",
    api_key=os.environ["SIE_API_KEY"],
)

upload = client.files.create(file=open("requests.jsonl", "rb"), purpose="batch")
batch = client.batches.create(
    input_file_id=upload.id,
    endpoint="/v1/chat/completions",
    completion_window="24h",
)

while batch.status not in ("completed", "failed", "expired", "cancelled"):
    time.sleep(30)
    batch = client.batches.retrieve(batch.id)

if batch.output_file_id:
    for line in client.files.content(batch.output_file_id).text.splitlines():
        print(line)
```

#### TypeScript

```typescript
import fs from "node:fs";
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.superlinked.com/v1",
  apiKey: process.env.SIE_API_KEY,
});

const upload = await client.files.create({
  file: fs.createReadStream("requests.jsonl"),
  purpose: "batch",
});
let batch = await client.batches.create({
  input_file_id: upload.id,
  endpoint: "/v1/chat/completions",
  completion_window: "24h",
});

const done = ["completed", "failed", "expired", "cancelled"];
while (!done.includes(batch.status)) {
  await new Promise((resolve) => setTimeout(resolve, 30_000));
  batch = await client.batches.retrieve(batch.id);
}

if (batch.output_file_id) {
  const output = await client.files.content(batch.output_file_id);
  console.log(await output.text());
}
```

`completion_window` accepts only `24h`. A batch that hasn't finished 24 hours after it was created ends as `expired`.

A batch on a model that isn't loaded waits for the model first, so even a small batch can take a few minutes.

## Read the output

Each output line answers one input line:

```json
{"id": "batch_req_…", "custom_id": "ticket-1", "response": {"status_code": 200, "request_id": "…", "body": {"id": "chatcmpl-…", "object": "chat.completion", "created": 1764057600, "model": "Qwen/Qwen3.5-4B", "choices": [{"index": 0, "message": {"role": "assistant", "content": "bug"}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 24, "completion_tokens": 2, "total_tokens": 26}}}, "error": null}
```

An embeddings line's `body` is the same list object `/v1/embeddings` returns, with one embedding.

Requests that failed are in a separate file, `error_file_id`. Each line keeps the `custom_id`, has `"response": null` and says why in `error`:

```json
{"id": "batch_req_ticket-2", "custom_id": "ticket-2", "response": null, "error": {"code": "invalid_request", "message": "…"}}
```

`invalid_request` means the line itself was refused, for example for an unsupported field. `not_processed` means the batch ended before the line ran. Any other code, such as `inference_error`, comes from running the request on the model.

A batch can complete with some lines in each file; `error_file_id` is `null` when every request succeeded.

## Batch states

| `status` | Meaning |
| --- | --- |
| `in_progress` | Requests are running. `request_counts` shows how many have finished. |
| `finalizing` | Every request has finished and the output files are being written. |
| `completed` | At least one request succeeded. The output file, and the error file if any request failed, are ready. |
| `failed` | No request succeeded. The error file says why for each line. |
| `expired` | It didn't finish within 24 hours, or it stopped because your organization's credit ran out. |
| `cancelling`, `cancelled` | You cancelled it with `POST /v1/batches/{id}/cancel`. |

The input file is checked when you create the batch, so a new batch starts at `in_progress`; SIE Serverless never reports `validating`.

An `expired` or `cancelled` batch has no output file, even for requests that finished before it stopped, and those requests are still charged. To keep partial results, split large work into several smaller batches.

## Files and limits

| | |
| --- | --- |
| Input file | JSONL, up to 64 MiB, uploaded with `purpose="batch"` |
| Requests per batch | 384 for chat completions, 100,000 for embeddings |
| Completion window | `24h` only |
| File retention | Input and output files are deleted 30 days after upload. Delete them sooner with `DELETE /v1/files/{id}`. |
| Rate limits | Every `/v1/files` and `/v1/batches` call counts against the batch jobs limits in [Rate limits](/docs/cloud/rate-limits/), 2 requests per second per key, so poll every few seconds, not in a tight loop. A refused call gets `429` with `Retry-After`; wait that long and send it again. |

`GET /v1/files` and `GET /v1/batches` list your organization's files and batches.

## Billing

Each request in a batch is charged at the same per-model price as the equivalent real-time call; see [pricing](/serverless#pricing). If your credit balance can't cover the batch, creating it returns `402` with the code `INSUFFICIENT_CREDITS` and nothing runs.

For encode work over items you send in the request body, the [jobs API](/docs/cloud/jobs/) is the SIE-native alternative.
