Batch
Upload a file of requests. Get all results within 24 hours.
Batch uses the OpenAI Batch API. Change only base_url and api_key in the OpenAI SDK.
1. Prepare the file
Write a .jsonl file with one request per line:
{"custom_id": "req-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "DeepSeek-V4-Flash-0731", "messages": [{"role": "user", "content": "What is 2 + 2?"}], "max_tokens": 16}}
{"custom_id": "req-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "DeepSeek-V4-Flash-0731", "messages": [{"role": "user", "content": "What is 3 + 3?"}], "max_tokens": 16}}custom_id: unique in the file, max 64 characters.url:/v1/chat/completionsor/v1/completions. Use the same value on all lines.body.model: use the same model on all lines.- Do not set
streamorservice_tier. - Max 50,000 lines and 200 MB per file.
Accepted: .jsonl, and .jsonl.gz (gzip). Not supported: CSV, Parquet, spreadsheets, PDF, JSON arrays, zstd, xz, bzip2, zip.
To send images or PDFs, put them inside body as you do for one request. See Images and PDFs.
2. Upload the file
curl https://api.qloud.sh/v1/files \
-H "Authorization: Bearer $QLOUD_API_KEY" \
-F purpose=batch \
-F file=@requests.jsonlIf a line is not correct, the upload fails. The error message gives the line number.
3. Create the batch
curl https://api.qloud.sh/v1/batches \
-H "Authorization: Bearer $QLOUD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input_file_id": "file-...", "endpoint": "/v1/chat/completions", "completion_window": "24h"}'completion_window is "24h" (Batch price) or "4h" (Async price).
The API checks all requests and your credit before it accepts the batch. If one request fails the check, the API refuses the whole batch. You can run max 20 batches at the same time.
For a small batch, you can send the lines in a requests array instead of input_file_id.
4. Track progress
import time
while batch.status not in ("completed", "cancelled"):
time.sleep(60)
batch = client.batches.retrieve(batch.id)
print(batch.status, batch.request_counts)Status is in_progress, completed, cancelling or cancelled. To get a call instead of polling, use a webhook.
5. Get the results
output_file_id has the successful results. error_file_id has the failed requests. Failed requests are not billed.
curl https://api.qloud.sh/v1/files/$OUTPUT_FILE_ID/content \
-H "Authorization: Bearer $QLOUD_API_KEY" -o results.jsonlResults are not in input order. Use custom_id to match them.
You can download results while the batch runs. Use ?offset= with the value of the x-last-line header to get only new lines.
6. Cancel a batch
curl -X POST https://api.qloud.sh/v1/batches/$BATCH_ID/cancel \
-H "Authorization: Bearer $QLOUD_API_KEY"Requests that have not started are cancelled at no cost. Running requests continue and are billed.
7. List batches
GET /v1/batches returns your batches, newest first. Use limit (max 100) and after to page.