Skip to main content
Back to docs

Node.js SDK

Seal an event from TypeScript.

The Node SDK signs events with the agent passport, appends them to a hash chain, and stays out of your execution path.

terminal
npm install @rankigi/sdk
npx @rankigi/cli init

Configure

Use one credential token.

The CLI writes a single credential and chain ID. Rankigi.fromEnv() reads both.

.env
RANKIGI_CREDENTIAL=rnk_live_cred_v1...
RANKIGI_CHAIN_ID=chn_your_chain_id

First event

Record one tool call.

seal-tool-call.ts
import "dotenv/config";
import { Rankigi } from "@rankigi/sdk";

const rankigi = Rankigi.fromEnv();

await rankigi.trackToolCall(
  "send_email",
  { to: "customer@example.com", template: "renewal_notice" },
  { status: "sent", provider_id: "msg_abc123" },
);

await rankigi.close();

Wrap work

Wrap any async function.

wrap.ts
const result = await rankigi.wrap(
  "contract-review",
  { document_id: "doc_123", model: "claude-sonnet-4-20250514" },
  async () => {
    return await reviewContract("doc_123");
  },
);

LLM calls

Wrap provider calls directly.

anthropic.ts
import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic();

const response = await rankigi.wrapAnthropic(
  "contract-review",
  { model: "claude-sonnet-4-20250514", document_id: "doc_123" },
  () =>
    anthropic.messages.create({
      model: "claude-sonnet-4-20250514",
      max_tokens: 1024,
      messages: [{ role: "user", content: "Review doc_123" }],
    }),
);

Methods

The small API surface.

Rankigi.fromEnv()Reads RANKIGI_CREDENTIAL and RANKIGI_CHAIN_ID.
rankigi.trackToolCall(tool, input, output)Records a tool invocation as a signed chain event.
rankigi.wrap(label, args, fn)Wraps any async function and records input plus result hashes.
rankigi.wrapAnthropic(label, args, fn)Wraps an Anthropic Messages call.
rankigi.wrapOpenAI(label, args, fn)Wraps an OpenAI Chat Completions call.
rankigi.close()Flushes pending events before process exit.

Failure behavior

Passive by design.

RANKIGI does not block your agent. The Node SDK retries transient failures and keeps a durable queue for replay. Your handler should not depend on RANKIGI being online.

shutdown.ts
const rankigi = Rankigi.fromEnv();

// RANKIGI is passive. SDK transport failures do not throw
// into your agent path. The Node SDK retries transient failures
// and stores failed events in the durable queue for replay.

process.on("SIGTERM", async () => {
  await rankigi.close();
  process.exit(0);
});

Verify

End with independent verification.

A sealed event matters only if the exported chain can be checked outside RANKIGI.

verify
# Export a closure bundle from the dashboard.
# Then verify it locally with the reference verifier.

python3 verify.py closure-export.json

# Browser verifier:
# https://rankigi.com/verify