jevfieldnotes
INTEGRATIONS

Call Jev with Node.js fetch

Load a request file and send it from a server-side JavaScript module.

2 MIN READ · UPDATED 20 SEP 2026

Prepare the file and key

Download request.json from Request Builder. Set TYPESAFE_API_KEY in the terminal where Node runs. Save the code below as request.mjs beside request.json. Use a Node runtime with fetch and AbortSignal.timeout.

Run node request.mjs

The script checks that the key exists, reads the request file and prints a successful response. It stops after a 30-second deadline. A failed HTTP status becomes an error instead of being handled as a valid prediction.

Validate before using the answer

For the default builder request, the result is under answers.decision. Before using it to select a handler, check the answer type and allowed labels. A TypeScript type assertion does not inspect a remote response at runtime.

Code example

import { readFile } from "node:fs/promises";

const key = process.env.TYPESAFE_API_KEY;
if (!key) throw new Error("Set TYPESAFE_API_KEY first");
const payload = JSON.parse(await readFile("request.json", "utf8"));
const response = await fetch("https://api.typesafe.ai/v1/systemone", {
  method: "POST",
  headers: { Authorization: `Bearer ${key}`,
    "Content-Type": "application/json" },
  body: JSON.stringify(payload),
  signal: AbortSignal.timeout(30000),
});
if (!response.ok) throw new Error(`Jev HTTP ${response.status}`);
console.log(await response.json());