Appearance
For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see For full documentation content, see For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at
For the complete documentation index, see llms.txt
Authenticate with a temporary token
If you need to authenticate on the client, you can avoid exposing your API key by using temporary authentication tokens. You should generate this token on your server and pass it to the client.
Request
GET
curl
curl -G \
-H "Authorization: <apiKey>" \
-d expires_in_seconds=60To generate a temporary token, make a POST request to the temporary token endpoint.
Use the expires_in_seconds parameter to specify the duration for which the token will remain valid. Optionally, use the max_session_duration_seconds parameter to specify the desired maximum duration for the session initialized using this token.
python
import requests
from urllib.parse import urlencode
def create_temporary_token():
url = ""
response = requests.get(
f"{url}?{urlencode({'expires_in_seconds': 60})}",
headers={"Authorization": "<YOUR_API_KEY>"},
)
data = response.json()
return data.get("token")To generate a temporary token, call StreamingClient.create_temporary_token().
Use the expires_in_seconds parameter to specify the duration for which the token will remain valid. Optionally, use the max_session_duration_seconds parameter to specify the desired maximum duration for the session started using this token.
python
from assemblyai.streaming.v3 import StreamingClient, StreamingClientOptions
def create_temporary_token():
client = StreamingClient(
StreamingClientOptions(
api_key="<YOUR_API_KEY>",
api_host="streaming.assemblyai.com",
)
)
return client.create_temporary_token(expires_in_seconds=60)To generate a temporary token, make a POST request to the temporary token endpoint.
Use the expires_in_seconds parameter to specify the duration for which the token will remain valid. Optionally, use the max_session_duration_seconds parameter to specify the desired maximum duration for the session started using this token.
js
async function createTemporaryToken() {
const url = new URL("");
url.search = new URLSearchParams({
expires_in_seconds: 60,
}).toString();
const response = await fetch(url, {
headers: {
Authorization: "<YOUR_API_KEY>",
},
});
const data = await response.json();
return data.token;
}To generate a temporary token, call client.streaming.createTemporaryToken().
Use the expires_in_seconds parameter to specify the duration for which the token will remain valid. Optionally, use the max_session_duration_seconds parameter to specify the desired maximum duration for the session started using this token.
js
import { AssemblyAI } from "assemblyai";
async function createTemporaryToken() {
const client = new AssemblyAI({ apiKey: "<YOUR_API_KEY>" });
return client.streaming.createTemporaryToken({
expires_in_seconds: 60,
});
}expires_in_seconds must be a value between 1 and 600 seconds. If specified, max_session_duration_seconds must be a value between 60 and 10800 seconds (defaults to maximum session duration of 3 hours).
The client should retrieve the token from the server and use the token to authenticate the transcriber.
Each token has a one-time use restriction and can only be used for a single session. Any usage associated with a temporary token will be attributed to the API key that generated it.
To use it, specify the token parameter as a query parameter in the WebSocket URL.
python
params_w_token = {**CONNECTION_PARAMS, "speech_model": "u3-rt-pro", "token": token}
ws_app = websocket.WebSocketApp(
f'{API_ENDPOINT_BASE_URL}?{urlencode(params_w_token)}',
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close,
)To use it, specify the token parameter when initializing the StreamingClient.
python
client = StreamingClient(
StreamingClientOptions(
token=token,
api_host="streaming.assemblyai.com",
)
)
client.connect(
StreamingParameters(
sample_rate=16000,
speech_model="u3-rt-pro",
)
)To use it, specify the token parameter as a query parameter in the WebSocket URL.
js
const token = await getToken(); // Implement getToken to retrieve token from server
const paramsWithToken = { ...CONNECTION_PARAMS, speech_model: "u3-rt-pro", token };
ws = new WebSocket(
`${API_ENDPOINT_BASE_URL}?${querystring.stringify(paramsWithToken)}`
);To use it, specify the token parameter when initializing the StreamingTranscriber.
js
import { StreamingTranscriber } from "assemblyai";
const token = await getToken(); // Implement getToken to retrieve token from server
const rt = new StreamingTranscriber({
token,
sampleRate: 16_000,
speechModel: "u3-rt-pro",
});