Skip to content
GitHub Login

Batch

Run asynchronous batch jobs with the Batch API and Files API.

The Batch API lets you run large numbers of requests asynchronously without real-time responses. It is compatible with the OpenAI Batch API: same JSONL format, Files API for uploads, and batch create/retrieve/cancel/list endpoints. Use https://api.8080.io and your 8080 API key in place of OpenAI’s base URL and key.

Batches complete within the chosen completion window (e.g., 24 hours). Input files can contain up to 50,000 requests and be up to 200 MB.

  1. Each line must be a single JSON object with:

    FieldTypeDescription
    custom_idstringYour unique ID for this request (used to match results).
    methodstringHTTP method, e.g., "POST".
    urlstringAPI path, e.g., "/v1/chat/completions".
    bodyobjectRequest body for that endpoint (same as the underlying API).

    All requests in one file must target the same endpoint. The body must match what the endpoint expects (e.g., model, messages for chat completions).

    Save as batch_input.jsonl:

    {"custom_id": "req-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "8080/taalas/llama3.1-8b-instruct", "messages": [{"role": "user", "content": "Say hello in one word."}], "max_tokens": 50}}
    {"custom_id": "req-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "8080/taalas/llama3.1-8b-instruct", "messages": [{"role": "user", "content": "What is 2+2?"}], "max_tokens": 50}}
    {"custom_id": "req-3", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "8080/taalas/llama3.1-8b-instruct", "messages": [{"role": "user", "content": "Name a color."}], "max_tokens": 50}}

    Each line is one request. Use custom_id later to map output lines back to your inputs (output order may not match input order).

  2. Upload the JSONL file with purpose batch so it can be used as batch input.

    curl https://api.8080.io/v1/files \
    -H "Authorization: Bearer $_8080_API_KEY" \
    -F purpose="batch" \
    -F file="@batch_input.jsonl"

    The response includes an id (e.g., ae1a17d0-...). Use this as input_file_id when creating the batch.

  3. Request: POST /v1/batches

    ParameterTypeRequiredDescription
    input_file_idstringYesFile ID from the upload step.
    endpointstringYesEndpoint for all requests in the file, e.g., "/v1/chat/completions".
    completion_windowstringYesTime window to complete the batch; e.g., "24h" if supported.
    metadataobjectNoKey-value pairs (e.g., for labeling).
    output_expires_afterobjectNoExpiration for output/error files (e.g., {"anchor": "created_at", "seconds": 86400}).
    curl https://api.8080.io/v1/batches \
    -H "Authorization: Bearer $_8080_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "input_file_id": "ae1a17d0-...",
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h"
    }'

    The response is a batch object with id, status (e.g., validating), input_file_id, output_file_id, error_file_id (often null until the batch progresses), and timestamps.

  4. Request: GET /v1/batches/{batch_id}

    Poll this until status is a terminal state.

    curl https://api.8080.io/v1/batches/batch_abc123 \
    -H "Authorization: Bearer $_8080_API_KEY"
    StatusDescription
    validatingInput file is being validated.
    failedValidation failed; see errors on the batch.
    in_progressBatch is running.
    finalizingBatch finished; results are being prepared.
    completedDone; use output_file_id (and optionally error_file_id) to download.
    expiredDid not finish within the completion window.
    cancellingCancel requested; waiting for in-flight work.
    cancelledBatch was cancelled.

    When status is completed, output_file_id points to a JSONL file of successful results, and error_file_id (if set) points to a JSONL file of failed requests.

  5. Request: GET /v1/files/{file_id}/content

    Use the batch’s output_file_id and error_file_id from the completed batch object.

    # Output (successful requests)
    curl https://api.8080.io/v1/files/RESULTS_FILE_ID/content \
    -H "Authorization: Bearer $_8080_API_KEY" \
    -o batch_output.jsonl
    # Errors (failed requests)
    curl https://api.8080.io/v1/files/ERROR_FILE_ID/content \
    -H "Authorization: Bearer $_8080_API_KEY" \
    -o batch_errors.jsonl

    One line per successful request. Each line is a JSON object with:

    FieldDescription
    idBatch request ID.
    custom_idThe custom_id from your input line.
    responseObject with status_code, request_id, and body (the API response body).
    errornull for success lines.

    Example output line (chat completions):

    {"id": "batch_req_abc", "custom_id": "req-1", "response": {"status_code": 200, "request_id": "req_xyz", "body": {"id": "chatcmpl-...", "object": "chat.completion", "choices": [{"index": 0, "message": {"role": "assistant", "content": "Hello."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 12, "completion_tokens": 1, "total_tokens": 13}}}, "error": null}

    Match results to inputs using custom_id; do not rely on line order.

    One line per failed request. Each line has id, custom_id, response: null, and error with code and message, for example:

    {"id": "batch_req_456", "custom_id": "req-2", "response": null, "error": {"code": "invalid_request", "message": "Invalid model."}}

GET /v1/batches (optional query: limit, after for pagination).

curl https://api.8080.io/v1/batches?limit=20 \
-H "Authorization: Bearer $_8080_API_KEY"

POST /v1/batches/{batch_id}/cancel

curl https://api.8080.io/v1/batches/batch_abc123/cancel \
-H "Authorization: Bearer $_8080_API_KEY" \
-X POST

After cancelling, status moves to cancelling then cancelled (may take a few minutes).