JEV TYPESCRIPT GUIDE

Jev TypeScript SDK tutorial

Call TypeSafe Jev from a TypeScript server with AI SDK evaluate, then validate typed Choice results before application code acts.

Updated 2026-09-238–12 min
01

1. Install the server-side packages

Use the AI SDK and gateway provider in a server-only route, worker, or backend process. Never expose the gateway credential in browser JavaScript.

npm install ai @ai-sdk/gateway

# Keep this in a server-only environment.
export AI_GATEWAY_API_KEY="your-key"
02

2. Send one typed Choice question

Start with one bounded decision and criteria that are easy to distinguish. The model selects from your keys; your code still owns every action that follows.

import { gateway } from '@ai-sdk/gateway';
import { experimental_evaluate as evaluate } from 'ai';

const result = await evaluate({
  model: gateway.evaluationModel('typesafe-ai/jev'),
  state: { message: 'Checkout returns HTTP 500.' },
  questions: {
    route: {
      type: 'choice',
      instructions: 'Which team should handle this?',
      criteria: {
        billing: 'Payments, invoices, or subscriptions',
        technical: 'Bugs, APIs, or integrations',
        human: 'Ambiguous or sensitive cases',
      },
    },
  },
});
03

3. Validate before branching

Check that the selected key belongs to the options you supplied, inspect the distribution and confidence, and reject incomplete responses instead of silently choosing a default.

const allowed = new Set(['billing', 'technical', 'human']);
const answer = result.answers.route;

if (!answer || !allowed.has(answer.choice)) {
  throw new Error('Invalid Jev response');
}

if (answer.confidence < REVIEW_THRESHOLD) {
  await enqueueHumanReview(answer);
} else {
  await suggestRoute(answer.choice);
}
04

4. Add operational safeguards

Because evaluate is currently experimental, pin the AI SDK version and review release notes before upgrading. Set timeouts, handle rate limits and overload, log model and question versions, and route high-risk or uncertain results to a person.