Type Safe
Back to integrations
Official SDKVerifiedAvailable2026-09-23

TypeSafe JavaScript SDK

A server-side Node.js integration using the official SDK, typed choice outputs, bounded retries, response validation, and a human-review threshold.

Install

npm install @typesafe-ai/sdk

Server environment variables

TYPESAFE_API_KEY

Prerequisites

  • Node.js 20 or newer
  • A TypeSafe API key stored on the server
  • A documented fallback for low-confidence decisions

Implementation steps

  1. 1Install the official package and keep it on the server.
  2. 2Set TYPESAFE_API_KEY in the server environment.
  3. 3Define named choices with operationally distinct criteria.
  4. 4Set a per-attempt timeout and a bounded retry count.
  5. 5Validate the returned choice and confidence before routing work.
  6. 6Send low-confidence decisions to human review.
Server example
import { choice, TypeSafeClient } from '@typesafe-ai/sdk';

const apiKey = process.env.TYPESAFE_API_KEY;
if (!apiKey) throw new Error('TYPESAFE_API_KEY is required');

const client = new TypeSafeClient({
  apiKey,
  timeout: 10_000,
  retry: { maxRetries: 2 },
});

const result = await client.systemOne({
  model: 'jev-latest',
  state: {
    ticket: 'I was charged twice. Please fix this ASAP.',
  },
  questions: {
    route: choice('Choose the support queue.', {
      billing: 'Payments, invoices, refunds, or duplicate charges',
      technical: 'Product behavior, errors, or integrations',
      other: 'Everything else',
    }),
  },
});

const decision = result.answers.route;
if (
  typeof decision.choice !== 'string' ||
  !Number.isFinite(decision.confidence) ||
  decision.confidence < 0 ||
  decision.confidence > 1
) {
  throw new Error('Unexpected decision response');
}

const action = decision.confidence < 0.8 ? 'human_review' : decision.choice;
console.log({ action, confidence: decision.confidence, model: result.model });

Production checks

  • Never ship the API key to browser code.
  • The SDK timeout is per attempt, so total wall time can exceed ten seconds when retries occur.
  • Do not log request bodies when they can contain personal or confidential data.
  • Pin and test a package version before release.

Limitations and verification notes

The example demonstrates integration safety, not task accuracy. Calibrate the 0.8 review threshold on representative data before production use.

Sources

This guide is independently maintained by Type Safe. Check the provider’s current documentation, versions, and terms before use.