opendunes
Video and batches
Copy page ▾

Batch status

GET /v1/batches/{id} answers where a batch stands and, once it is done, every request's answer under its custom_id.

Request

Send it with an API keyAPI keyThe key you create and send with every request that calls a model.More on API keys →. The one field goes in the address. The Batches guide runs a batch from start to end.

FieldNeededYou send
idyesthe batch's id, as POST /v1/batches answered it

Ask again every few minutes until status is completed, failed, expired or cancelled. You read only your own account's batches: any other id is a 404. The id in each sample is an example of the shape; put the one your batch was given in its place.

GET /v1/batches lists your batches, newest first, each without its results: after ?, it takes limit, 1 to 100, absent 20; after, a batch's id, to start after it; and status, to list only batches in that status. DELETE /v1/batches/{id} deletes a batch that has ended; its charge and its receipt stay.

import json
import os
import urllib.request

API_KEY = os.environ["OPENDUNES_API_KEY"]
BATCH_ID = "0d3f5a8e-6b1c-4e2a-9f7d-2c4b8e1a5f90"
ADDRESS = "https://opendunes.com/v1/batches/" + BATCH_ID

request = urllib.request.Request(
    ADDRESS,
    headers={"Authorization": "Bearer " + API_KEY},
)
with urllib.request.urlopen(request) as response:
    batch = json.load(response)

print(batch["status"], batch["request_counts"])
for result in batch["results"] or []:
    answer = result["response"]["body"]["choices"][0]["message"]["content"]
    print(result["custom_id"], answer)

Response

200 OK.

FieldHolds
idthe batch's id
objectbatch
endpointthe route its requests go to
modelthe model, lab/model
completion_window24h
statusvalidating, in_progress and finalizing while it runs, cancelling while it stops, then completed, failed, expired or cancelled once it has ended
created_atwhen it was taken, in Unix seconds
finalized_atwhen it ended, in Unix seconds; null until then
request_countstotal, completed and failed: how many requests, and how many are done
usageonce it ends: the tokens counted across every request, and cost, the charge in DADAThe Algerian dinar, the one currency the docs show.More on Balance and charges →
resultsonce it has ended: one entry per request; null until then
custom_idin each entry: the name you gave the request
responsein each entry: its answer, status_code and body, the body in the shape of the batch's endpoint
errorin an entry: why that request failed, else null. On the batch: why the whole batch failed, with its code and message

What it cost

Free. Asking for a batch is never charged. The batch itself is charged once, when it ends: the tokens of every request at the rates of the model's batch entry. usage.cost shows that charge, and a failed batch charges nothing.

Errors

error.code carries the status, and error.message says why.

StatusWhen
401the key is missing, wrong, disabled or expired
403the key is kept to other addresses
404no batch of yours has that id
409DELETE on a batch that has not ended
502DELETE: the batch service failed; ask again
504DELETE: the batch service did not answer in time; ask again

Last modified on