App runs endpoint

The App runs endpoint lets you create an app run for an AI Hub app and returns a run ID. A deployment-specific version lets you run deployments, also returning a run ID. You can then use the run ID to check the status of an app or deployment run and, when complete, get the results.

The AI Hub interface includes an API runner tool you can use to generate end-to-end code samples for running an app or deployment by API.

Run app

MethodSyntax
POSTAPI_ROOT/v2/apps/runs

Description

Run an app by its name or app ID by sending a POST request to API_ROOT/v2/apps/runs. The input for the run is specified using a batch ID or an input file path. To run deployments by API, use the Run deployment endpoint.

Any specified input or output is validated against the context set by the IB-Context header. For example, if the context is set to your community account, but the batch ID used as input for the run is stored in your organization, the call fails.
You can find an app ID by opening the app in AI Hub and clicking App details in the left panel. The app ID is also listed in the app URL, such as https://aihub.instabase.com/hub/apps/**528c36e8-ac5b-490d-a41b-7eec9c404b87**.

Request body

Parameters are required unless marked as optional.

ParameterTypeDescriptionValues
app_idstringRequired unless using app_name. The app ID of the AI Hub app through which you want to process the files.A valid app ID of a prebuilt or custom AI Hub app.
app_namestringRequired unless using app_id. The name of the AI Hub app through which you want to process the files.A valid name of a prebuilt or custom AI Hub app.
ownerstringOptional. The account that generated the app. If not specified, defaults to your AI Hub username.For custom AI Hub apps belonging to you, don’t specify a value. For public AI Hub apps published by Instabase, specify instabase.
batch_idstringRequired unless using input_dir. The batch ID of a batch created with the Batches endpoint. All files uploaded to the batch are used as input for the run.A valid integer batch ID.
input_dirstringRequired unless using batch_id. The path of the input folder in a connected drive or Instabase Drive.A complete path to the input folder. See specifying file paths.
versionstringOptional. Which version of the app to use. If not specified, defaults to the latest production version.A valid semantic version string that exists for the app.
output_workspacestringOptional. The workspace in which to run the app. The output is saved to the default drive of the specified workspace. If not defined, the default is:

- Community accounts: Runs in and saves to the personal workspace’s Instabase Drive (<USER-ID>/my-repo/Instabase Drive).

- Organization accounts: Runs in and saves to the organization’s default drive (<ORGANIZATION-ID>/<USER-ID>/<default-drive>).
A valid name of a workspace in the specified community or organization context, such as shared-workspace-accounting.
output_dirstringOptional. Defines a specific location for the output to be saved in a connected drive or Instabase drive. If defined, overrides the output_workspace value.A complete path to the output folder. See specifying file paths.
settingsdictOptional. Advanced settings for your run.
settings/runtime_configdictOptional. A dictionary containing the runtime configuration for the app run, for use in validation functions. See runtime config for details.
settings/webhook_configdictOptional. Configure the webhook URL that’s called on app run completion. See webhook parameters.
settings/webhook_config/urlstringOptional. The webhook URL to which a HTTP request is sent when the run is completed.
settings/webhook_config/headersdictOptional. Configure the headers that are sent alongside the HTTP request. The format is { "<HTTP-HEADER>": "<VALUE>"}.

Response status

StatusMeaning
200 OKRun started successfully.

Response schema

The response body is a JSON object known as a run object. The run object provides information about the run and its progress, but not the run results. You can use the run’s id to poll the Run status endpoint and the Run results endpoint.

KeyTypeDescription
idstringRun ID of the run.
statusstringStatus of the run. Possible values are COMPLETE, FAILED, CANCELLED, RUNNING, or STOPPED_AT_CHECKPOINT.
msgstringOptional. Message about the run.
start_timestampintegerWhen the run started, in Unix time.
finish_timestampintegerWhen the run finished, in Unix time. null if run is still in progress.

Examples

Request (curl)

