Generate session token
Get credentials to start a voice or chat session with an agent. Specify agent_id and optionally the agent version, transport (websocket or webrtc), opening message, prompt, chat access, caller ID, and custom variables.
curl --request POST \
--url https://api.vatel.ai/v1/session-token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"version_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"chat_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"caller_id": "<string>",
"first_message": "<string>",
"prompt": "<string>",
"chat": true,
"variables": [
{
"key": "<string>",
"value": "<string>"
}
]
}
'import requests
url = "https://api.vatel.ai/v1/session-token"
payload = {
"agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"version_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"chat_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"caller_id": "<string>",
"first_message": "<string>",
"prompt": "<string>",
"chat": True,
"variables": [
{
"key": "<string>",
"value": "<string>"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
version_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
chat_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
caller_id: '<string>',
first_message: '<string>',
prompt: '<string>',
chat: true,
variables: [{key: '<string>', value: '<string>'}]
})
};
fetch('https://api.vatel.ai/v1/session-token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.vatel.ai/v1/session-token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'version_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'chat_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'caller_id' => '<string>',
'first_message' => '<string>',
'prompt' => '<string>',
'chat' => true,
'variables' => [
[
'key' => '<string>',
'value' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.vatel.ai/v1/session-token"
payload := strings.NewReader("{\n \"agent_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"version_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"chat_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"caller_id\": \"<string>\",\n \"first_message\": \"<string>\",\n \"prompt\": \"<string>\",\n \"chat\": true,\n \"variables\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.vatel.ai/v1/session-token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"version_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"chat_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"caller_id\": \"<string>\",\n \"first_message\": \"<string>\",\n \"prompt\": \"<string>\",\n \"chat\": true,\n \"variables\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.vatel.ai/v1/session-token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"version_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"chat_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"caller_id\": \"<string>\",\n \"first_message\": \"<string>\",\n \"prompt\": \"<string>\",\n \"chat\": true,\n \"variables\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"token": "<string>",
"room": "<string>",
"identity": "<string>",
"url": "<string>",
"webrtc_token": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}Authorizations
Send your organization API key as Authorization: Bearer <key>.
Body
UUID of the agent that will run this voice session.
Agent version to use. If omitted, the active published version is used.
Existing chat to continue in this session.
Optional caller identifier stored as the call's party number. Defaults to api-client for WebSocket sessions and the LiveKit participant identity for WebRTC.
websocket for voice over the platform WebSocket API (default). webrtc for WebRTC; the response includes room connection details.
websocket, webrtc Opening line the agent uses for this session.
System instructions for the agent for this session.
Also allow access to the chat API for this session.
Custom key-value data available to the agent in this session.
Show child attributes
Show child attributes
Response
Session credentials.
Connection credentials for the session.
Credential for voice WebSocket, WebRTC setup, or chat API as applicable.
Room name for WebRTC. Returned when transport is webrtc.
Your participant id for WebRTC. Returned when transport is webrtc.
Media server URL for WebRTC. Returned when transport is webrtc.
Credential to join the WebRTC media room. Returned when transport is webrtc.
curl --request POST \
--url https://api.vatel.ai/v1/session-token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"version_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"chat_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"caller_id": "<string>",
"first_message": "<string>",
"prompt": "<string>",
"chat": true,
"variables": [
{
"key": "<string>",
"value": "<string>"
}
]
}
'import requests
url = "https://api.vatel.ai/v1/session-token"
payload = {
"agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"version_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"chat_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"caller_id": "<string>",
"first_message": "<string>",
"prompt": "<string>",
"chat": True,
"variables": [
{
"key": "<string>",
"value": "<string>"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
version_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
chat_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
caller_id: '<string>',
first_message: '<string>',
prompt: '<string>',
chat: true,
variables: [{key: '<string>', value: '<string>'}]
})
};
fetch('https://api.vatel.ai/v1/session-token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.vatel.ai/v1/session-token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'version_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'chat_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'caller_id' => '<string>',
'first_message' => '<string>',
'prompt' => '<string>',
'chat' => true,
'variables' => [
[
'key' => '<string>',
'value' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.vatel.ai/v1/session-token"
payload := strings.NewReader("{\n \"agent_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"version_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"chat_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"caller_id\": \"<string>\",\n \"first_message\": \"<string>\",\n \"prompt\": \"<string>\",\n \"chat\": true,\n \"variables\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.vatel.ai/v1/session-token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"version_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"chat_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"caller_id\": \"<string>\",\n \"first_message\": \"<string>\",\n \"prompt\": \"<string>\",\n \"chat\": true,\n \"variables\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.vatel.ai/v1/session-token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"version_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"chat_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"caller_id\": \"<string>\",\n \"first_message\": \"<string>\",\n \"prompt\": \"<string>\",\n \"chat\": true,\n \"variables\": [\n {\n \"key\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"token": "<string>",
"room": "<string>",
"identity": "<string>",
"url": "<string>",
"webrtc_token": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}
