Authentication
Cognipeer supports two primary authentication flows. Choose the one that matches your deployment model.
Personal Access Tokens (PAT)
Use PATs for server-to-server workloads where you control the environment.
typescript
import { CognipeerClient } from '@cognipeer/sdk';
const client = new CognipeerClient({
token: process.env.COGNIPEER_TOKEN!
});- Issued per user inside the Cognipeer dashboard.
- Carry the user identity, so each request is associated with that user automatically.
- Ideal for backends, cron jobs, and internal tooling.
Rotating PATs
- Create a new PAT in the dashboard.
- Update your secret manager / CI.
- Redeploy services.
- Revoke the previous PAT once traffic is confirmed.
API Channel Tokens (Hook IDs)
Use hook IDs when integrating channel-based bots or client-side webchat.
typescript
const client = new CognipeerClient({
token: process.env.COGNIPEER_API_TOKEN!,
hookId: 'channel-hook-id'
});tokenauthenticates the workspace,hookIdidentifies the channel instance.- Works for browser environments because the hook encapsulates the contact context.
- Combine with client-side tools for fully local execution.
Best Practices
- Store tokens in environment variables or secret managers, never commit them to Git.
- Prefer short-lived infrastructure (containers, serverless) so rotations are easy.
- Scope PAT permissions to the minimum required workspace access.
- For frontend usage, only expose hook-based tokens designed for that purpose.