Batches endpoint
The Batches endpoint lets you create and manipulate batches. A batch is a RESTful object that contains a user-defined list of files. A batch can be used as input for an AI Hub app, allowing for batch processing of all files you’ve added to the batch. Batches are useful for logically grouping files that you want to easily and repeatedly use as an app’s input.
API_ROOT
, API_TOKEN
, and IB_CONTEXT
values as variables. If you don’t set up these variables, define them in the request.- For Python request examples, it’s assumed you installed the AI Hub SDK. All examples also include lines initializing the API client, with values you must define.
- All endpoints support the IB-Context header. Organization members must set the
IB-Context
header as their organization ID to complete the request with their organization account. While optional, it’s a best practice to include the IB-Context
header in all requests.- All endpoints use the standard HTTP response status codes. For each endpoint, some common status codes are listed.
Create batch
Description
Create a new batch by sending a POST
request to API_ROOT/v2/batches
. You must upload files to the batch separately.
Commercial & Enterprise For organization members, a batch is stored in the default drive of the workspace specified when creating the batch. If the default drive changes, but is still connected, you can still use the batch as input for running an app. However, you can’t upload any additional files to the batch. If the default drive is disconnected, you can’t use batches stored on that drive as input for any app run.
Request body
Response status
Response schema
Examples
Request (curl)
Request (Python SDK)
Response
Upload file to batch
Description
Send a PUT
request to API_ROOT/v2/batches/<BATCH-ID>/files/<FILENAME>
to upload a file to a batch, or to update the contents of a previously uploaded file in a batch.
In the request URL, <BATCH-ID>
is the batch’s ID and <FILENAME>
is a user-defined name for the file. The file name must include the file extension.
Files can be uploaded one at a time and the suggested max size for each file is 10 MB. For larger files, use the Multipart file upload endpoint.
Request headers
Request body
The raw contents of file to be uploaded. See the example request, being sure to define the <LOCAL_FILEPATH>
with the full path to the file in the machine that’s running the script.
Response status
Response schema
There is no response body.
Examples
Request (curl)
Where <LOCAL_FILEPATH>
is the full path to the file in the machine that’s running the script.
Request (Python SDK)
Get batch information
Description
Retrieve information about a batch by sending a GET
request to API_ROOT/v2/batches/<BATCH-ID>
.
Request body
There is no request body. Use the request URL to provide the batch ID (BATCH-ID
).
Response status
Response schema
Examples
Request (curl)
Request (Python SDK)
Response
List batches
Description
Return a list of batches by sending a GET
request to API_ROOT/v2/batches
. You can use query parameters to filter results.
Query parameters
Request body
There is no request body. Use the request URL’s query parameters to filter the list of batches.
Response status
Response schema
Examples
Request (curl)
Request (Python SDK)
Response
Delete batch
Description
Delete a batch and all of its files by sending a DELETE
request to API_ROOT/v2/batches/<BATCH-ID>
. This is an asynchronous operation that must be checked for completion. See details on polling jobs.
Specify the <BATCH-ID>
in the URL to identify the batch to be deleted.
Request body
There is no request body. Use the request URL to specify the batch to be deleted.
Response status
Response schema
Examples
Request (curl)
Request (Python SDK)
Response
Delete file from batch
Description
Delete a file from a batch by sending this DELETE request. Use <BATCH-ID>
and <FILENAME>
in the request URL to specify the file to be deleted.
Request body
There is no request body. Use the request URL to specify the file to be deleted.
Response status
Response headers
Response schema
There is no response body.
Examples
Request (curl)
Request (Python SDK)
Poll batches job
Description
Use this endpoint to poll asynchronous jobs created when deleting a batch or deleting a file from a batch. In the request URL, <JOB_ID>
is the job_id
value returned by a Delete batch request or the Location
header value returned by a Delete file from a batch request.
Request body
There is no request body. Use the request URL to specify the job to poll.
Response status
Response schema
Multipart file upload
To upload a file larger than 10 MB in size to a batch, you must use multipart upload. Multipart upload involves three endpoints and the following steps:
-
Start a multipart upload session, specifying the batch ID, file name, and file size. This call returns a session ID and maximum
part_size
to reference when uploading each part. -
Split the file into parts, according to the specified
part_size
, and upload each part individually. -
When all parts are uploaded, commit the session.
Multipart upload example request (Python)
Where <LOCAL_FILEPATH>
is the full path to the file in the machine that’s running the script.
Start multipart upload session
Description
Start a multipart upload session. Use this endpoint when you need to upload a file larger than 10 MB to a batch.
Request body
Response status
Response headers
Response schema
Examples
See the full multipart upload request.
Upload part to session
Description
Upload part of a file to the multipart upload session, where each part’s size matches the part_size
returned by the Start multipart upload session call. Each part should match the part_size
, except for the final part, which can be smaller than the part_size
.
<SESSION_ID>
can be obtained in the Location header from the Start multipart upload session response, and <PART_NUM>
is an increasing consecutive integer sequence starting at 1
for every part uploaded.
Request body
Raw content of the part to be uploaded.
Response status
Response schema
Examples
See the full multipart upload request.
Commit session
Description
After uploading all parts to a multipart upload session, use this endpoint to commit and close the multipart upload session, or to cancel the session.
Request body
Response status
Response schema
There is no response body.
Examples
See the full multipart upload request.