Auth for Chat
Token Generation
How to generate authentication tokens
Endpoint
POST https://api.performchat.com/rest/v1/auth/tokenRequest Body
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
keyId | string | Yes | Your API key ID |
keySecret | string | Yes | Your API key secret |
userId | string | Yes | Your user's ID from your system |
agentId | string | Yes | The ID of the AI agent to connect to |
expiresIn | string | No | Token expiration time (default: 24h) |
Example Request
{
"keyId": "pk_your_key_id",
"keySecret": "sk_your_secret_key",
"userId": "user_123_from_your_system",
"agentId": "agent_abc",
"expiresIn": "1h" // Optional - defaults to 24h
}Expiration Time Format
The expiresIn parameter accepts the following formats:
| Format | Description | Example |
|---|---|---|
s | Seconds | "3600s" = 1 hour |
m | Minutes | "30m" = 30 minutes |
h | Hours | "24h" = 24 hours (default) |
d | Days | "7d" = 7 days |
Examples:
"15m"- Short-lived token (15 minutes)"1h"- Standard token (1 hour)"24h"- Default (24 hours)"7d"- Long-lived token (7 days)
Note: Shorter expiration times provide better security, especially for sensitive operations. Consider using
15mor1hfor high-security scenarios.
Response
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"customerUser": {
"id": "cm4abc123xyz", // ⚠️ SAVE THIS for token invalidation!
"externalId": "user_123_from_your_system",
"companyId": "your_company_id",
"agentId": "agent_abc"
},
"agent": {
"id": "agent_abc",
"name": "Customer Support Agent",
"active": true
},
"apiKey": {
"id": "key_id",
"name": "Production API Key",
"environment": "production"
}
}Important: Store Customer User ID
You MUST store the user.id from the response to be able to invalidate tokens later. This is the internal database ID required for the invalidation endpoint.
const response = await generateToken(userId)
// Store in your database
await db.users.update({
where: { externalId: userId },
data: {
performChatToken: response.token,
performChatUserId: response.customerUser.id // ⚠️ Save this!
}
})See Token Invalidation for details.
Token Expiration
- Default lifetime: 24 hours (if
expiresInnot specified) - Customizable: Use
expiresInparameter to set custom expiration - Recommended approach: Generate tokens on-demand, not in advance
- Best practice: Use shorter expiration times for security (
15m-1h) - Long-lived tokens: Only use for trusted environments (
7d)