Skip to main content
This is a beta feature according to Algolia’s Terms of Service (“Beta Services”).
This helper method generates a signed JSON Web Token (JWT) for authenticating users with Agent Studio. Use this token to scope conversations and memory to individual users in your app. The method builds an HS256 JWT with the following claims:
  • sub: your user’s unique identifier
  • exp: token expiration timestamp (defaults to 24 hours from now)
  • kid (header): your Algolia authentication key ID
This helper is currently available for JavaScript and Python only. For other languages, generate the JWT manually. For more information, see User authentication.

Usage

import { agentStudioClient } from "@algolia/agent-studio";

const client = agentStudioClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");

const token = client.forgeSecuredUserToken({
  secretKey: "ALGOLIA_SECRET_KEY",     // Your authentication key (sk-alg-...)
  secretKeyId: "ALGOLIA_KEY_ID",       // Your authentication key ID
  userId: "user-123",                  // Your user's unique identifier
  expiresIn: 24 * 3600,               // Optional: token lifetime in seconds (default: 24h)
});
Pass the generated token in the X-Algolia-Secure-User-Token header when making Agent Studio API requests.

Parameters

secretKey
string
required
Your Algolia authentication key. This is the full sk-alg-... value from the Agent Studio Settings > User authentication page.
secretKeyId
string
required
Your Algolia authentication key ID. This is the value in the ID column of the authentication keys table in the Agent Studio dashboard.
userId
string
required
A unique identifier for the user. This value is set as the sub (subject) claim in the JWT.
expiresIn
number
Token lifetime in seconds. Defaults to 86400 (24 hours).

Response

The method returns a string: a signed JWT that you can pass in the X-Algolia-Secure-User-Token header.
Last modified on June 12, 2026