// Server-side JavaScript (Node 20+ or Bun). Set DECISIONS_API_KEY.
const response = await fetch("https://decisions-api.dev/v1/systemone", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.DECISIONS_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model": "~liquid/d1-ultra-latest",
"state": "I was charged twice for order A-4471. My account is blocked and I need access today. Please refund the duplicate payment.",
"questions": {
"route": {
"type": "choice",
"instructions": "Which team should handle this ticket? Use other when no option fits.",
"criteria": {
"billing": "Payments, charges and refunds",
"technical": "Bugs and product errors",
"account": "Login and account access",
"other": "None of these teams"
}
},
"urgency": {
"type": "score",
"instructions": "Rate the urgency using only the supplied ticket.",
"criteria": [
"Low: routine request",
"Medium: timely help needed",
"High: blocked or time-critical"
]
},
"needs_review": {
"type": "noul",
"instructions": "Does this ticket require a human to review a billing or account action?",
"criteria": {
"true": "A refund, payment correction or blocked account needs review.",
"false": "An informational request that needs no account or payment change."
}
}
}
}),
});
const body = await response.json();
if (!response.ok || body.code !== 0) throw new Error(body.message);
console.log(body.data.result.answers);
console.log(body.data.creditsUsed);