Keep the call in a server route
Place the fragment below in a server-side handler. Define payload from a validated request with fixed question criteria. The fragment is the provider call, not a complete public API route.
Add the key to the deployed environment
Set TYPESAFE_API_KEY in the project’s server environment and deploy with that setting. Do not use a NEXT_PUBLIC_ variable. If the call works locally but fails after deployment, check the deployed environment before changing the request schema.
Decide whether you need the gateway path
Vercel lists TypeSafe AI in its AI Gateway catalog. The code below calls TypeSafe directly and uses its key. For gateway routing, follow the gateway’s current structured-model instructions. Do not assume this fragment demonstrates an AI SDK adapter.
Test the route before connecting a UI
Verify one successful response and one provider failure in your server route. Return only the fields the UI needs. If other users can call it, apply your application’s authentication and request limits before it makes a paid provider call.
Code example
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),
signal: AbortSignal.timeout(30000),
});
if (!response.ok) throw new Error(`Jev HTTP ${response.status}`);
const result = await response.json();