clefdecide

Clef API guide

Everything you need to call @cf/cloudflare/clef-flash and @cf/cloudflare/clef on Cloudflare Workers AI. Want to test a question first? Use the playground.

Endpoint and authentication

Send a POST to https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run/@cf/cloudflare/clef-flash (or …/clef) with an API token that has Workers AI permission in the Authorization: Bearer header. Inside a Worker, use the AI binding instead.

Request fields

FieldRequiredWhat it is
modelyes"clef-flash" or "clef"; must match the model in the URL.
stateyesThe thing to judge: a string, or structured data such as records, chat logs or app state. Long text is truncated to fit the context window.
questionsyesMap of question id → typed question. 1 to 64 questions. Ids may use letters, digits, _, ., - (max 100 characters).
imagesnoUp to 4 embedded PNG, JPEG or WebP images (data URLs). 4 MiB and 16 megapixels each, 8 MiB total decoded, whole body under 13 MiB. Remote URLs are not accepted.

Question types

noul (yes / no)

{ "type": "noul", "instructions": "Is this support request urgent?" } → { "type": "noul", "noul": 0.97 }, the probability of yes.

choice

criteria is an object of option id → description. The answer has choice (the top option), probabilities per option (sum to 1) and confidence.

score

criteria is an ordered array of levels, lowest first. The answer has score (probability-weighted, can land between levels), a legend, probabilities per level index and confidence.

Full example

curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/cloudflare/clef-flash \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -d '{
    "model": "clef-flash",
    "state": "Checkout has been failing for every customer for the last hour.",
    "questions": {
      "urgent": { "type": "noul", "instructions": "Is this support request urgent?" },
      "team": {
        "type": "choice",
        "instructions": "Which team should handle this request?",
        "criteria": { "billing": "Payments and refunds", "technical": "Outages and errors", "sales": "Plans and upgrades" }
      },
      "severity": {
        "type": "score",
        "instructions": "How severe is the customer impact?",
        "criteria": ["No impact", "Minor", "Major", "Critical"]
      }
    }
  }'

Response

{
  "model": "clef-flash",
  "answers": {
    "urgent":   { "type": "noul", "noul": 0.97 },
    "team":     { "type": "choice", "choice": "technical",
                  "probabilities": { "billing": 0.02, "technical": 0.96, "sales": 0.02 },
                  "confidence": 0.9 },
    "severity": { "type": "score", "score": 2.7,
                  "legend": { "0": "No impact", "1": "Minor", "2": "Major", "3": "Critical" },
                  "probabilities": { "0": 0.01, "1": 0.05, "2": 0.2, "3": 0.74 },
                  "confidence": 0.6 }
  },
  "usage": { "input_tokens": 212, "output_tokens": 3 }
}

Values above are illustrative; field names and shapes follow the published output schema.

Inside a Cloudflare Worker

export default {
  async fetch(request, env) {
    const result = await env.AI.run("@cf/cloudflare/clef-flash", {
      model: "clef-flash",
      state: await request.text(),
      questions: {
        spam: { type: "noul", instructions: "Is this message spam?" }
      }
    });
    // result.answers.spam.noul is the probability of "yes", from 0 to 1
    return Response.json(result.answers.spam);
  }
};

Pricing and limits

Clef-FlashClef
Model id@cf/cloudflare/clef-flash@cf/cloudflare/clef
Size9B27B
Price$0.09 per M input tokens$0.24 per M input tokens
Context window65,536 tokens65,536 tokens
Visionyesyes

Tips for reliable decisions

Sources: Cloudflare Workers AI model pages for clef-flash and clef, checked 2026-10-02.