Authentication

To make HTTP requests, you must include the API key in the header of each request.

Prerequisites

To use the platform, you need an API key:

1

If you don’t have an account, sign up for a free account.

2

Go to the API Key page.

3

Select the Copy icon next to your key.

Procedure

1

Verify that the required packages are installed on your system. If necessary, install the following packages:

Install the requests package by entering the following command:

$python -m pip install requests
2

Define the URL of the API and the specific endpoint for your request.

3

Create the necessary headers for authentication.

4

Prepare the data payload for your API request.

5

Send the API request and process the response.

Below are complete code examples for Python and Node.js, integrating all the steps outlined above:

1import requests
2
3# Step 2: Define the API URL and the specific endpoint
4API_URL = "https://api.twelvelabs.io/v1.3"
5INDEXES_URL = f"{API_URL}/indexes"
6
7# Step 3: Create the necessary headers for authentication
8headers = {
9 "x-api-key": "<YOUR_API_KEY>"
10}
11
12# Step 4: Prepare the data payload for your API request
13INDEX_NAME = "<YOUR_INDEX_NAME>"
14data = {
15 "models": [
16 {
17 "model_name": "marengo2.7",
18 "model_options": ["visual", "audio"]
19 }
20 ],
21 "index_name": INDEX_NAME
22}
23
24# Step 5: Send the API request and process the response
25response = requests.post(INDEXES_URL, headers=headers, json=data)
26print(f"Status code: {response.status_code}")
27if response.status_code == 201:
28 print(response.json())
29else:
30 print("Error:", response.json())