JavaScript guide
There are two paths to Jev: the official SDK (requires Node.js 20 or newer), or plain fetch (Node.js 18+ and edge runtimes). Both hit the same endpoint.
Option 1: the official SDK
Section titled “Option 1: the official SDK”npm install @typesafe-ai/sdkimport { choice, noul, TypeSafeClient } from '@typesafe-ai/sdk';
const client = new TypeSafeClient(); // reads TYPESAFE_API_KEY; the model defaults to jev-latest
const { answers } = await client.systemOne({ state: 'Hi, my Stripe integration keeps failing. Please refund my subscription.', questions: { department: choice('Which team should handle this', { billing: 'Payment or subscription issues', technical: 'Bugs or integration problems', }), asks_refund: noul('The customer explicitly requests a refund'), },});
console.log(answers.department.choice, answers.department.confidence);console.log(answers.asks_refund.noul);// answers.department.choice is inferred from the criteria keys as// "billing" | "technical" — a typo'd branch fails at compile time. That is// what "type-safe" means once it reaches your code.Questions are built with choice(), score(), and noul(); add model to the request to pin a version. The SDK also ships inferred answer types, a RetryPolicy (retries 408, 429, and 5xx — including 529 — by default), and structured error classes (RateLimitError, AuthenticationError, …). Repo: typesafe-ai/typesafe-sdk-js (MIT, 206★, verified 2026-09-22).
Option 2: zero-dependency fetch
Section titled “Option 2: zero-dependency fetch”Prefer no SDK? fetch the endpoint directly. The complete runnable example, triage.mjs, is a direct download (zero dependencies, Node.js 18+):
curl -O https://typesafe-jev.com/examples/javascript/triage.mjsTYPESAFE_USE_FIXTURE=1 node triage.mjsTYPESAFE_API_KEY=your-key node triage.mjsThe example asks a department Choice, a frustration Score, and a refund Noul in one request, then applies confidence thresholds to decide auto-assign versus human triage. The core:
const response = await fetch('https://api.typesafe.ai/v1/systemone', { method: 'POST', headers: { Authorization: `Bearer ${process.env.TYPESAFE_API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify(payload),});if (!response.ok) { // 401/422: do not retry. 429/529: exponential backoff. console.error(`HTTP ${response.status}: ${await response.text()}`); process.exit(1);}From the frontend?
Section titled “From the frontend?”Never bundle TYPESAFE_API_KEY into browser code. When a web UI needs Jev, have your own backend (serverless function, Worker) hold the key and expose your own API to the page. See Tool approval for a pattern.