API authorization set up

When on API keys page, scroll down and you will see the Region code and your Project Id.

To generate your Relevance API key, click on "Create new secret key", with the role "Admin". Click on "Generate API key". Copy the values shown on the modal.

  • Authorization token
  • API key
  • Region
  • Project

Authorization tokens are formed by combining Project Id:API Key.

Either directly copy the Authorization token from the API page or use the Project id and API key combination as shown in the snippet below:

project_id = "YOUR_PROJECT_ID" # Can be found in the API Keys page
authorization_token = f"{YOUR_PROJECT_ID}:{YOUR_API_KEY}"   # Both values can be found in the API Keys page
region = "YOUR_REGION"       # Can be found in the API Keys page
base_url = f"https://api-{region}.stack.tryrelevance.com/latest"
headers = {
  "Authorization": authorization_token,
}

Agent Id

Currently, the easiest way to access Agent Ids is from URLs. For instance, when on the "Edit agent" page, the last piece after project id and before /edit shows the Agent Id. The URL is structured as

https://app.relevanceai.com/agents/{region}/{project_id}/{agent_id}/edit

agent_id = "YOUR_AGENT_ID"

Conversation Id

Currently, the easiest way to access a conversation Id is from the page URL. Click on the target conversation. In the URL, the last piece after the Agent id and before ?studioId= shows the Conversation Id. The URL is structured as

https://app.relevanceai.com/agents/{region}/{project_id}/{agent_id}/{conversation_id}?studioId=agent_....

API call to list all conversation Ids


filters = [
  {
    "filter_type": "exact_match",
    "field": "type",
    "condition_value": "conversation",
  },
  {
    "filter_type": "exact_match",
    "field": "conversation.agent_id",
    "condition_value": agent_id
  }
]
# Send the POST request
response = requests.post(
  base_url+"/knowledge/sets/list", 
  headers=headers, 
  json={
    "filters":filters, "include_hidden":True
  }
)

response.json()["results"]

The output is a list of dictionaries. All conversation Ids associated with the target agent can be found under the knowledge_set field. In the sample below, 041157d4-61bb-4855-8202-cdf8fab7202a is a conversation that can be used in the next step.

'knowledge_set': '041157d4-61bb-4855-8202-cdf8fab7202a'

API call to list all conversations using the conversation Id(s)


# Send the POST request
response = requests.post(
  base_url + "knowledge/list", 
  headers=headers, 
  json={
    "knowledge_set": conversation_id,
    "filters": [],
    "sort": [
      {
        "insert_date_": "desc"
      }
    ]
  }
)

conversation_messages = response.json()["results"]