Description
This endpoint provides a single-use token for client-side authentication. Each token has a configurable Time-To-Live (TTL) and expires automatically if unused. The default TTL is 60 seconds, with a maximum allowable duration of 5 minutes.
Query Parameters
Name | Required | Type | Description |
---|
ttl | No | integer | Token Time-To-Live in seconds (default: 60, max: 300) |
Authentication
No authentication required for this endpoint.
Example Request
curl --request POST \
--url https://aitutor-api.vercel.app/api/v1/chat/token \
--header 'Authorization: Bearer YOUR-KEY-HERE' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"chatbotId": "CHATBOT-ID",
"sessionId": "RANDOM-STRING"
}'
Example Request with Custom TTL
curl --request GET \
--url "https://aitutor-api.vercel.app/api/v1/chat/token?ttl=300" \
--header 'accept: application/json'
Success Response
{
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_in": 60
}
Error Responses
{
"success": false,
"error": {
"message": "Invalid TTL value. Must be between 1 and 300 seconds",
"code": "invalid_ttl"
}
}
{
"success": false,
"error": {
"message": "Token generation failed",
"code": "token_generation_failed"
}
}
Notes
The token is single-use and can only be used once for workflow execution
Tokens automatically expire after their TTL period
This endpoint is publicly accessible as it generates secure, time-limited tokens
Unused tokens do not count against your API quota
Code Examples
import requests
url = "https://aitutor-api.vercel.app/api/v1/chat/token"
headers = {
"accept": "application/json"
}
response = requests.get(url, headers=headers)
print(response.json())
Node.js
const axios = require('axios');
const url = 'https://aitutor-api.vercel.app/api/api/v1/chat/token';
const headers = {
'accept': 'application/json'
};
axios.get(url, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));