Chatspark
Pricing
⌘K

API Reference

v1
⌘K

Node.js / TypeScript SDK

Use the official SDK for chat, streaming, agents, conversations, and leads. Examples use numeric agent IDs and the current client method signatures.

Installation

Install the SDK in your server application. Keep API keys on your server.

bash

npm install @chatspark/sdk

Basic Usage

Replace 123 with an agent ID from your dashboard. Chat requires Plus or above and the chat:write scope.

javascript

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

const apiKey = process.env.CHATSPARK_API_KEY;
if (!apiKey) throw new Error("Set CHATSPARK_API_KEY before running this example.");
const client = new ChatSpark({ apiKey });
const { text, conversationId } = await client.agents.chat(123, { message: "Hello!" });
console.log(text);

// Continue the same conversation.
await client.agents.chat(123, { message: "Are you open on weekends?", conversationId });

SDK Methods

MethodAccess and purpose
client.agents.chat(id, params)Plus+. Send a message. Returns text and conversationId.
client.agents.chatStream(id, params)Plus+. Stream events and read delta text when present.
client.agents.list(params)Plus+. List accessible agents.
client.agents.get(id)Plus+. Get agent configuration.
client.agents.create(params)Enterprise. Create an agent.
client.agents.update(id, params)Enterprise. Update an agent.
client.agents.delete(id)Enterprise. Permanently delete an agent.
client.conversations.list(agentId, params)Plus+. List conversations.
client.conversations.messages(agentId, conversationId, params)Plus+. List messages.
client.leads.list(agentId, params)Plus+. List captured leads.

API key scopes and agent restrictions apply in addition to the plan requirement. Analytics and training endpoints are documented in the REST API reference. Do not assume every REST endpoint has a dedicated SDK resource.

Code Examples

for await (const event of client.agents.chatStream(123, { message: "Tell me about your services" })) {
  if (typeof event.delta === "string") process.stdout.write(event.delta);
}

TypeScript Support

The SDK includes types for its supported resources. Check your installed SDK version when following examples.

Previous

Management API

Next

Changelog