Jev with the Vercel AI SDK
Call Jev from TypeScript through the AI SDK's experimental_evaluate function and Vercel AI Gateway, including routing logic and tests with a mock model.
- In the AI SDK, Jev is called with
experimental_evaluate, and the model id istypesafe-ai/jev. - It goes through Vercel AI Gateway, so you use your gateway key, not a TypeSafe key.
- Needs
aiversion 7.0.105 or later. - One naming difference: the AI SDK calls Noul
boolean, and the answer field isprobability. - There is a mock evaluation model for unit tests.
One question
import { experimental_evaluate as evaluate } from "ai";
export async function wasRefunded(transcript: string) {
const result = await evaluate({
model: "typesafe-ai/jev",
state: transcript,
questions: {
refunded: {
type: "boolean",
instructions: "Was a refund issued to the customer?",
criteria: {
true: "The agent confirmed that money was returned to the customer.",
false: "No refund was issued, or the refund was declined.",
},
},
},
});
return result.answers.refunded.probability;
}Routing a ticket
Three questions, one call, then plain code decides.
import { experimental_evaluate as evaluate } from "ai";
export async function routeTicket(ticket: {
subject: string;
message: string;
plan: string;
}) {
const result = await evaluate({
model: "typesafe-ai/jev",
state: ticket,
questions: {
department: {
type: "choice",
instructions: "Which team should handle this ticket?",
criteria: {
billing: "Charges, invoices, and refunds",
technical: "Bugs, outages, and integration failures",
account: "Login, permissions, and profile changes",
other: "Anything that does not fit the other teams",
},
},
severity: {
type: "score",
instructions: "How severe is the issue for the customer?",
criteria: [
"Cosmetic or informational",
"Degraded, but a workaround exists",
"Blocking with no workaround",
"Blocking and causing financial or data loss",
],
},
requestsRefund: {
type: "boolean",
instructions: "Is the customer asking for money back?",
},
},
providerOptions: {
gateway: { zeroDataRetention: true },
},
});
const { department, severity, requestsRefund } = result.answers;
const confidence = result.providerMetadata?.typesafe?.confidence as
| Record<string, number>
| undefined;
if ((confidence?.department ?? 0) < 0.6) {
return { action: "human-review" as const };
}
return {
action: "assign" as const,
queue: department.choice,
severity: severity.score,
refundRequested: requestsRefund.probability >= 0.8,
};
}Note where confidence lives here: in result.providerMetadata.typesafe.confidence, keyed by question name. If it is missing, treat it as zero and send the case to a person.
Testing without the network
The AI SDK ships a mock evaluation model, so you can test your routing logic with fixed answers.
import { Experimental_EvaluationMockModelV4 as MockEvaluationModel } from "ai/test";
const model = new MockEvaluationModel({
doEvaluate: async () => ({
answers: {
department: {
type: "choice",
choice: "technical",
probabilities: { billing: 0.05, technical: 0.93, account: 0.02, other: 0 },
},
severity: { type: "score", score: 2.4, probabilities: { 0: 0, 1: 0.1, 2: 0.4, 3: 0.5 } },
requestsRefund: { type: "boolean", probability: 0.2 },
},
warnings: [],
providerMetadata: { typesafe: { confidence: { department: 0.91 } } },
}),
});To use it, let routeTicket accept an optional model argument that defaults to "typesafe-ai/jev", and pass the mock in tests.
Other ways in
| Route | When it makes sense |
|---|---|
AI SDK experimental_evaluate | You are already on the AI SDK in TypeScript |
| TypeSafe SDKs pointed at AI Gateway | You want the TypeSafe client but one bill through Vercel |
| TypeSafe API directly | Simplest setup, no gateway |
| OpenRouter, Cloudflare | You already route models through one of them |
Where this page's facts come from▾
Vercel's How to classify, route, and score with Jev and AI SDK, the AI Gateway evaluation docs, and the changelog entry AI Gateway now supports TypeSafe clients and an HTTP API for Jev. The code is shortened from Vercel's examples.