API Reference
The official @chatspark/sdk provides a typed client for the ChatSpark API. Use it for chat, agents, conversations, leads, and streaming.
bash
npm install @chatspark/sdkOr with yarn: yarn add @chatspark/sdk
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!",
});| Method | Description |
|---|---|
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 |
const { reply, conversationId } = await client.chat.send({
agentId: "ag_123",
message: "What are your opening hours?",
conversationId: "conv_abc", // optional, for continuing a thread
});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;