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

SDK GUIDE

Rust

Install and configure the Chronicle Rust SDK. Until the crate 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 crate is published:
cargo add chronicle-labs

# Until then, add to Cargo.toml:
[dependencies]
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
eventsource-client = "0.13"

Initialize the client

Node
JS
use chronicle_labs::Chronicle;

let chronicle = Chronicle::new(
    std::env::var("CHRONICLE_API_KEY").unwrap(),
);
// base_url defaults to https://api.chronicle-labs.dev/v1

HTTP fallback (available now)

Use this helper until the crate is live.

Node
JS
use reqwest::Client;
use serde_json::json;

let client = Client::new();
let api_base = std::env::var("CHRONICLE_BASE_URL")
    .unwrap_or_else(|_| "https://sandbox-api.chronicle-labs.dev/v1".into());
let api_key = std::env::var("CHRONICLE_API_KEY").unwrap();

let resp = client
    .post(format!("{api_base}/events"))
    .bearer_auth(&api_key)
    .header("Idempotency-Key", "order_1001_paid")
    .json(&json!({
        "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"
    }))
    .send()
    .await?;

println!("{}", resp.text().await?);

Create an event

Node
JS
// SDK (target interface)
let event = chronicle.events().create(CreateEventParams {
    source: "custom_app".into(),
    source_event_id: "order_1001_paid".into(),
    event_type: "order.payment_succeeded".into(),
    conversation_id: "order_1001".into(),
    actor_type: ActorType::System,
    actor_id: "payments_service".into(),
    payload: json!({ "order_id": "order_1001", "amount": 4999, "currency": "usd" }),
    tenant_id: Some("tenant_demo".into()),
    ..Default::default()
}).await?;

println!("ingested: {}", event.event_id);
Response
JSON
{
  "event_id": "evt_01J8WNEQ2NWY4G7EJAZ9M8MXXV",
  "ingested": true,
  "message": "Event ingested successfully"
}