Authentication
Session tokens
Deprecated multi-use JWTs — use one-time tokens wherever possible.
A session token is a JWT created from your API key. Unlike a one-time token, it can be used repeatedly. The client can open connections and make requests until the token expires, a few hours after creation. For new direct client integrations, use it for a Realtime voice session and mint it on your backend, so the API key itself never reaches the client. A long-lived TTS WebSocket can use a one-time token: single-use limits connection attempts, not the number of synthesis messages on that connection.
Mint a session token
On the US API, send the copied Base64 API key with Basic authentication. Set INWORLD_API_KEY to the full value you copied from Portal or the CLI.
POST https://api.inworld.ai/v1/sessionTokens/token:generate
Authorization: Basic $INWORLD_API_KEY
Content-Type: application/json
{}Send an empty JSON object to mint for the key's workspace. To choose a workspace, set resources in the request body.
{
"resources": ["workspaces/my-workspace"]
}api_key(optional with Basic) — if present, it must match the key ID in the Basic credential.resources(optional) — a singleworkspaces/{workspace}name to scope the token to. Omitted, the token is scoped to the key's own workspace. Another workspace is allowed when the key's workspace collection contains it, or when it is public.
The US API also accepts the Basic header on POST /auth/v1/tokens/token:generate. The optional key ID field on that endpoint is named key.
The response includes the session token and its expiration time.
{
"token": "eyJhbGciOiJSUzI1NiIs...",
"type": "Bearer",
"expirationTime": "2026-09-01T16:00:00Z",
"sessionId": "my-workspace:1f0d8e9a-..."
}Server-side mint example
Save this as mint-session-token.mjs on your Node.js backend. It sends the copied Base64 credential as-is and returns the minted token.
export async function mintSessionToken() {
const credential = process.env.INWORLD_API_KEY;
if (!credential) throw new Error('Missing server API credential');
const response = await fetch('https://api.inworld.ai/v1/sessionTokens/token:generate', {
method: 'POST',
headers: {
Authorization: `Basic ${credential}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
signal: AbortSignal.timeout(10000),
});
if (!response.ok) throw new Error(`Session mint failed (${response.status})`);
return response.json();
}Call mintSessionToken() inside your application's authenticated, authorized, rate-limited token endpoint, following the backend handler pattern. Return only token and expirationTime with Cache-Control: no-store. Keep the workspace choice on the server.
Use it
Send the token as a Bearer credential from the client:
Authorization: Bearer <token>It works across the APIs allowed by the parent key, including WebSocket and Realtime connections. Browser WebSockets use new WebSocket(url, ["bearer_" + token]); WebRTC signaling uses the Bearer HTTP header. See Realtime WebSocket and WebRTC for connection URLs and session messages. The TTS SDK refreshes tokens for you — pass a fetcher and it re-mints shortly before expiry:
const tts = InworldTTS({
token: await fetchToken(), // your backend endpoint that mints the token
onTokenExpiring: fetchToken, // called automatically before expiry
});Lifetime and revocation
- Tokens expire a few hours after creation. Always read
expirationTimerather than assuming a duration, and refresh before it passes. - A session token is valid until it expires: there is no per-token revocation. Deleting the parent API key invalidates every token minted from it immediately.
For clients that open exactly one connection per credential, prefer one-time tokens — shorter-lived, and dead after first use. See Security best practices for choosing between the two.
Realtime session expiry
When token expiry enforcement is active, a Realtime WebSocket or WebRTC session opened with a token ends by the token's expiration time. The server can close it shortly before that time.
- If the token has too little time left, the server refuses the connection with HTTP
401. Get a fresh token from your backend and try again. - When a running session reaches its deadline, the server sends an
authentication_errorwith codetoken_expiredand closes the connection. Open a new session with a fresh token and send your session configuration again.
A connection opened directly with an API key has no token expiry deadline.