This page contains all the required steps to allow longer runtime on your desired Tool.

Requirements

Region and Authorization token

Follow the instruction on the API keys page to fetch your authorization token and your account region.

region = "REGION CODE AS INSTRUCTED in the API keys page"
authorization_token = "AUTHORIZATION TOKEN AS INSTRUCTED in the API keys page"

Studio ID

There are different ways to find the studio ID of a Tool. The easiest way is to use the URL. For example when on the Tool and Use tab, the component before use/app and after project ID is the studio ID. The string below shows the URL structure:

https://app.relevanceai.com/notebook/<Region>/<Project ID>/<Studio ID>/use/app

studio_id = "STUDIO ID AS INSTRUCTED ABOVE"

Tool inputs

A Get API call to the URL below, will provide you with the Tool information.

https://api-<Region>.stack.tryrelevance.com/latest/studios/list_public?filters=${JSON.stringify([{ filter_type: 'exact_match', field: 'title', condition_value: <ToolTitle>}])}
Tool title can be found on top of the page and s the name assigned to the Tool.
import requests
import json

tool_title = "xxxxxxxxxx"
headers = {"Authorization": authorization_token}

filters = json.dumps([{ "filter_type": 'exact_match', "field": 'title', "condition_value": tool_title}])
url = f"https://api-{region}.stack.tryrelevance.com/latest/studios/list_public?filters={filters}"

tool_info = requests.get(url, headers=headers).json()["results"][0]
tool_inputs = tool_info["params_schema"]["properties"]

Start long running tool

Provide studio_id in the code below to trigger a task and check the progress:

  • Synchronous triggers last for 30 seconds
  • Asynchronous triggers last for 15 minutes
# Start long running tool
url = f"https://api-{region}.stack.tryrelevance.com/latest/studios/{studio_id}/trigger_async"
headers = {
    "Authorization": authorization_token,
    "Content-Type": "application/json"
}
payload = {"params":tool_inputs}
response = requests.post(url, headers=headers, json=payload)

# Extract the tools job id, so we can check its progress
job_id = response.json()['job_id']

# Every 5 seconds, check if the tool had finished by calling the poll endpoint
poll_url = f"https://api-{region}.stack.tryrelevance.com/latest/studios/{studio_id}/async_poll/{job_id}?ending_update_only=true"
tool_output = {}
for _ in range(100):
  poll_response = requests.get(poll_url,headers=headers).json()
  print(poll_response)
  if poll_response['type'] == "complete" or poll_response['type'] == 'failed':
    print(poll_response)
    tool_output = poll_response["updates"][0]["output"]["output"]
    break
  time.sleep(5)

# This is the tools output
print('Tool-output',tool_output)