Batches API: run bulk requests and reconcile the results
Run uploaded JSONL requests through UplinkSwitch batches, follow counts and result files, and understand the 24-hour window, discount and cancellation rules.
A batch turns an uploaded request file into background work. The client tracks one job while the gateway executes its lines under the creating key’s permissions and limits. Use this workflow for prepared work that can complete within a window, and reconcile both the successful output and error files afterwards.
Prepare the input before starting execution
Upload JSONL through POST /v1/files with purpose: batch. Upload validates and stores the request lines without running or charging them. The files reference covers the multipart form, line format and limits.
Then call POST /v1/batches with a JSON object:
| Field | Required | Meaning |
|---|---|---|
input_file_id | Yes | String identifying the uploaded batch-purpose file. |
endpoint | Yes | One of the routes listed below; every line’s url must match it. |
completion_window | Yes | The only declared value is 24h. |
metadata | No | An object of up to 16 string values, returned with the batch. |
The endpoint enum contains /v1/chat/completions, /v1/completions, /v1/embeddings, /v1/responses and /v1/moderations. This is a validation enum, not an availability claim. Check the public catalog before selecting a moderation workload.
Creation returns HTTP 200 with a batch object. Use an ordinary API key in UPLINKSWITCH_API_KEY for this illustrative call. Replace the file identifier with a real uploaded input. Running it begins billable work.
curl --fail-with-body -X POST 'https://api.uplinkswitch.com/v1/batches' \
-H "Authorization: Bearer ${UPLINKSWITCH_API_KEY}" \
-H 'Content-Type: application/json' \
--data '{"input_file_id":"file-REPLACE_WITH_UPLOADED_ID","endpoint":"/v1/embeddings","completion_window":"24h","metadata":{"job":"knowledge-index"}}'Execution and cost follow each request line
The OpenAPI operation specifies catalog pricing with a half-price batch discount on each line. The discounted charge appears in the receipt and usage log. Holds apply against balance as lines execute, and the creating key’s budget and limits still apply. Log export provides a separate way to examine recorded usage.
The description says a few lines run concurrently per organization. For an exact concurrency count, a caller-controlled concurrency field or a guaranteed finish time inside the window, the contract leaves those details unspecified. Lines still unrun at the end of the window enter the error file with batch_expired.
Track status and counts
GET /v1/batches/{batch_id} returns a batch owned by the organization. The required members are id, object, endpoint, input_file_id, completion_window, status, created_at, expires_at and request_counts.
| Member | Documented shape |
|---|---|
id | batch_ followed by 24 lowercase hex characters. |
object | The constant batch. |
status | validating, in_progress, finalizing, completed, failed, expired, cancelling or cancelled. |
request_counts | Object requiring integer total, completed and failed. |
output_file_id | Optional nullable string, set at completion when any line answered 2xx. |
error_file_id | Optional nullable string, set at completion when any line failed or expired. |
errors, metadata | Optional objects that can also be null. |
Additional nullable integer timestamps describe entry into the processing and terminal states. For the units of batch timestamps, the OpenAPI document does not say. Do not infer seconds from the neighboring files API, which does specify seconds.
An HTTP 200 management read does not mean every request succeeded. Inspect the counts and state, then retrieve any returned result identifiers through GET /v1/files/{file_id}/content. Successful 2xx lines go to the output file; other outcomes go to the error file.
List and cancel
GET /v1/batches lists jobs newest first. Its description supports limit, default 20 and maximum 100, and an after batch ID for continuation. These query controls are documented in prose, without formal parameter schemas. The response includes object: list, data, has_more, first_id and last_id.
POST /v1/batches/{batch_id}/cancel has no declared body. It leaves unstarted lines out, retains completed results and lets running requests finish. The state remains cancelling until those requests end, then becomes cancelled. A finished batch cannot be cancelled.
Authentication and errors
All four batch operations inherit API-key authentication. The batch operations document API-key authentication; console-session acceptance is not specified. SDK setup covers the connection guide.
| Operation | Declared failures |
|---|---|
| Create | 400 invalid_request for unsupported endpoint/window or a mismatched line URL; 401 invalid_api_key; 404 not_found for an input outside the organization or absent there. |
| List | 401 invalid_api_key. |
| Retrieve | 401 invalid_api_key; 404 not_found. |
| Cancel | 401 invalid_api_key; 404 not_found; 409 batch_not_cancellable. |
These are batch-management errors. Individual inference failures are reported in the result files and should be reconciled separately.