logitsDocs

Batch API

Run a JSONL file of Chat Completions requests asynchronously. Upload input, choose a service level, poll the batch, and download its output and error files.

The Batch API accepts a file of Chat Completions requests and processes them asynchronously. Use it when you can wait for results instead of holding a connection open for each request.

All endpoints use https://api.logits.com and the same API key as the chat API. Create a key on the API keys page; if the key is restricted to specific models, allow the model used by every input row.

Credentials
export LOGITS_API_KEY="logits_live_..."

Models and input limits

Batch accepts every chat model the API serves. Today these are:

ModelInput limits
deepseek/deepseek-v4.1-flashUp to 50,000 rows and 200 MiB per input file
logits/deepseek-v4.1-flash-abliteratedUp to 50,000 rows and 200 MiB per input file
moonshotai/kimi-k3.1-proUp to 50,000 rows and 200 MiB per input file
logits/kimi-k3.1-pro-abliteratedUp to 50,000 rows and 200 MiB per input file

Every row in a batch must use the same model. The batch accepts only /v1/chat/completions; each request body follows the ordinary Chat Completions contract, except that stream must be absent or false and priority is not allowed.

Prepare the JSONL input

Write one JSON object per line with these fields:

FieldRequired value
custom_idA non-empty string of at most 255 bytes, unique within the batch. Use it to match output and error rows to this input.
methodPOST
url/v1/chat/completions
bodyA Chat Completions request object with model set to the batch model.
batch-input.jsonl
{"custom_id":"first-question","method":"POST","url":"/v1/chat/completions","body":{"model":"deepseek/deepseek-v4.1-flash","messages":[{"role":"user","content":"What is the capital of France?"}],"stream":false}}
{"custom_id":"second-question","method":"POST","url":"/v1/chat/completions","body":{"model":"deepseek/deepseek-v4.1-flash","messages":[{"role":"user","content":"Summarize why batch processing is useful."}],"stream":false}}

The file must not be empty. Duplicate custom_id values, mixed models, streaming requests, and priority in a request body are rejected when the batch is created.

Upload, create, poll, and download with curl

Upload the input file

Upload the JSONL as multipart form data with purpose batch_input:

Upload the input file
curl --fail-with-body https://api.logits.com/v1/files \
  -H "Authorization: Bearer $LOGITS_API_KEY" \
  -F "file=@batch-input.jsonl" \
  -F "purpose=batch_input"

Save the returned file id:

export INPUT_FILE_ID="file_..."

Create the batch

Send the file ID and endpoint. Choose a service_level and its matching completion_window; this example uses the default tier explicitly:

Create the batch
curl --fail-with-body https://api.logits.com/v1/batches \
  -H "Authorization: Bearer $LOGITS_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"input_file_id\": \"$INPUT_FILE_ID\",
    \"endpoint\": \"/v1/chat/completions\",
    \"completion_window\": \"72h\",
    \"service_level\": \"standard-3d\"
  }"

A successful create returns HTTP 202 and a batch object. Save its id:

export BATCH_ID="batch_..."

Creation is atomic when you send an Idempotency-Key header: reusing a key with identical request body bytes returns the original batch, while reusing it with different body bytes returns 409 idempotency_conflict.

Poll the batch

Retrieve the batch until its status is completed, failed, expired, or cancelled:

Retrieve the batch
curl --fail-with-body "https://api.logits.com/v1/batches/$BATCH_ID" \
  -H "Authorization: Bearer $LOGITS_API_KEY"

The response includes request_counts, aggregate usage, and the output_file_id and error_file_id fields when those files exist. A completed batch can contain failed rows; check the error file as well as the output file.

Download the result files

Download each file whose ID is present on the batch:

Download output and error JSONL
export OUTPUT_FILE_ID="file_..."
export ERROR_FILE_ID="file_..."

curl --fail-with-body "https://api.logits.com/v1/files/$OUTPUT_FILE_ID/content" \
  -H "Authorization: Bearer $LOGITS_API_KEY" \
  --output batch-output.jsonl

