For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
PlaygroundChangelogSign In
OverviewAPI ReferencePre-recorded STTStreaming STTVoice AgentsSpeech UnderstandingGuardrailsLLM GatewayFAQ
OverviewAPI ReferencePre-recorded STTStreaming STTVoice AgentsSpeech UnderstandingGuardrailsLLM GatewayFAQ
  • Getting started
    • Transcribe streaming audio
    • Model selection
    • View model benchmarks
    • Evaluate model accuracy
    • Cloud endpoints & data residency
    • Manage concurrent sessions
    • Webhooks
    • Self-hosted streaming
  • Models
    • Whisper Streaming
    • Medical Mode
  • Features
    • Boost specific terms
    • Label speakers and separate channels
    • PII redaction
    • Filter profanity
    • Authenticate with a temporary token
    • Common session errors and closures
  • Integrations
    • LiveKit
    • Pipecat
  • Guides
LogoLogo
PlaygroundChangelogSign In
On this page
  • Authenticate with a temporary token
Features

Authenticate with a temporary token

Was this page helpful?
Previous

Common session errors and closures

Next
Built with

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.

GET
/v3/token
1curl -G https://streaming.assemblyai.com/v3/token \
2 -H "Authorization: <apiKey>" \
3 -d expires_in_seconds=60
Try it
1
Python
Python SDK
JavaScript
JavaScript SDK

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 initialized using this token.

1import requests
2from urllib.parse import urlencode
3
4
5def create_temporary_token():
6 url = "https://streaming.assemblyai.com/v3/token"
7 response = requests.get(
8 f"{url}?{urlencode({'expires_in_seconds': 60})}",
9 headers={"Authorization": "<YOUR_API_KEY>"},
10 )
11 data = response.json()
12 return data.get("token")

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).

2

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.

Python
Python SDK
JavaScript
JavaScript SDK

To use it, specify the token parameter as a query parameter in the WebSocket URL.

1params_w_token = {**CONNECTION_PARAMS, "speech_model": "u3-rt-pro", "token": token}
2ws_app = websocket.WebSocketApp(
3 f'{API_ENDPOINT_BASE_URL}?{urlencode(params_w_token)}',
4 on_open=on_open,
5 on_message=on_message,
6 on_error=on_error,
7 on_close=on_close,
8)