Overview
The Mindset AI SDK 3 uses token-based authentication to link client-side sessions to user accounts within the Mindset AI platform. This authentication mechanism ensures secure, seamless integration of user sessions with your embedded agents. The authentication process handles two scenarios automatically: Existing users: If the user already exists in Mindset AI, the authentication process generates a token that links the current session to their existing account. This provides continuity for returning users. New users: If the user doesn’t exist, the system automatically creates a new user account using the provided identifier (email or external ID) and generates an authentication token. This streamlines onboarding without manual intervention. The authentication token serves as the key to accessing SDK features while maintaining user-specific context, conversation history, and preferences.How Authentication Works
1
User initiates session
Your application captures user identification (email or external ID)
2
Server requests token
Your server makes a secure POST request to Mindset AI’s authentication endpoint with user details
3
Token generation
Mindset AI validates the request, creates or links the user account, and returns an authentication token
4
Client-side initialization
Your client-side code uses the token to initialize the SDK and establish the user session
Generate Authentication Token
Make a secure server-side HTTP POST request to the Mindset AI authentication endpoint to generate an authentication token.Endpoint
Headers
| Header | Value | Description |
|---|---|---|
Content-Type | application/json | Required |
x-api-key | YOUR-MINDSET-API-KEY | Your Mindset AI API key (manage in Developer Tools → API Keys) |
API keys are managed in the Agent Management Studio under Developer Tools → API Keys.
Request Body
The request body must include user identification using eitherexternalId or userEmail (not both).
| Parameter | Type | Required | Description |
|---|---|---|---|
externalId | String | Conditional* | Unique identifier for the user in your system |
userEmail | String | Conditional* | Email address of the user |
name | String | Optional | Display name for the user (used when creating new accounts) |
accountUids | Array | Optional | Array of Mindset AI account UIDs to grant this user access to restricted agents |
Request Examples
Using external ID (recommended):Response
On successful authentication, the API returns an authentication token:User Management
How User Accounts Work
When you provide a user identifier to Mindset AI:- Lookup: The API checks if a user with that identifier already exists
- Create or Link: If the user doesn’t exist, a new account is created and linked to the identifier
- Token Generation: An authentication token is generated for this user
- Session Continuity: Returning users automatically access their previous conversation threads and context
User Identification Best Practices
Use externalId (recommended):
- Gives you strict control over what PII you share with Mindset AI
- Allows cross-referencing user activity with your platform
- Can be any unique string that identifies the user in your system
Using userEmail:
- Email addresses are modified to make them unique to your application
- Mindset AI never sends emails to these addresses
- The email serves purely as an identification string
Account Membership
The optionalaccountUids parameter lets you grant users access to restricted agents automatically during authentication.
When to use this:
- You have agents with restricted access (not public to all users)
- You want to control which users can interact with specific agents
- You’re implementing role-based or tier-based agent access
Server-Side Implementation
Node.js Example
Here’s how to implement authentication in Node.js:Integration Pattern
- Capture user identity in your application (email, user ID, etc.)
- Call authentication endpoint from your server with user details
- Receive authentication token from Mindset AI
- Pass token to client securely (never log or expose it)
- Initialize SDK on client side using the token
Security Considerations
API Key Protection
Best practices:- Store API keys in environment variables
- Use secret management services (AWS Secrets Manager, Azure Key Vault, etc.)
- Rotate keys periodically
- Never commit keys to version control
- Use different keys for development and production
Authentication Token Security
Handle tokens securely:- Transmit tokens over HTTPS only
- Store tokens securely on the client (memory, secure storage)
- Implement token refresh mechanisms for long-lived sessions
- Clear tokens when users log out
- Log tokens to console or files
- Store tokens in localStorage without encryption
- Share tokens between users
- Transmit tokens in URL parameters
API Reference
For complete API documentation including error codes, rate limits, and advanced parameters, see the SDK Users API documentation.Migrate to SDK 3 Authentication
If you’re currently using SDK 2 authentication, you’ll need to migrate to SDK 3’s authentication flow.Check if you need to migrate: If your code uses the legacy endpoint
https://MINDSET-API-HOST/api-authenticate-embedded-user, you need to migrate.Migration Steps
1
Generate new API key
In Agent Management Studio, navigate to Developer Tools → API Keys and generate a new API key.
2
Update authentication endpoint
Replace the legacy endpoint with the new SDK 3 endpoint:
3
Update request format
Update your request body to use the new parameter format:
4
Update headers
Use the new API key in the
x-api-key header:5
Test authentication flow
Verify that your server successfully receives authentication tokens and your client can initialize the SDK.
Key Changes from SDK 2
| Aspect | SDK 2 (Legacy) | SDK 3 (Current) |
|---|---|---|
| Endpoint | /api-authenticate-embedded-user | /api/v1/appuid/{YOUR-APP-UID}/sdkusers/auth |
| API Key Header | Custom format | x-api-key |
| User Identification | Email only | externalId or userEmail |
| API Key Management | Legacy system | Developer Tools → API Keys |
Troubleshooting
Authentication request fails with 401
Possible causes:- Invalid or missing API key
- API key is from wrong environment (dev key in production)
- API key has been revoked
Authentication request fails with 400
Possible causes:- Missing both
externalIdanduserEmail - Provided both
externalIdanduserEmail - Invalid request body format
externalId OR userEmail) in valid JSON format.
Token works initially but fails later
Possible causes:- Token has expired
- User account has been disabled
- Network connectivity issues