You have a TypeSafe API key and you want typed answers from Jev. Install @tanstack/ai-typesafe. Then pass typesafeDecider to decide().
The adapter covers evaluate only. It talks to TypeSafe over fetch. There is no TypeSafe SDK.
npm i @tanstack/ai @tanstack/ai-typesafepnpm add @tanstack/ai @tanstack/ai-typesafeyarn add @tanstack/ai @tanstack/ai-typesafebun add @tanstack/ai @tanstack/ai-typesafeimport { decide, choice, score, boolean } from "@tanstack/ai";
import { typesafeDecider } from "@tanstack/ai-typesafe";
const ticket = {
subject: "Charged twice for the same invoice",
body: "Please refund the extra payment.",
};
const result = await decide({
adapter: typesafeDecider("jev-latest"),
state: ticket,
questions: {
queue: choice({
instructions: "Which team should handle this ticket?",
options: {
billing: "Payments, invoices, refunds",
tech: "Bugs, outages, integrations",
sales: "Pricing, upgrades, new accounts",
},
}),
urgency: score({
instructions: "How urgent is this ticket?",
levels: ["low", "medium", "high"],
}),
refund: boolean({
instructions: "Is the customer asking for a refund?",
}),
},
});
console.log(result.queue.value);
console.log(result.queue.probability);
console.log(result.queue.confidence);
console.log(result.meta.usage);For question helpers, the result shape, abort, and middleware, see Evaluate.
| Model | Description |
|---|---|
| jev-latest | Current stable Jev alias |
| jev-1.13.0 | Pinned Jev release |
You can also pass other TypeSafe model ids as a string.
The adapter reads your API key from the environment:
TYPESAFE_API_KEY=your-typesafe-api-key| Variable | Required | Description |
|---|---|---|
| TYPESAFE_API_KEY | Yes | Your TypeSafe API key |
Get a key from TypeSafe.
To pass a key directly, use createTypesafeDecider:
import { createTypesafeDecider } from "@tanstack/ai-typesafe";
const adapter = createTypesafeDecider(
"jev-latest",
process.env.MY_TYPESAFE_KEY!,
);Route every request through a gateway with baseURL and defaultHeaders. These two option names are the same on every TanStack AI adapter.
import { createTypesafeDecider } from "@tanstack/ai-typesafe";
const adapter = createTypesafeDecider(
"jev-latest",
process.env.TYPESAFE_API_KEY!,
{
baseURL: "https://gateway.example.com/typesafe",
defaultHeaders: {
"cf-aig-authorization": `Bearer ${process.env.GATEWAY_TOKEN}`,
},
},
);baseUrl and headers are aliases of the same two options. If you set both forms, baseURL and defaultHeaders win.
Creates an evaluate adapter. It reads TYPESAFE_API_KEY from the environment.
Same as typesafeDecider with an explicit API key.
The adapter sends POST /v1/systemone to that base URL.