2026-10-06
Clef Model Example Code: Workers AI Inference (System One Schema)
Copy-paste Clef model example code for Cloudflare Workers AI �?state + noul/choice/score questions, clef and clef-flash model ids, and playground tips.
This page is a practical Clef model example code and Clef model inference example pack for developers who already know they want System One–style decisions �?not chat. ## 1) Request body (playground / HTTP shape)
json
{
"state": "User cart checkout failed 3 times. Payment provider returning 503.",
"questions": [
{
"id": "next",
"type": "choice",
"instructions": "What should the agent do next?",
"options": ["retry_payment", "switch_provider", "notify_user", "escalate"]
},
{
"id": "urgent",
"type": "noul",
"instructions": "Is this incident urgent for on-call?"
}
],
"model": "clef-flash"
}
state: text or JSON string your agent already tracksquestions: typed schema (noul|choice|score)model:cleforclef-flash(see Clef-flash vs Clef)
ts
// Pseudocode �?wire to your Worker + AI binding
const model = "@cf/cloudflare/clef-flash"; // or "@cf/cloudflare/clef"
const result = await env.AI.run(model, {
// Map playground fields into the official Clef / System One input
// your adapter builds from state + typed questions
...clefPayload,
});
// result �?per-question option probabilities
This site’s playground adapter stays Jev / System One compatible for demos. ## 3) REST sketch (account token)
bash
curl -X POST \
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai/run/@cf/cloudflare/clef-flash" \
-H "Authorization: Bearer $CF_API_TOKEN" \
-H "Content-Type: application/json" \
-d @payload.json
4) Minimal agent loop 1. Assemble `state` from tools / tickets / session. 2. Ask one **routing** question with a closed option list ([Clef for agent routing](/blog/clef-for-agent-routing/)). 3. Take `argmax` or apply a confidence threshold (e.g. require top probability �?0.55). 4. Log state hash + probabilities for later offline eval. ## 5) Docs + live demo - Short ops notes: [Docs �?How to use Cloudflare Clef Workers AI](/docs/) - Live UI: [Try Clef online](/#playground) - Schema deep dive: [State & question schema](/blog/how-to-use-clef-state-question-schema/) ## Related reading - [Clef vs Jev decision model](/blog/clef-vs-jev-decision-model/) - [How to run Clef locally](/blog/how-to-run-clef-locally/) - [Clef-flash vs Clef benchmark](/blog/clef-flash-vs-clef-benchmark/)
Ready to test? Open the Clef Decision Playground.