$curl "${API_ROOT}/v2/apps/runs" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"\
> -H "Content-Type: application/json" \
> -d '{
> "batch_id": "<BATCH-ID>",
> "app_name": "<APP-NAME>"
> }'

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6result = client.apps.runs.create(app_name='<APP-NAME>',
7 batch_id='<BATCH-ID>')

Response

1{
2 "id": "<RUN-ID>",
3 "status": "RUNNING",
4 "msg": "",
5 "start_timestamp": 1709592306000,
6 "finish_timestamp": null,
7}

Run deployment

MethodSyntax
POSTAPI_ROOT/v2/aihub/deployments/<DEPLOYMENT-ID>/run

Description

Run a deployment by sending a POST request to API_ROOT/v2/aihub/deployments/<DEPLOYMENT-ID>/run, using the request URL to specify the ID of the deployment. The input for the run is specified using a batch ID or an input file path.

Any specified input or output is validated against the context set by the IB-Context header. For example, if the context is set to your community account, but the batch ID used as input for the run is stored in your organization, the call fails.
You can find a deployment’s ID by opening the deployment in AI Hub and looking at the site URL, such as https://aihub.instabase.com/deployments/**01902d6f-bb35-74cb-bd27-c09b38bbf20a**/runs.

Request body

Parameters are required unless marked as optional.

ParameterTypeDescriptionValues
batch_idstringRequired unless using input_dir. The batch ID of a batch created with the Batches endpoint. All files uploaded to the batch are used as input for the run.A valid integer batch ID.
input_dirstringRequired unless using batch_id. The path of the input folder in a connected drive or Instabase Drive.A complete path to the input folder. See specifying file paths.
output_workspacestringOptional. The workspace in which to run the app. The output is saved to the default drive of the specified workspace. If not defined, the default is:

- Community accounts: Runs in and saves to the personal workspace’s Instabase Drive (<USER-ID>/my-repo/Instabase Drive).

- Organization accounts: Runs in and saves to the organization’s default drive (<ORGANIZATION-ID>/<USER-ID>/<default-drive>).
A valid name of a workspace in the specified community or organization context, such as shared-workspace-accounting.
output_dirstringOptional. Defines a specific location for the output to be saved in a connected drive or Instabase drive. If defined, overrides the output_workspace value.A complete path to the output folder. See specifying file paths.
settingsdictOptional. Advanced settings for your run.
settings/runtime_configdictOptional. A dictionary containing the runtime configuration for the run, for use in validation functions. See runtime config for details.
settings/webhook_configdictOptional. Configure the webhook URL that’s called on run completion. See webhook parameters.
settings/webhook_config/urlstringOptional. The webhook URL to which a HTTP request is sent when the run is completed.
settings/webhook_config/headersdictOptional. Configure the headers that are sent alongside the HTTP request. The format is { "<HTTP-HEADER>": "<VALUE>"}.

Response status

StatusMeaning
202 ACCEPTEDSuccessfully initiated an asynchronous operation to run the deployment.

Response schema

The response body contains the run ID, that you can use to poll the Run status endpoint and the Run results endpoint.

KeyTypeDescription
job_idstringRun ID of the run.

Examples

Request (curl)

$curl "${API_ROOT}/v2/aihub/deployments/<DEPLOYMENT-ID>/run" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"\
> -H "Content-Type: application/json" \
> -d '{
> "batch_id": "<BATCH-ID>",
> }'

Response

1{
2 "job_id": "<RUN-ID>",
3}

Run status

MethodSyntax
GETAPI_ROOT/v2/apps/runs/<RUN-ID>

Description

Get the status of a run by sending a GET request to API_ROOT/v2/apps/runs/<RUN-ID>. The run’s id value is returned in the response of the initial run.

Request body

There is no request body. Use the request URL to specify a run id.

Response status

StatusMeaning
200 OKSuccess.

Response schema

The response body is a JSON object known as a run object. The run object provides information about the run and its progress, but not the run results. You can use the run’s id to poll the Run results endpoint.

