When deploying to production, do not expose your API key publicly. Instead:
- Exchange your API key for a short-lived session token on the server side.
- Pass this token to the client.
- Initialize the TruGen SDK with the session token.
Getting a Session Token
Session tokens are valid for 5 minutes by default. You should request a new token for each user session rather than caching tokens long-term.
The session token endpoint must be called from your server, not from client-side code. Making this request from the browser would expose your API key.
Fetching a Session Token on Your Server
From your server, make a request to get a session token by referencing your Agent ID (create and get one here):
User Identity Configuration
When generating a session token, you can optionally provide details about the user connecting to the conversation session:
userName: A string representing the user’s name (defaults to "JS SDK" if omitted).
userId: A unique string identifying the user. If omitted, the SDK automatically generates a timestamp-based ID (e.g. usr_2026_06_25t12_49_49_168175).
These values are passed inside the JSON request body when calling https://api.trugen.ai/v1/auth/conversation.
Example Request Body
Common Error Responses