API Keys

Prev Next

1. Introduction

Use an API key if you want more control over how Verax accesses your data. Verax generates an API key that you can use to send your chatbot request/response data to Verax. The API key gives you programmatic access to Verax. The API key lets you avoid placing Verax between critical request/response interactions and helps you manage latency issues.  


2. Create a New API Key

To create a new API key to connect to Verax via an API, follow these steps:

  1. Navigate to the Settings > API Keys tab.

  2. Click Create API key.  

     

  3. Add a Name and Description and click Create key.

     

  4.   The API key is created. Click Download CSV to save the key data. Ensure that you save the key data, as you will not be able to see it later.


3. Use the API Key to Send Interactions to Verax

After creating an API key, you need to configure the API key to send interactions to Verax within your internal systems.

The following script is an example of a Python-based API key configuration:

import requests
import json

# Define base URL
base_url = "https://34.29.50.103:3000/api/v1" 

# Step 1: Login to get JWT token
login_url = f"{base_url}/auth/login"
login_payload = {
    "api_key_name": "my_key", # replace with your API key name  
    "api_key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx" # replace with your API key
}

try:
    login_response = requests.post(login_url, json=login_payload)
    login_response.raise_for_status()  # Raise an error for bad HTTP response
    jwt_token = login_response.json().get('accessToken') 
    if not jwt_token:
        raise ValueError("JWT token not found in response.")
except Exception as e:
    print(f"Login request failed: {e}")
    exit()

print(f"JWT Token: {jwt_token}")

# Step 2: Use the JWT token to send interaction request
interaction_url = f"{base_url}/interaction"
interaction_payload = {
    "request": "How can I access professional development resources?",
    "response": "Contact HR to learn about available professional development resources and programs that you are eligible to participate in.",
    "timestamp": "2024-09-15T05:34:13.000Z"
}

headers = {
    "Authorization": f"Bearer {jwt_token}",  # Include the token in Authorization header
    "Content-Type": "application/json"
}

try:
    interaction_response = requests.post(interaction_url, json=interaction_payload, headers=headers)
    interaction_response.raise_for_status()
    interaction_result = interaction_response.json()
    print("Response:", json.dumps(interaction_result))
except Exception as e:
    print(f"Interaction request failed: {e}")


4. Edit Existing API Key

To edit an existing API key used to connect to Verax via a API, follow these steps:

  1. Click on the three dots to the right of the key and click Edit key.  

  2. Edit the key description and click Save changes.


5. Rotate API Key

To rotate existing API keys used to connect to Verax via a API, follow these steps:

  1. Click on the three dots to the right of the key and click Rotate key.
     

  2.  Click Rotate key to confirm.

     

  3. A new API key is created.  Click Download CSV to save the key data. Ensure that you save the key data, as you will not be able to see it later. Ensure that you recommend your system to the Verax Control Center with the new API key, as the old key will no longer work.