KeyTypeDescription
idstringRun ID of the run.
statusstringStatus of the run. Possible values are COMPLETE, FAILED, CANCELLED, RUNNING, or STOPPED_AT_CHECKPOINT.
msgstringOptional. Message about the run.
start_timestampintegerWhen the run started, in Unix time.
finish_timestampintegerWhen the run finished, in Unix time. null if run is still in progress.

Examples

Request (curl)

$curl "${API_ROOT}/v2/apps/runs/<RUN-ID>" \
> -H "Authorization: Bearer ${API_TOKEN}"\
> -H "IB-Context: ${IB_CONTEXT}"

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6status = client.apps.runs.status('<RUN-ID>')

Response

1{
2 "id": "<RUN-ID>",
3 "status": "COMPLETE",
4 "msg": "Completed",
5 "start_timestamp": 1709592306000,
6 "finish_timestamp": 1709592306500,
7}

Run results

MethodSyntax
GETAPI_ROOT/v2/apps/runs/<RUN-ID>/results

Description

Get the results of a completed run by sending a GET request to API_ROOT/v2/apps/runs/<RUN-ID>/results. The run id value is returned in the response of the initial run.

You can use this endpoint to get the results of a deployment run. Use the run ID returned by the deployment run.

Query parameters

Query parameterDescription
include_review_resultsOptional. Whether to include human review details in the results. When set to true, details such as review status and edits at the run or document level and the extracted field level are included. See the include_review_results section of the response schema for details.
include_confidence_scoresOptional. Whether to include confidence scores in the results. When set to true, classification confidence scores at the run or document level and extraction confidence scores at the extracted field level are included. See the include_confidence_scores section of the response schema for details.
include_validation_resultsOptional. Whether to include validation status in the results. When set to true, validation results at the run or document level and extracted field level are included. See the include_validation_results section of the response schema for details.
include_source_infoOptional. Whether to include source information in the results. When set to true, source details such as the image path of the generated image are included in the results. See the include_source_info section of the response schema for details.
file_offsetOptional, defaults to 0. The initial file index to start returning results from.

Response status

StatusMeaning
200 OKResults successfully retrieved.

Response schema

The response body is a JSON object containing the results of the run.

KeyTypeDescription
batch_idintegerOptional. The batch ID.
fileslistA list of files processed during the run.
files/original_file_namestringThe original name of the file processed.
files/documentslistAn array containing each document within the file.
files/documents/fieldslistA list containing the extracted fields from the document, each with its field name, extracted value, and type. See <DOCUMENT-FIELD> structure below.
files/documents/class_namestringThe classification label of the document. Can be null if classification is not applicable.
files/documents/post_processed_pathslistAn array of strings, each representing a path to post-processed documents.
has_morebooleanIndicates whether additional results are available beyond those included in the current response.

For each extracted field, there is a <DOCUMENT-FIELD> object structure:

KeyTypeDescription
field_nameanyThe name of the field.
valueanyThe extracted value of the field.
typestringThe type of the field.

Depending on the included query parameters, the following information can also be included in the results.

include_review_results

The following fields are included in the response when using the include_review_results query parameter.

Run or document level:

KeyTypeDescription
review_completedbooleanIndicates if the run or document has completed review.
files/documents/review_completedbooleanIndicates if the document has been marked as reviewed.
files/documents/class_edit_historylistAn array containing the history of edits to the document’s class.
files/documents/class_edit_history/timestampstringDatetime string of the class edit history event.
files/documents/class_edit_history/user_idstringUser ID of the user who edited the class.
files/documents/class_edit_history/modificationslistList of class modifications made in this single edit history event.
files/documents/class_edit_history/modifications/messagestringMessage of class edit history modification.
The review process can include manually correcting values. The Run results endpoint doesn’t support returning the original and corrected values.

Extracted field level:

KeyTypeDescription
edit_historylistAn array containing the history of edits to the document’s field.
files/edit_history/timestampstringA datetime string of the field edit history event.
files/edit_history/user_idstringUser ID of user who edited the field’s value.
files/edit_history/modificationslistList of field modifications made in this single edit history event.
files/edit_history/modifications/messagestringMessage of field edit history modification.

