Authenticate with a temporary token

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
1

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.

1client = StreamingClient(
2 StreamingClientOptions(
3 api_key="<YOUR_API_KEY>",
4 api_host="streaming.assemblyai.com",
5 )
6)
7
8return client.create_temporary_token(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).
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.

To use it, specify the token parameter when initializing the StreamingClient.

1client = StreamingClient(
2 StreamingClientOptions(
3 token=token,
4 api_host="streaming.assemblyai.com",
5 )
6)