Skip to main content
For any Python application shipped to end users — desktop binaries, packaged distributions, or apps you don’t fully control — do not embed your API key. Follow the two-step pattern below:
  1. Exchange your API key for a short-lived session token on the server side.
  2. Return the token to the client and use it in place of the API key.

Getting a Session Token

Session tokens are valid for 5 minutes by default. Request a new token per user session rather than caching them long-term.
The session token endpoint must be called from your server, not from your desktop app. Making this request from a shipped binary would expose your API key.

Fetching a Session Token on Your Server

From your server (Python, Node, Go — anything), call TruGen’s /v1/auth/conversation endpoint with your API key and the target agent ID.
The response contains a token field, plus the conversationId, the LiveKit url, and the avatar metadata.

Using the Token in Your Desktop App

Once your app receives the token from your backend, use it in place of a create_session() call by connecting to LiveKit with the returned token/URL directly.
The Python SDK’s TruGenClient.create_session() currently expects an API key. For a token-based flow in Python, contact support@trugen.ai for the recommended pattern for your deployment shape.

User Identity Configuration

When generating a session token, you can optionally supply details about the user connecting:
  • userName — Display name (defaults to "JS SDK" if omitted; safe to override).
  • userId — Unique user identifier. If omitted, TruGen auto-generates a timestamp-based ID.
These are included in the JSON body sent to https://api.trugen.ai/v1/auth/conversation.

Example Request Body

Common Error Responses

Next steps

Authentication

Full two-tier authentication overview.

Basic Usage

Full SDK reference for initializing, streaming, and disconnecting.