Install
install.sh
npm install @jazzmine-ui/sdkRuntime compatibility
Works in browser runtimes and Node.js 18+. For older Node versions, pass fetchImpl in constructor options.
Choose a flow
| Flow | Use it when | Method |
|---|---|---|
| Basic chat | You need one request/response call | chat() |
| Streaming chat | You want progress events while generating output | chatStream() |
| Convenience send | You want auto-create + first message in one call | sendMessage() |
Basic chat
Use this for straightforward non-streaming request/response calls.
basic-chat.ts
import JazzmineClient from "@jazzmine-ui/sdk";
const client = new JazzmineClient("https://your-jazzmine-api.example.com", {
apiKey: "your-api-key", /* Optional: include when backend is protected */
});
const reply = await client.chat({
message: "Summarize this dataset.", /* Required: prompt text */
});
console.log(reply.response); /* Assistant output text */Streaming chat
Use this when your UI needs progressive updates during generation.
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." }, /* Required: prompt payload */
{
onIntermediate: (event) => {
/* Optional: handle intermediate stream updates */
console.log("intermediate", event);
},
onDone: (response) => {
/* Optional: handle final stream response */
console.log("done", response.response);
},
onErrorEvent: (event) => {
/* Optional: handle stream error events from server */
console.error("stream error event", event);
},
},
);
console.log(final.conversation_id); /* Final response keeps ChatResponse shape */Convenience sendMessage flow
Use this helper to auto-create a conversation and send the first message in one call.
send-message.ts
import JazzmineClient from "@jazzmine-ui/sdk";
const client = new JazzmineClient("https://your-jazzmine-api.example.com", {
defaultUserId: "alice", /* Optional: used when userId is omitted per call */
});
const { response, conversationId } = await client.sendMessage("Start a new thread", {
autoCreateConversation: true, /* Optional: create a conversation when none is provided */
conversationTitle: "Project planning", /* Optional: initial title for auto-created conversation */
});
console.log(conversationId, response.response); /* Continue the same thread later */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, /* Required on Node < 18 */
});