Authentication
The API uses keys for authentication, and your key is similar to a password. Avoid distributing your API key to other users, or hard-coding it. Generate a new key whenever you think your account may have been compromised.
For security reasons, your API key automatically expires every 90 days. When your key has expired, you must generate a new one to continue using the API.
Notes
- If your policies require you to rotate keys more often, you can always generate a new key.
- If you want to pause using the API without deleting your account, you can revoke your API key.
Before you begin, sign up for a free account, or if you already have one, sign in.
The process of managing your API key can be divided into the following tasks:
- Retrieve your API key: Go to the API Key page, and select the Copy icon to the right of the key to copy it to your clipboard.
- Generate a new API key: Go to the API Key page, and then select the Regenerate Key button under the API Key section.
- Revoke an API key: Go to the API Key page, and then select the Revoke Key button under the API Key section.
You can interact with the platform using an available SDK or an HTTP client like requests
or axios
. Follow the steps in one of the sections below, depending on your use case.
Use an SDK
If you are using an SDK client, provide your API key when instantiating the client.
Prerequisites
- You have an API key.
Procedure
-
Install the
twelvelabs
package: -
Import the SDK into your application:
-
Instantiate the SDK client, replacing the placeholder surrounded by
<>
with your API key: -
Use the SDK to interact with the platform. The example code below demonstrates creating an index:
If your API key is valid, the response should look similar to the following:
If your API key has expired or is invalid, the response should look similar to the following:
Use an HTTP client
If you are making HTTP requests using clients such as requests
or axios
, include the API key in the header of each HTTP request.
Prerequisites
- You have an API key.
- The URL of the API service is stored in a variable named
API_URL
. For details about retrieving the URL of the API service, see the Call an endpoint section.
Procedure
-
Depending on the programming language you are using, ensure that the required packages are installed.
- For Python: Install the
requests
package by entering the following command:Python - For Node.js: Install the
axios
andform-data
packages by entering the following command:Node.js
- For Python: Install the
-
Construct the headers for the HTTP request, replacing the placeholder surrounded by
<>
with your API key: -
Declare the
/indexes
endpoint: -
Create a new index by calling the
POST
method of the/indexes
endpoint, passing thex-api-key
header parameter with the value of your API key.If your API key is valid, the response should look similar to the following:
JSONIf your API key has expired or is invalid, the response should look similar to the following:
JSON