Skip to content
Secnd

TypeScript

Use typed requests, bounded retries, and cancellation.

Use Node.js 22 or newer with native fetch and AbortSignal. Install the local @secnd/sdk workspace package after building it; registry publication is not assumed.

import { Secnd, type DecideRequest } from "@secnd/sdk";

const apiKey = process.env.SECND_API_KEY;
if (!apiKey) throw new Error("Set SECND_API_KEY");
const client = new Secnd({ apiKey });
const request: DecideRequest = {
  model: "ren-zero-2026-11-12",
  type: "noul",
  situation: "The customer asks to cancel before renewal.",
  question: "Is cancellation explicitly requested?",
  threshold: 0.9,
};
const result = await client.decide(request);
console.log(result.choice, result.probability, result.action);

Constructor options: apiKey (required), baseURL (default https://api.secndai.com), maxRetries (default 2; 0–5), timeoutMs (default 30000 per attempt), and an optional fetch implementation. HTTPS is required except on localhost.

Bound the whole call

const result = await client.decide(request, {
  signal: AbortSignal.timeout(10_000),
});

Pass an AbortSignal to enforce an application deadline across attempts and retry waits. Catch errors rather than treating cancellation as a decision.

Typed errors

AuthenticationError, ValidationError, RateLimitError, and ServerError extend SecndError. Instances expose status, code, message, and optional retryAfter. Network, cancellation, and invalid-response failures can use the base class.

The client retries 429 and server errors with exponential backoff, honoring the full Retry-After up to 60 seconds; a longer delay throws a typed error carrying retryAfter instead of retrying. It surfaces transport failures directly. Do not put this client, or its bearer key, in browser code.