Chronicle Labs API is currently in beta. Reach out for access

SDK GUIDE

Node.js

Install and configure the Chronicle Node.js SDK. Until the package is published, use the HTTP helpers shown below.

Installnpm install @chronicle-labs/sdk
SDK generation in progress - until published, Node 18+ fetch works with no extra dependencies.

Install

Node
JS
// When the SDK is published:
npm install @chronicle-labs/sdk

// Until then, no extra dependency needed (Node 18+ has fetch built-in)

Initialize the client

Node
JS
import { Chronicle } from "@chronicle-labs/sdk";

const chronicle = new Chronicle({
  apiKey: process.env.CHRONICLE_API_KEY,
  // baseUrl defaults to https://api.chronicle-labs.dev/v1
});

HTTP fallback (available now)

Use this helper until the SDK package is live.

Node
JS
const API_BASE = process.env.CHRONICLE_BASE_URL || "https://sandbox-api.chronicle-labs.dev/v1";
const API_KEY = process.env.CHRONICLE_API_KEY;

async function chronicleRequest(path, options = {}) {
  const resp = await fetch(`${API_BASE}${path}`, {
    ...options,
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
      ...(options.headers || {}),
    },
  });
  if (!resp.ok) throw new Error(`Chronicle ${resp.status}: ${await resp.text()}`);
  return resp.json();
}

Create an event

Node
JS
// SDK
const event = await chronicle.events.create({
  source: "custom_app",
  source_event_id: "order_1001_paid",
  event_type: "order.payment_succeeded",
  conversation_id: "order_1001",
  actor_type: "system",
  actor_id: "payments_service",
  payload: { order_id: "order_1001", amount: 4999, currency: "usd" },
  tenant_id: "tenant_demo",
});

// HTTP fallback
const evt = await chronicleRequest("/events", {
  method: "POST",
  headers: { "Idempotency-Key": "order_1001_paid" },
  body: JSON.stringify({ /* same body */ }),
});
Response
JSON
{
  "event_id": "evt_01J8WNEQ2NWY4G7EJAZ9M8MXXV",
  "ingested": true,
  "message": "Event ingested successfully"
}