Model Capabilities
Ephemeral Tokens
Ephemeral tokens provide secure, short-lived authentication for client-side applications. Use them when connecting to the Speech to Speech API from browsers or mobile apps to avoid exposing your API key.
How It Works
Your server requests an ephemeral token from xAI using your API key
Your server passes the ephemeral token to the client
The client uses the ephemeral token to authenticate the WebSocket connection
The token expires automatically after the configured duration
Creating Ephemeral Tokens
You need to set up a server endpoint to fetch the ephemeral token from xAI. The ephemeral token gives the holder scoped access to resources.
Endpoint: POST https://api.x.ai/v1/realtime/client_secrets
curl --url https://api.x.ai/v1/realtime/client_secrets \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XAI_API_KEY" \
--data '{
"expires_after": {
"seconds": 300
}
}'
# Note: Does not support "session" or "expires_after.anchor" fieldsUsing Ephemeral Tokens
The ephemeral token can be used in the same fashion as an API key:
import os
import websockets
base_url = "wss://api.x.ai/v1/realtime?model=grok-voice-latest"
# Connect with API key in Authorization header
async with websockets.connect(
uri=base_url,
ssl=True,
additional_headers={"Authorization": f"Bearer {OBTAINED_EPHEMERAL_TOKEN}"}
) as websocket:
# WebSocket connection is now authenticated
passBrowser WebSocket Authentication
If you need to send the ephemeral token from the browser, you can add the ephemeral token with a prefix xai-client-secret. to the sec-websocket-protocol header:
new WebSocket("wss://api.x.ai/v1/realtime", [\`xai-client-secret.\${OBTAINED_EPHEMERAL_TOKEN}\`]);Last updated:July 21, 2026