typescript · 2026-09-23
REST Jev Review Gate
Call the Jev System One endpoint without an SDK, using bounded retries and explicit response checks.
Use cases
- Edge services
- Small server handlers
- SDK evaluation
Dependencies and versions
- Node.js 20+
Expected behavior
The request returns a validated choice or human_review after at most three attempts.
Failure behavior
Permanent HTTP failures, timeouts after the retry budget, and malformed payloads stop the workflow.
Code template
const API_URL = 'https://api.typesafe.ai/v1/systemone';
const MAX_RETRIES = 2;
const apiKey = process.env.TYPESAFE_API_KEY;
if (!apiKey) throw new Error('TYPESAFE_API_KEY is required');
const requestBody = {
model: 'jev-latest',
state: { ticket: 'I was charged twice. Please fix this ASAP.' },
questions: {
route: {
type: 'choice',
instructions: 'Choose the support queue.',
criteria: { billing: null, technical: null, other: null },
},
},
};
const retryable = (status) =>
status === 408 || status === 429 || status >= 500;
let response;
for (let attempt = 0; attempt <= MAX_RETRIES; attempt += 1) {
response = await fetch(API_URL, {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
signal: AbortSignal.timeout(10_000),
});
if (response.ok || !retryable(response.status) || attempt === MAX_RETRIES) {
break;
}
await new Promise((resolve) => setTimeout(resolve, 500 * 2 ** attempt));
}
if (!response?.ok) {
throw new Error(`TypeSafe request failed with HTTP ${response?.status}`);
}
const payload = await response.json();
const decision = payload?.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: payload.model });Sources
This example calls a third-party service. Before copying it, verify the current API, dependency version, cost, privacy requirements, and service terms.