include_confidence_scores

The following fields are included in the response when using the include_confidence_scores query parameter.

Run or document level:

KeyTypeDescription
files/documents/classification_confidence/ocrfloatThe classification model’s confidence to classify the document. Takes values from [0,1].

Extracted field level:

KeyTypeDescription
confidence/modelfloatThe model’s confidence in the extracted value. Takes values from [0,1].

include_validation_results

The following fields are included in the response when using the include_validation_results query parameter.

Run or document level:

KeyTypeDescription
files/validations/final_result_passbooleanIndicates if the document has passed all validation rules.

Extracted field level:

KeyTypeDescription
validations/validbooleanIndicates if the document has passed validation rules pertaining to this field.
validations/alertslistAny alerts for field-level validation rules. Populated only if the validations/valid value is false.

include_source_info

The following fields are included in the response when using the include_source_info query parameter.

Run or document level:

KeyTypeDescription
files/documents/post_processed_pathslistAn array of strings, each representing a path to post-processed documents.

Extracted field level:

KeyTypeDescription
source_coordinates/top_xfloatTop-left x coordinate of the bounding box.
source_coordinates/top_yfloatTop-left y coordinate of the bounding box.
source_coordinates/bottom_xfloatBottom-right x coordinate of the bounding box.
source_coordinates/bottom_yfloatBottom-right y coordinate of the bounding box.
source_coordinates/page_numberintegerZero-indexed page number of the bounding box.

Examples

Simple request (curl)

A simple request returns extracted field names and values:

$curl "${API_ROOT}/v2/apps/runs/<RUN-ID>/results" \
>-H "Authorization: Bearer ${API_TOKEN}"`
>-H "IB-Context: ${IB_CONTEXT}"

Simple request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6results = client.apps.runs.results('<RUN-ID>')

Response (simple request)

1{
2 "has_more": false,
3 "batch_id": "9706",
4 "files": [
5 {
6 "original_file_name": "test.png",
7 "documents": [
8 {
9 "class_name": "Wage And Tax Statement",
10 "fields": [
11 {
12 "value": "123 STREET RD ANYWHERE, USA,12345",
13 "type": "TEXT",
14 "field_name": "employers_address_and_ZIP_code"
15 }
16 ],
17 "doc_id": null
18 }
19 ]
20 },
21 {
22 "original_file_name": "test2.png",
23 "documents": [
24 {
25 "class_name": "Driver License",
26 "fields": [
27 {
28 "value": "Male",
29 "type": "TEXT",
30 "field_name": "sex"
31 }
32 ],
33 "doc_id": null
34 }
35 ]
36 }
37 ]
38}

Request with query parameters (curl)

This request includes the include_confidence_scores and include_source_info query parameters. Confidence scores and source information (coordinates) are returned:

$curl "${API_ROOT}/v2/apps/runs/<RUN-ID>/results?include_confidence_scores=true&include_source_info=true" \
> -H "Authorization: Bearer ${API_TOKEN}"`
> -H "IB-Context: ${IB_CONTEXT}"\