curl --fail-with-body "https://api.logits.com/v1/files/$ERROR_FILE_ID/content" \
  -H "Authorization: Bearer $LOGITS_API_KEY" \
  --output batch-errors.jsonl

Output rows contain custom_id, response.status_code, the ordinary Chat Completions response in response.body, and response.request_id when available. Error rows contain custom_id and an error object with type, code, message, and an optional param. Match rows by custom_id.

Use the OpenAI Python SDK

Install the openai package and set BATCH_POLL_SECONDS to the polling interval you want. The Logits-specific service_level goes in extra_body; the other batch calls use the SDK's ordinary methods.

OpenAI Python SDK — upload, create, poll, and download
import os
import time
from pathlib import Path

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["LOGITS_API_KEY"],
    base_url="https://api.logits.com/v1",
)
poll_seconds = float(os.environ["BATCH_POLL_SECONDS"])

with Path("batch-input.jsonl").open("rb") as input_file:
    uploaded = client.files.create(file=input_file, purpose="batch_input")

batch = client.batches.create(
    input_file_id=uploaded.id,
    endpoint="/v1/chat/completions",
    completion_window="72h",
    extra_body={"service_level": "standard-3d"},
)

while batch.status in {"validating", "in_progress", "finalizing"}:
    time.sleep(poll_seconds)
    batch = client.batches.retrieve(batch.id)

if batch.output_file_id:
    output = client.files.content(batch.output_file_id)
    Path("batch-output.jsonl").write_bytes(output.read())

if batch.error_file_id:
    errors = client.files.content(batch.error_file_id)
    Path("batch-errors.jsonl").write_bytes(errors.read())

print(batch.status, batch.request_counts)

Service levels and pricing

completion_window is the batch's total window from creation to expiry. service_level selects the configured queue policy and its price multiplier. Omit both fields for standard-3d, or send one of these matching pairs:

Service levelCompletion windowPrice multiplier
express-1d24h0.65 × the online price
standard-3d (default)72h0.50 × the online price
economy-5d120h0.35 × the online price

The multiplier applies to the model's online input, cached-input, and output rates. The batch response reports the selected service_level, canonical completion_window, max_queue_seconds, price_multiplier, and expires_at. The window is a deadline, not a guarantee that every row will finish.

Statuses, cancellation, and expiry

StatusMeaning
validatingThe batch is accepted and waiting to start.
in_progressRequests are being processed. A batch with a pending cancellation remains in this state while it finishes.
finalizingThe batch is finalizing its results.
completedAll rows are terminal and any result files are ready. Individual rows can still have errors.
failedThe batch itself failed; inspect its error field.
expiredThe completion window elapsed before every row finished.
cancelledCancellation finished.

Cancel a batch that is still validating or in progress:

Cancel a batch
curl --fail-with-body -X POST "https://api.logits.com/v1/batches/$BATCH_ID/cancel" \
  -H "Authorization: Bearer $LOGITS_API_KEY"

Cancellation and expiry preserve rows that already finished. Unfinished rows become cancelled or expired errors in the error file, and any successful rows remain in the output file.

DELETE /v1/batches/{id}, which removes the record of a finished batch, is deprecated and will be removed on or after 2026-12-19. OpenAI's Batch API has no delete. To stop a batch that is still running, use POST /v1/batches/{id}/cancel; it is not a replacement for delete. A file referenced by any batch cannot be deleted; once no batch references it, delete it with DELETE /v1/files/{id}.

Retention

Batch input, output, and error files have a 30-day retention period. File metadata includes expires_at; output and error files receive their own retention period when they are created. Download results before expiry.

HTTP errors

API operation failures use the same envelope as the other Logits endpoints. param is null when the error does not belong to one parameter.

Example: invalid batch request
{
  "error": {
    "message": "Invalid batch request.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_request"
  }
}

Uploading a file over 200 MiB returns 400 file_too_large; batch input over that limit during creation returns 400 request_too_large, and more than 50,000 rows returns 400 too_many_requests. Missing resources return 404 not_found. Deleting a running batch or a referenced file returns 409 conflict. Row-level inference failures use the error JSONL described above instead of this HTTP envelope.

On this page