Start with a Worker that has an AI binding
The fragment below belongs inside an existing Worker with a binding named AI. Follow Cloudflare’s setup instructions first. Pasting it into browser JavaScript will not create that binding.
Send state and questions
The model call uses typesafe/jev. The example asks which team should handle a delivery message. It is a structured question payload; do not replace it with a chat messages array.
Check the result in your Worker
Confirm model access and inspect the actual result before writing the response parser. Cloudflare’s binding, authentication and billing are separate from a direct TypeSafe HTTP request. A working native-API call does not establish that this provider path is configured.
Code example
const result = await env.AI.run("typesafe/jev", {
state: "My package has not arrived.",
questions: {
team: { type: "choice",
instructions: "Which team handles this request?",
criteria: { shipping: "Delivery issues", billing: "Payment issues" }
}
}
});