> ## Documentation Index
> Fetch the complete documentation index at: https://secndai.manicule.dev/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://secndai.manicule.dev/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://secndai.manicule.dev/api/mcp.
> Every agent surface: https://secndai.manicule.dev/.well-known/llms-manifest.json

# TypeScript (/sdk/typescript)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 463 · updated: 2026-11-12 -->
Related: [Python](/sdk/python.md), [Make a decision](/api-reference/decide.md)

> 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.

```typescript
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

```typescript
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.