Request with query parameters (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6results = client.apps.runs.results('<RUN-ID>',
7 include_confidence_score=True,
8 include_source_info=True)

Response (request with query parameters)

1{
2 "has_more": false,
3 "batch_id": "9706",
4 "files": [
5 {
6 "original_file_name": "test.png",
7 "documents": [
8 {
9 "class_name": "Wage And Tax Statement",
10 "fields": [
11 {
12 "value": "123 STREET RD ANYWHERE, USA,12345",
13 "type": "TEXT",
14 "confidence": {
15 "model": 0.59005505
16 },
17 "source_coordinates": [
18 {
19 "top_x": 36.0,
20 "top_y": 181.0,
21 "bottom_x": 84.0,
22 "bottom_y": 212.0,
23 "page_number": 0
24 },
25 {
26 "top_x": 90.0,
27 "top_y": 182.0,
28 "bottom_x": 198.0,
29 "bottom_y": 211.0,
30 "page_number": 0
31 }
32 ],
33 "field_name": "employers_address_and_ZIP_code"
34 }
35 ],
36 "post_processed_paths": [
37 "instabase-org/orguser/fs/S3 Drive/app-runs/dd97-42cb-8b8e-28a63066887e/4180-8508-b103afb67185/s1_process_files/images/test.png.PNG"
38 ],
39 "doc_id": null
40 }
41 ]
42 },
43 {
44 "original_file_name": "test2.png",
45 "documents": [
46 {
47 "class_name": "Driver License",
48 "fields": [
49 {
50 "value": "Male",
51 "type": "TEXT",
52 "confidence": {
53 "model": 0.691
54 },
55 "source_coordinates": [],
56 "field_name": "sex"
57 }
58 ],
59 "post_processed_paths": [
60 "instabase-org/orguser/fs/S3 Drive/app-runs/dd97-42cb-8b8e-28a63066887e/4180-8508-b103afb67185/s1_process_files/images/test2.png.PNG"
61 ],
62 "doc_id": null
63 }
64 ]
65 }
66 ]
67}

Runtime config

You can use the runtime_config setting to specify key-value pairs to pass into the run at runtime. These values are propagated to downstream processes and can be referenced in validation functions.

For example, if your validation function’s behavior varies based on time of year, you might use runtime_config to pass in the current date, for example:

1{
2 "current_date": "06/01/2024",
3 ...
4}

Webhook parameters

You can use the webhook_config setting to ensure your application is notified when a run completes. AI Hub POSTs JSON-encoded data of the format below to the webhook endpoint:

$# body
>{
>"status": <string>,
>"msg": <string>,
>"job_id": <string>,
>"input_dir": <string>,
>"output": <string>
>}

The response body contains the following fields:

  • status: "OK" | "ERROR"

  • msg: (optional) Error message. Present only if status is ERROR.

  • job_id: A unique identifier for the run.

  • input_dir: Input directory.

  • output: The full path to the root output folder.

To acknowledge receipt of the event, your endpoint must return a 2xx HTTP status code. All response codes outside this range, including 3xx codes, indicate to AI Hub that you did not receive the event.

If AI Hub does not receive a 2xx HTTP status code, the notification attempt is repeated up to 7 times.

Specifying file paths

When running an app using the v2/apps/runs endpoint, there are two methods to specify the app’s input:

  • Batch: Create a batch using the Batches endpoint, upload files from your local filesystem, then use the batch_id parameter to specify the batch. All files in the batch are processed.

  • Connected drive: Use the input_dir parameter to specify a file path to an input folder in a connected drive. All files in the input folder are processed.

When specifying a file path in a connected drive, the format varies if you have a community or organization account.

  • Community account: /<USER-ID>/my-repo/fs/<DRIVE-NAME>/<FOLDER>/

  • Organization account: /<ORGANIZATION-ID>/<WORKSPACE>/fs/<DRIVE-NAME>/<FOLDER>/

ValueDescription
<USER-ID>Your user ID. You can find this on the Settings > APIs page, under User ID.
<ORGANIZATION-ID>Your organization ID. You can find this on the Settings > APIs page, under Organization ID.
<WORKSPACE>This value reflects the workspace name (shared workspaces) or your user ID (personal workspaces). You can find this value by selecting the workspace in Workspaces, then looking at the workspace query string in the URL.

For example:
- https://aihub.instabase.com/workspaces/create?workspace=New_Workspace
- https://aihub.instabase.com/workspaces/create?workspace=john.doe_gmail.com
<DRIVE-NAME>The drive’s display name. You can see a drive’s display name in by opening the Data Sources panel in a workspace where the drive is connected. For example, the Instabase Drive’s display name is Instabase Drive.
<FOLDER>The exact name of the folder, as displayed in the filesystem.
Was this page helpful?