Getting Started

Get a working SDK integration quickly with basic chat, streaming, and convenience sendMessage flow.

Install

npm install @jazzmine-ui/sdk

Runtime compatibility

Works in browser runtimes and Node.js 18+. For older Node versions, pass fetchImpl in constructor options.

Choose a flow

FlowUse it whenMethod
Basic chatYou need one request/response callchat()
Streaming chatYou want progress events while generating outputchatStream()
Convenience sendYou want auto-create + first message in one callsendMessage()

Basic chat

basic-chat.ts
import JazzmineClient from "@jazzmine-ui/sdk";

const client = new JazzmineClient("https://your-jazzmine-api.example.com", {
  apiKey: "your-api-key",
});

const reply = await client.chat({ message: "Summarize this dataset." });

console.log(reply.response);

Streaming chat

streaming-chat.ts
import JazzmineClient from "@jazzmine-ui/sdk";

const client = new JazzmineClient("https://your-jazzmine-api.example.com");

const final = await client.chatStream(
  { message: "Plan a 5-day trip to Tokyo." },
  {
    onIntermediate: (event) => console.log("intermediate", event),
    onDone: (response) => console.log("done", response.response),
    onErrorEvent: (event) => console.error("stream error event", event),
  },
);

console.log(final.conversation_id);

Convenience sendMessage flow

send-message.ts
import JazzmineClient from "@jazzmine-ui/sdk";

const client = new JazzmineClient("https://your-jazzmine-api.example.com", {
  defaultUserId: "alice",
});

const { response, conversationId } = await client.sendMessage("Start a new thread", {
  autoCreateConversation: true,
  conversationTitle: "Project planning",
});

console.log(conversationId, response.response);

Node.js note

For Node.js versions below 18, provide a fetch implementation through fetchImpl.

node-polyfill.ts
import JazzmineClient from "@jazzmine-ui/sdk";
import fetch from "cross-fetch";

const client = new JazzmineClient("https://your-jazzmine-api.example.com", {
  fetchImpl: fetch as unknown as typeof globalThis.fetch,
});

On this page