Chatspark
K

API Reference

v1
K

Node.js / TypeScript SDK

The official @chatspark/sdk provides a typed client for the ChatSpark API. Use it for chat, agents, conversations, leads, and streaming.

Installation

bash

npm install @chatspark/sdk

Or with yarn: yarn add @chatspark/sdk

Basic Usage

javascript

import { ChatSpark } from "@chatspark/sdk";

const client = new ChatSpark({
  apiKey: process.env.CHATSPARK_API_KEY!,
});

// Send a chat message
const { reply, conversationId, messageId } = await client.chat.send({
  agentId: "ag_123",
  message: "Hello!",
});

SDK Methods

MethodDescription
client.chat.send()Send a message and receive the AI reply
client.chat.sendStreaming()Send a message and stream the reply token-by-token
client.agents.list()List all agents
client.agents.get()Get a single agent
client.conversations.list()List conversations for an agent
client.conversations.getMessages()List messages in a conversation
client.leads.list()List leads for an agent
client.analytics.get()Get analytics for an agent

Code Examples

const { reply, conversationId } = await client.chat.send({
  agentId: "ag_123",
  message: "What are your opening hours?",
  conversationId: "conv_abc", // optional, for continuing a thread
});

TypeScript Support

The SDK is written in TypeScript and includes full type definitions. All methods and responses are typed for IDE autocomplete and compile-time checks.

javascript

import type { ChatResponse, Lead } from "@chatspark/sdk";

const res: ChatResponse = await client.chat.send({
  agentId: "ag_123",
  message: "Hi",
});

const leads: Lead[] = (await client.leads.list({ agentId: "ag_123" })).leads;

Previous

Management API

Next

Changelog