Getting Started
Welcome to the Cognipeer SDK! This guide will help you get up and running with building conversational AI applications.
What is Cognipeer?
Cognipeer is a powerful AI platform that enables you to create intelligent conversational agents (called "Peers") that can interact with users, execute functions, and perform complex workflows. The SDK provides a simple JavaScript/TypeScript interface to integrate these capabilities into your applications.
Key Features
🤖 Conversational AI
Create multi-turn conversations with AI agents that remember context and can handle complex dialogues.
🔧 Client-Side Tool Execution
Define JavaScript functions that the AI can automatically call and execute on your side. This enables:
- Integration with external APIs
- Database queries
- Custom business logic
- Real-time data access
🌊 Flow Automation
Execute pre-built workflows and automations with structured inputs and outputs.
📦 Universal Compatibility
- ✅ Node.js (v16+)
- ✅ Modern browsers
- ✅ Edge runtimes (Cloudflare Workers, Vercel Edge)
- ✅ ESM and CommonJS support
Prerequisites
Before you begin, you'll need:
- A Cognipeer Account: Sign up at cognipeer.com
- A Personal Access Token (PAT): Generate one from your workspace settings
- An API Channel: Create an API channel and get its hook ID
- Node.js 16+ or a modern browser
Installation
Install the SDK using your preferred package manager:
npm install @cognipeer/sdkyarn add @cognipeer/sdkpnpm add @cognipeer/sdkGetting Your Credentials
1. Personal Access Token (PAT)
- Log in to your Cognipeer workspace
- Navigate to Settings → Security → Personal Access Tokens
- Click Generate New Token
- Copy your token (starts with
pat_) - Store it securely
Token Types:
- PAT Token (recommended): Starts with
pat_, provides user-scoped access. Conversations are automatically associated with your user account.- API Token (legacy): For contact-based operations. Requires providing
contactIdfor conversation operations.
2. API Channel Hook ID
- Create or select a Peer (AI agent) in your workspace
- Navigate to Channels → API Channel
- Copy the Hook ID (e.g.,
bhdwxdpdkndpzolyttqf) - The peer associated with this channel will be used for all conversations
Security
Never commit your API token to version control. Use environment variables or secure secret management.
Authentication
The SDK requires two pieces of information:
- token: Your authentication token (PAT recommended)
- PAT tokens (
pat_xxx): User-scoped, no need to specify userId/contactId - API tokens: Contact-scoped, requires
contactIdparameter for conversations
- PAT tokens (
- hookId: Your API channel's hook ID (determines which peer to use)
const client = new CognipeerClient({
token: process.env.COGNIPEER_TOKEN, // PAT token (starts with pat_)
hookId: process.env.COGNIPEER_HOOK_ID
});
// With PAT token - userId is automatic
const response = await client.conversations.create({
messages: [{ role: 'user', content: 'Hello!' }]
});
// With API token - contactId is required
const apiResponse = await client.conversations.create({
contactId: 'contact-123', // Required with API tokens
messages: [{ role: 'user', content: 'Hello!' }]
});Next Steps
- Quick Start - Build your first conversation
- Client Configuration - Configure the SDK
- Client Tools - Learn about function calling