Getting Started
Welcome to the Cognipeer Console SDK! This guide will help you get started with the Cognipeer Console SDK.
What is Cognipeer Console SDK?
The Cognipeer Console SDK is the official TypeScript/JavaScript client library for Cognipeer Console, a multi-tenant SaaS platform for AI and Agentic services. It provides:
- Chat Completions: OpenAI-compatible chat API with streaming
- Embeddings: Text vectorization for semantic search
- Vector Operations: Unified API for vector databases
- File Management: Upload and process documents
- Agent Tracing: Observability for agent executions
Prerequisites
- Node.js 18 or higher
- A Cognipeer Console account and API key
Installation
Install the SDK using your preferred package manager:
bash
npm install @cognipeer/console-sdkbash
yarn add @cognipeer/console-sdkbash
pnpm add @cognipeer/console-sdkGet Your API Key
- Sign up at Cognipeer Console
- Navigate to your dashboard
- Go to Settings > API Tokens
- Create a new API token
- Copy the token (you'll need it in the next step)
Initialize the Client
Create a new client instance with your API key:
typescript
import { ConsoleClient } from '@cognipeer/console-sdk';
const client = new ConsoleClient({
apiKey: 'your-api-key-here',
});Environment Variables
For security, we recommend storing your API key in an environment variable:
typescript
const client = new ConsoleClient({
apiKey: process.env.COGNIPEER_API_KEY!,
});Your First Request
Let's make a simple chat completion request:
typescript
const response = await client.chat.completions.create({
model: 'gpt-4',
messages: [
{
role: 'system',
content: 'You are a helpful assistant.',
},
{
role: 'user',
content: 'What is the capital of France?',
},
],
});
console.log(response.choices[0].message.content);
// Output: "The capital of France is Paris."Streaming Example
Stream responses for real-time output:
typescript
const stream = await client.chat.completions.create({
model: 'gpt-4',
messages: [
{
role: 'user',
content: 'Tell me a short story about a robot.',
},
],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}Configuration Options
The client supports several configuration options:
typescript
const client = new ConsoleClient({
apiKey: 'your-api-key',
baseURL: 'https://api.cognipeer.com', // Optional: custom API URL
timeout: 60000, // Optional: request timeout (ms)
maxRetries: 3, // Optional: max retry attempts
fetch: customFetch, // Optional: custom fetch implementation
});Next Steps
Now that you've set up the SDK, explore these topics:
- Authentication - Learn about API keys and security
- Configuration - Advanced client configuration
- Chat API - Detailed chat completions documentation
- Examples - Real-world usage examples
TypeScript Support
The SDK is written in TypeScript and includes full type definitions:
typescript
import type {
ChatCompletionRequest,
ChatCompletionResponse,
EmbeddingRequest,
} from '@cognipeer/console-sdk';
// Full intellisense and type checking
const request: ChatCompletionRequest = {
model: 'gpt-4',
messages: [
{ role: 'user', content: 'Hello!' }
],
};