Skip to main content
POST
/
v2
/
realtime
/
token
Create temporary authentication token for Streaming STT
curl --request POST \
  --url https://api.assemblyai.com/v2/realtime/token \
  --header 'Authorization: <api-key>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "expires_in": 480
}
'
import requests

url = "https://api.assemblyai.com/v2/realtime/token"

payload = { "expires_in": 480 }
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({expires_in: 480})
};

fetch('https://api.assemblyai.com/v2/realtime/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.assemblyai.com/v2/realtime/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([
'expires_in' => 480
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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.assemblyai.com/v2/realtime/token"

payload := strings.NewReader("{\n \"expires_in\": 480\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "<api-key>")
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.assemblyai.com/v2/realtime/token")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"expires_in\": 480\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.assemblyai.com/v2/realtime/token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"expires_in\": 480\n}"

response = http.request(request)
puts response.read_body
{
  "token": "fe4145dd1e7a2e149488dcd2d553a8018a89833fc5084837d66fd1bcf5a105d4"
}
{
"error": "This is a sample error message"
}
{
"error": "Authentication error, API token missing/invalid"
}
{
"error": "Not found"
}
{
"error": "Too Many Requests"
}
{
"error": "Internal Server Error"
}

Authorizations

Authorization
string
header
required

Body

application/json

Params to create a temporary authentication token

expires_in
integer
required

The amount of time until the token expires in seconds

Required range: x >= 60

Response

Temporary authentication token generated

token
string
required

The temporary authentication token for Streaming Speech-to-Text