Generate time-limited single-use tokens with embedded authentication for frontend clients. Tokens are used for secure client-side access to real-time services like WebSocket transcription and TTS streaming.
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
const client = new ElevenLabsClient({ apiKey: "your-api-key" });
// Access this API via: client.tokensGenerate a time-bound token that expires after 15 minutes and is consumed on first use.
/**
* Generate a time limited single-use token with embedded authentication for frontend clients.
*
* @param token_type - Type of token to generate
* @param requestOptions - Request-specific configuration
* @returns Single-use token response with token string
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.tokens.singleUse.create("realtime_scribe")
*/
client.tokens.singleUse.create(
token_type: ElevenLabs.SingleUseTokenType,
requestOptions?: RequestOptions
): HttpResponsePromise<ElevenLabs.SingleUseTokenResponseModel>;Usage Example:
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
const client = new ElevenLabsClient({
apiKey: process.env.ELEVENLABS_API_KEY,
});
// Generate token for realtime transcription
const tokenResponse = await client.tokens.singleUse.create("realtime_scribe");
console.log(tokenResponse.token);
// Generate token for WebSocket TTS
const ttsToken = await client.tokens.singleUse.create("tts_websocket");/**
* Token type for single-use token generation
*/
const SingleUseTokenType = {
/** Token for real-time speech-to-text transcription via WebSocket */
RealtimeScribe: "realtime_scribe",
/** Token for text-to-speech via WebSocket */
TtsWebsocket: "tts_websocket",
} as const;
type SingleUseTokenType = (typeof SingleUseTokenType)[keyof typeof SingleUseTokenType];
/**
* Response model for single-use token creation
*/
interface SingleUseTokenResponseModel {
/** A time bound single use token that expires after 15 minutes. Will be consumed on use. */
token: string;
}Real-time Transcription: Generate tokens for frontend applications to connect to WebSocket-based speech-to-text services without exposing your API key.
WebSocket TTS: Enable client-side streaming text-to-speech connections with secure, temporary credentials.
Security: