Type Safe
Back to templates
typescript · 2026-09-23

TypeScript Jev Review Gate

Route a support ticket with Jev while preserving a human-review branch for low-confidence outputs.

Use cases

  • Support routing
  • Lead qualification
  • Content triage

Dependencies and versions

  • @typesafe-ai/sdk: verify current release before install
  • Node.js 20+

Expected behavior

Validated results at or above 0.8 confidence return the selected queue; lower-confidence results return human_review.

Failure behavior

Missing credentials, exhausted request failures, and malformed responses fail closed with an exception.

Code template
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 });

Sources

This example calls a third-party service. Before copying it, verify the current API, dependency version, cost, privacy requirements, and service terms.