Overview
TalkifAI supports two authentication methods:- Session-based authentication — For Studio UI and logged-in users (via Better Auth)
- API keys — For server-to-server API access
| Use Case | Authentication Method |
|---|---|
| Studio UI (logged-in users) | Session-based |
| Marketing site → Studio API | API key (x-api-key) |
| External backend → Studio API | API key (x-api-key) |
| Backend service (your own) | Session-based or API key |
Session-Based Authentication
For applications where users log in to TalkifAI Studio, authentication is handled automatically via Better Auth session cookies.How It Works
- User logs in via TalkifAI Studio
- Session cookie is set automatically
- All API requests include the session cookie
- Backend validates session via
auth.api.getSession()
Example (Server-Side)
Example (Client-Side)
API Key Authentication
For server-to-server communication (e.g., marketing site → Studio API, external backends), use API keys.Generating an API Key (Via Studio UI)
Navigation: Studio → Organization → API Keys URL:/organization/api-key
Owner access required: Only organization owners can generate API keys. Admins and Members cannot access this feature.
-
Navigate to API Keys Page
- Go to Studio → Organization (sidebar)
- Click API Keys in the organization settings
-
Enter Key Details
- Key Name (required, max 50 characters)
- Example: “Production Server”, “Marketing Site”, “Dev Testing”
- Organization is automatically selected from your active session
- Key Name (required, max 50 characters)
-
Click “Generate API Key”
- Button shows loading spinner while processing
- Backend creates key via Better Auth
-
Copy the Key Immediately ⚠️
- The full key is shown only once in a dark gray box
- Click Copy button to copy to clipboard
- Shows “Copied!” confirmation for 2 seconds
- Important: You cannot view the key again after leaving the page
-
Key Details Shown
- Created date
- Expires date (1 year from creation)
- API endpoints that accept this key:
- Public Chat API:
https://api.talkifai.dev/v1/chat - Data Export API:
https://api.talkifai.dev/api/export
- Public Chat API:
- Key appears in the “Existing Keys” list on the right
- Shows: Name, prefix (e.g.,
abc123••••••••), created date, expires date, status - Can be revoked anytime by clicking Delete (trash icon)
API Key Format
TalkifAI API keys are random strings (no special prefix liketk_live_).
Example: abc123def456... (64 characters)
Using API Keys
Include the API key in thex-api-key header:
API Key Features
| Feature | Description |
|---|---|
| Organization-scoped | Keys are tied to a specific organization |
| Rate limiting | 1000 requests per hour (default) |
| Expiration | 1 year from creation (default) |
| Metadata | Stores creator, creation date, org ID |
Organization Context
All API operations are scoped to your active organization.Session-Based (Studio Users)
The active organization is stored in the session:activeOrganizationId.
API Key Authentication
API keys are automatically scoped to the organization they were created in:Environment Variables
Store credentials securely as environment variables:Verifying Your API Key
Test your API key with a simple request:Revoking API Keys
To revoke a key:- Go to Studio → Organization → API Keys
- Find the key in the “Existing Keys” list (right column)
- Click Delete (trash icon with red button)
- Confirm deletion in the dialog: “Are you sure you want to delete this API key?”
401 Unauthorized on all requests.
Security Best Practices
Rotate Keys Regularly
Generate new API keys every 90 days. Delete old keys after rotation.
Use Separate Keys
Use different keys for development, staging, and production environments.
Monitor Active Keys
Check Organization → API Keys regularly. Revoke unused keys immediately.
Never Log Keys
Never log API keys in application logs. Redact sensitive headers.
Use Environment Variables
Store keys in environment variables, not in code or config files.
Limit Key Permissions
Create separate keys for different services with minimal required access.
Error Codes
| Status | Error | Description |
|---|---|---|
401 | Unauthorized | Missing or invalid API key / session |
401 | Invalid API key | API key is malformed or revoked |
403 | Forbidden | Valid auth but insufficient permissions |
403 | Not a member of the selected organization | User/org mismatch |
429 | Rate limit exceeded | Too many requests (API keys only) |
Related Documentation
- Organization Management — Manage organizations and members
- API Keys — Detailed API key management guide
- Get Agent — Example API endpoint
- Initiate Call — Example API endpoint