Configure the supported Gateway path
After designing a question and policy, you need a transport. Vercel AI Gateway exposes Jev through AI SDK 7's experimental evaluation API, not through a chat endpoint. evaluation model: an AI SDK model that answers typed questions about supplied state instead of generating a message is created with gateway.evaluationModel("typesafe-ai/jev"). The verified catalog ID is typesafe-ai/jev; one older example used typesafe-ai/jev-latest, which the current catalog does not list.
Keep AI_GATEWAY_API_KEY on the server or use supported Vercel OIDC. TypeSafe's official native SDK instead reads TYPESAFE_API_KEY; the direct AI SDK TypeSafe provider reads TYPESAFE_AI_API_KEY. These are three separate integrations. An environment variable with the wrong name can leave the intended client unauthenticated even when another integration in the same application works. Pin an AI SDK version because experimental_evaluate can change in a patch release; it appeared in 7.0.105, and 7.0.106 was current when this course was verified.
A string model ID can use the application's default provider configuration. The explicit gateway.evaluationModel form above makes the selected provider visible during review and prevents an unrelated default from changing the transport. Gateway evaluation is supported through AI SDK evaluation; its OpenAI-, Anthropic-, and Cohere-compatible endpoints do not provide this modality. The internal evaluation transport is not a stable cURL contract.
Trace this example from input to result
Customer choice
A customer sends a duplicate-charge ticket.
Request or event
A server route calls experimental_evaluate with state, typed questions, a deadline, and Gateway provider options.
Backend behavior
Gateway routes the evaluation to Jev and AI SDK validates the normalized result.
Customer sees
The application routes the ticket or asks for review; it does not expose provider credentials.
Diagnostic reasoning
Separate local input validation, Gateway authentication and routing, provider response, result validation, and application policy.
| Customer sees | Application does | Jev returns |
|---|---|---|
| A routed support ticket | Calls Gateway and applies a threshold | Typed judgments normalized by AI SDK |
Build the evaluation request
import { experimental_evaluate as evaluate, gateway } from "ai";
const result = await evaluate({
model: gateway.evaluationModel("typesafe-ai/jev"),
state: {
message: "My card was charged twice. Please refund one charge.",
account: { refundEligible: true },
},
questions: {
refundIntent: {
type: "boolean",
instructions: "Is the customer asking for a refund?",
criteria: { true: "Requests reversal", false: "Does not request reversal" },
},
queue: {
type: "choice",
instructions: "Which queue best fits?",
criteria: { billing: "Charges or refunds", technical: "Product failures", other: "Neither" },
},
frustration: {
type: "score",
instructions: "How frustrated is the customer?",
criteria: ["Calm", "Frustrated", "Very angry"],
},
},
providerOptions: { gateway: { zeroDataRetention: true } },
abortSignal: AbortSignal.timeout(15_000),
});
const refundProbability = result.answers.refundIntent.probability;
const route = refundProbability >= 0.85 ? "billing-review" : "general-review";
console.log({ route, usage: result.usage });
Run this example only in a server-side TypeScript project with a pinned AI SDK version. The ticket and 0.85 threshold are synthetic teaching choices. The code selects a review queue and does not move money.
State may be a string, object, or array; an array is still one state, not a batch. Question IDs become answer keys. Gateway calls native Noul questions boolean and calls their returned value probability. Choice criteria must be nonempty, Score requires at least two ordered levels, the current TypeSafe provider limits Choice to 255 options and Score to 10 levels, and the result arrives as one complete response rather than a stream.
Read normalized answers and metadata
Boolean answers contain type and probability. Choice contains choice and may contain probabilities. Score contains score and may contain index-keyed probabilities. TypeSafe-specific Choice and Score confidence appears under result.providerMetadata.typesafe.confidence, keyed by question ID. provider metadata: provider-specific fields preserved beside AI SDK's normalized result should be treated as optional at the generic interface boundary.
The Gateway catalog and the native API describe the same provider through different contracts. Gateway uses boolean and probability where native TypeSafe uses noul and noul. Gateway puts Choice and Score confidence in providerMetadata.typesafe.confidence; native responses put confidence on each answer. Gateway usage uses camel-case token fields, while native usage uses snake case. Keep an adapter at the application boundary instead of mixing both shapes throughout business code.
Usage uses inputTokens, outputTokens, and totalTokens. Preserve these counts separately from money: a free output-token rate still permits a nonzero output-token count. Independent questions share state, but adding questions still increases input. Estimate cost from measured request usage rather than multiplying a ticket's character length by a guessed conversion. Include calls that end in review and calls repeated after transient failures when estimating the cost per completed workflow.
AI SDK validates distributions: Choice probabilities must cover labels, sum to one within tolerance, and agree with the chosen maximum. Values are not silently normalized. Structural failure after the provider call becomes invalid response data, not a reason to retry until an answer passes.
After a successful call, validate that the application knows every returned Choice label before mapping it to a queue. Treat missing optional distributions or provider metadata as unavailable evidence rather than substituting zero confidence. Log the AI SDK version, requested Gateway model ID, question version, policy version, usage, latency, and final route. Because Gateway's modelId may echo typesafe-ai/jev, it is not evidence of the resolved native Jev release. Use native version pinning when immutable backend selection is a requirement.
A Choice response is rejected after a successful provider call
InvalidResponseDataError · probabilities sum to 0.93Classify this as a response-contract failure. Capture safe request identifiers and package versions, do not retry it as overload, and route the ticket to review. Check whether a provider or AI SDK upgrade changed rounding or normalization before changing business policy.
Set deadlines and handle Gateway failures
The live catalog marks Jev as an evaluation model and lists both ZDR and no-training support. zeroDataRetention: true asks Gateway to enforce that requirement for this request. If no compliant provider is available, Gateway returns an error instead of silently using a retaining route. ZDR does not erase application logs, traces, queue payloads, or error reports.
The inspected AI SDK core allows at most three attempts under its default maxRetries: 2. Retry backoff and server-directed waits still consume the workflow budget. The 15-second abort signal bounds attempts and waits; set it below the caller's timeout so the application can return a controlled fallback.
The evaluation call has no dedicated timeout option in the inspected implementation. A route handler that also retries can multiply the SDK attempts, so choose one owner for immediate retries and another explicit policy for delayed queue delivery. Cancellation is useful only if the caller preserves it through the integration; do not catch an abort and silently start a new evaluation with a fresh deadline.
A production handler should catch errors outside the evaluation call. InvalidArgumentError and unsupported-question errors point to code or payload defects and should go to configuration review. InvalidResponseDataError means a provider response violated the normalized contract; preserve safe identifiers and package versions, then fall back without retrying for a preferred semantic answer. Provider lookup errors require model or provider configuration repair. Transient network, throttling, and overload errors can use the SDK's bounded retry behavior, followed by general review when the deadline expires.
Local bad inputs raise InvalidArgumentError; unsupported types raise Experimental_EvaluationUnsupportedQuestionTypeError; malformed output raises InvalidResponseDataError. Provider and model lookup can raise NoSuchProviderError, NoSuchModelError, or UnsupportedModelVersionError. ZDR routing can fail rather than silently choose a noncompliant provider.
Specify a Gateway call
Your answers stay in this browser. Write enough that another engineer could continue the investigation.
Dig deeperUnderstand the Gateway transport boundary+
Gateway's SDK provider uses an evaluation-specific internal transport and specification version. That path is an implementation detail, not a public cURL or Python contract. Use AI SDK for Gateway evaluation. Use the native TypeSafe HTTP API when another language or immutable native model pin is required.