Skip to content

JavaScript SDK

Cloudmind JavaScript SDK reference: monitoring wrappers, manual tracing, prompt fetching, feedback and flushing.

npm install @cloudmind-ai/js

Monitoring wrappers

import { monitorOpenAI } from "@cloudmind-ai/js/openai";
import { monitorAnthropic } from "@cloudmind-ai/js/anthropic";

const openai = monitorOpenAI(new OpenAI());
const anthropic = monitorAnthropic(new Anthropic());

Wrappers are transparent. The returned object has the same interface as the original client, so nothing downstream changes.

Manual tracing

import { cloudmind } from "@cloudmind-ai/js";

const result = await cloudmind.trace(
  { name: "answer-question", userId: "u_123", metadata: { source: "web" } },
  async (trace) => {
    const chunks = await trace.span({ name: "retrieve", kind: "retrieval" }, async (span) => {
      const docs = await vectorStore.search(question, { k: 5 });
      span.record({ query: question, chunks: docs });
      return docs;
    });

    return generate(question, chunks);
  },
);

Prompts

const prompt = await cloudmind.prompts.get("support-summary", {
  label: "production",
  requires: ["ticket", "tone"],
});

const messages = prompt.render({ ticket: ticket.body, tone: "concise" });

Prompts are cached in memory and on disk. If the API is unreachable the cached revision is served and a warning is logged.

Feedback

await cloudmind.feedback({ traceId, score: 1, comment: "Resolved my issue" });

Score is a number. The convention is 1 for positive and 0 for negative, but any numeric scale works as long as you are consistent.

Flushing

await cloudmind.flush();

Required in serverless functions, CLI scripts and anywhere the process exits promptly.

Configuration in code

import { configure } from "@cloudmind-ai/js";

configure({
  apiKey: process.env.CLOUDMIND_API_KEY,
  flushInterval: 2000,
  redact: (payload) => ({ ...payload, email: "[redacted]" }),
});

redact runs in your process before anything is sent, so redacted fields never reach Cloudmind.

Last updated 2026-07-30