AI Gateway Decision Quickstart
Ask a typed question about application state through AI Gateway and get a boolean answer back. This quickstart uses the experimental Decision API, available as experimental_decide in ai 7.0.128 or later. Earlier AI SDK 7 releases call it experimental_evaluate, which still works as a deprecated alias.
Paste this prompt into a coding agent with terminal access:
Add a decision request through AI Gateway in the current environment. Use the AI Gateway skill for this task. If it is unavailable, run npx skills add vercel/vercel-plugin --skill ai-gateway, then find and read its SKILL.md before continuing. Reuse the environment's Node.js project, framework, and package manager when possible. Otherwise, add the smallest TypeScript entry point and explain why. Use ai 7.0.128 or later for this quickstart, upgrading an existing ai dependency if it is older, and add only required dependencies. Read AI_GATEWAY_API_KEY from the environment. If it is missing, run npx vercel@latest whoami and pause for login if needed. Determine the team, then run npx vercel@latest --scope <team-slug> ai-gateway api-keys create --name <descriptive-name>. Capture stdout directly into AI_GATEWAY_API_KEY for the request or existing ignored secret storage, and never expose the value. Use typesafe-ai/jev with experimental_decide from the ai package to decide whether a support agent issued a refund, print the structured boolean answer, run the result, and report the output.
Use Node.js 22.18 or later and a team with available AI Gateway Credits. Export AI_GATEWAY_API_KEY in your current shell. If you need a key, open the Create API Key dialog.
export AI_GATEWAY_API_KEY="your_ai_gateway_api_key"Install the latest AI SDK:
pnpm add ai@latestCreate index.mts:
import { experimental_decide as decide } from 'ai';
const result = await decide({
model: 'typesafe-ai/jev',
state: 'The support agent issued a full refund to the customer.',
questions: {
refunded: {
type: 'boolean',
instructions: 'Was a refund issued?',
},
},
});
console.log(JSON.stringify(result.answers, null, 2));Run the script:
node index.mtsThis quickstart logs only result.answers. The probability can vary, but you should see output with this shape:
{
"refunded": {
"type": "boolean",
"probability": 0.99
}
}- Make decisions through the HTTP API
- Use the OpenAI SDK with the OpenAI-Compatible Decisions API
- Migrate an existing client to the TypeSafe-compatible API
- Add choice and score questions
- Ask multiple questions or pass structured state
- Learn how to classify, route, and score with Jev and AI SDK and route form submissions
- Learn how to automatically approve tool calls in eve with Jev
- Build a product review moderation workflow with Jev and TanStack AI
- Browse decision models
Was this helpful?