Skip to main content
A temporary token lets a browser or an app use an AssemblyAI product without your API key. Your server mints the token with your key, hands the token to the client, and the client uses it in place of the key. Each token expires after a short window, usage through it is attributed to the key that minted it, and a token cannot mint another token. Keep your API key on your server. Anything a client receives, including a token, can be read by that client, so keep each token’s window short and mint a new one for each connection.

Mint a token

Send POST to a token. host with your API key in the Authorization header and a JSON body. Only the token. hosts accept this request: Mint on the host of the zone your sessions connect to.
The response is JSON with the token in its token field:

Use the token

Pass the token in place of your API key. A server can send it in the Authorization header, as it would your key. A browser cannot set headers on a WebSocket handshake, so it passes the token in the token query parameter of the WebSocket URL instead. Each product page shows the exact WebSocket URL and parameters. Mint a fresh token for each connection. Until its window closes, a token can open more than one session, so keep expires_in_seconds short.

Request fields

Products

Each product page shows how its client uses the token:

Limit what a token can do

A token can open any product your account can, unless you narrow it. The access field on the request narrows it for that one token. Your API key and account are not changed, and a token minted without access behaves as it does without it. Each product in access is keyed by product name or alias and takes: Each model in models takes these optional limits. Each one is a whole number of 1 or more. Products you leave out of access are not restricted by the token. List each product once: streaming and realtime name the same product, so listing both is an error.

Defaults for LLM Gateway limits

Tutorials

1. Open one product only

A token for a real-time transcription page should not open text-to-speech, a voice agent session, or the LLM Gateway. Mint it with those products disabled:

2. Limit one LLM Gateway model

To let a chat widget use one model at a set rate, mint an llm_gateway token with limits for that model. Other models are not listed, so they get the default of 10 requests per minute:
A request that sets max_tokens above 500, or a prompt longer than 8000 characters, is refused by the gateway. The same token can still call other models, at the default of 10 requests per minute.

3. Handle a rejected request

The API checks the whole request before it mints anything and returns every problem at once. A problem with the request body returns 400 with the problems in detail:
Unknown fields inside access, such as a misspelled enabled or a limit that is not one of the four above, return 422 with the field named in the error. A 401 or 403 means the API key was not accepted. A 500 or 502 means the token could not be issued right now; retry with backoff.