SuperAPI AI Directory

Clef - Cloudflare's open-source decision model family

Author: AI小集 · Original source: AI工具集

What is Clef

Clef is an open-source decision model family from Cloudflare that sets the context and then decides the next action. Unlike chat models that generate open text, Clef defines questions on the fly within a request, assigns probabilities to each option, and lets code use them to route or block accordingly, without repeatedly retraining for newly added categories. In the Clef family, the 27B Clef focuses on accuracy, while the 9B Clef-flash is as fast as 38.8 ms median latency, making it suitable for embedding into the hot path of Agents.

Clef

Clef's main features

  • Probabilistic decision-making: Takes state and typed questions as input, outputs the probability of each option, and code can directly use it to route, block, or escalate to a human.
  • Three question types: Supports noul, choice, and score, with up to 64 questions per request.
  • Visual classification: Built-in vision encoder, can embed up to 4 images and score them together with text.
  • 64K context: Can accommodate more complete inputs such as long logs, tickets, and JSON states.
  • Jev API compatible: The request schema is aligned with Jev, so migration basically only requires changing the endpoint and model name.
  • Non-autoregressive inference: After a single prefill, it scores valid options in parallel without generating text token by token, resulting in latency far lower than general-purpose LLMs.
  • Low-latency edge hosting: Relying on the Workers AI global GPU network, Clef has a median of 209 ms and Clef-flash only 38.8 ms, making it suitable for the hot path.

Clef's technical principles

  • Non-autoregressive decision architecture: Clef first performs one prefill-only forward computation on the input, then scores the valid schema options defined in the request in parallel, deriving structured results directly from internal representations.
  • Two-stage attention routing: Each valid option first extracts context relevant to itself from the prompt, then lets each field parameter cross-attend to each other and connect back to the original payload for joint modeling, while using a lexical prior to maintain semantic consistency across options, ultimately aggregating the evidence into scores under schema constraints.
  • Frozen backbone + lightweight adaptation: The backbone is Qwen3.8-27B and Qwen3.5-9B, with the main trunk frozen and only the routing head and rank-256 LoRA adapters jointly optimized, obtaining decision-making capability with a very small number of trainable parameters and reducing training and deployment costs.
  • Calibration-oriented training objectives: Post-training uses label-smoothed cross-entropy to ensure outputs fall within the valid schema, combined with Brier loss specifically for calibrating probabilities, making the output probability values themselves trustworthy.
  • RLCD reinforcement learning: The self-developed Reinforcement Learning for Calibrated Decisions serves as a secondary optimization objective, giving partial credit for adjacent ordinal options, full credit for exact hits, and adding a reference penalty to prevent distribution drift, improving accuracy and generalization.
  • Data strategy: The training data is an internal synthetic dataset, and generalization is enhanced by permuting field order, prompt, and schema structure, making the model insensitive to how questions are phrased and able to adapt to new categories defined on the fly at request time.
Dig into GitHub

Follow on WeChat and reply "open source" to join theAI Open Source Project Communication Group

How to use Clef

  • Confirm account and permissions: Register a Cloudflare account, get the Account ID and API Token, and enable Workers AI.
  • Choose a model: Choose @cf/cloudflare/clefor @cf/cloudflare/clef-flash。
  • Construct the request body: Write model、state(text/JSON state) and questions(1–64 noul/choice/score type questions, with criteria boundaries clearly written).
  • Make the call: Use REST POST to /accounts/{id}/ai/run/@cf/cloudflare/clef, or call in a Worker through the env.AI.run() binding.
  • Parse the probability results: From response.answers , read the option probabilities/weighted scores for each question, and use "highest option + probability threshold" for routing or blocking.
  • Add image input (optional): When visual judgment is needed, embed PNG/JPEG/WebP bytes in the request; do not pass remote URLs.
  • Load test before launch: Test latency and accuracy with your own state length and question count, then decide whether to switch fully or route by risk between flash/clef.
  • Advanced fine-tuning (optional): When domain labels are special, accumulate data through AI Gateway and use the FDE team's RL fine-tuning service to customize the model.

Clef's core advantages

  • Fast: Non-autoregressive parallel scoring + edge GPU hosting; Clef has a median latency of 209ms and Clef-flash only 38.8ms, 2.5×–13× faster than Jev, so it can go in the hot path.
  • High accuracy: Ranked first on the Jev Decision Index, highest score on 7 of 10 official decision benchmarks, and won 3 of 4 in the Typesafe workflow evaluation.
  • Add categories without retraining: Categories are defined temporarily in the request; adding new labels does not require retraining the model like traditional classifiers.
  • Calibratable probabilities: Brier loss + RLCD training makes the output probabilities themselves trustworthy, so thresholds can be set directly for automated decisions.
  • Native multimodal: Built-in vision encoder can classify images, while Jev currently only does text.
  • Double the context: 64K context (Jev is 32K), able to fit longer logs and states.
  • Zero-cost migration: Fully compatible with the Jev API; just change the endpoint and model name for a smooth replacement.

Clef's project address

  • Project website:https://blog.cloudflare.com/clef-decision-models/
  • HuggingFace model repository:
    • https://huggingface.co/Cloudflare/clef
    • https://huggingface.co/Cloudflare/clef-flash

Clef's comparison with similar competitors

Dimension Clef / Clef-flash(Cloudflare) Jev (Typesafe AI)
Category positioning Decision model (probabilistic classification, Jev API compatible) Decision model (category pioneer)
Context 64K 32K
Visual input ✅ Built-in vision encoder (up to 4 embedded images) ❌ Currently text only
Median latency 209.3 ms / 38.8 ms 524.1 ms
p95 latency 238.6 ms / 122.4 ms 536.0 ms
Jev Decision Index First Reference baseline
Quality benchmark Highest score on 7 of 10 Behind on most items
Typesafe workflow evaluation Won 3 of 4 (invoice/customer service/security incident) Slightly higher on 1 item: Agent observability
Question definition method Defined temporarily in the request; add categories without retraining Similar mechanism (API compatible)

Clef Use Cases

  • Customer Service Ticket Triage: Input the ticket content and screenshots, and in a single request simultaneously determine whether it is urgent, which team it should be routed to, and its severity score, with automatic escalation to a human when confidence is low.
  • Threat Intelligence and Anti-Phishing: Combined with Browser Run to fetch and render web pages, perform multi-label classification on domains/pages; official testing shows the entire process takes only 2.2 seconds.
  • Bot Traffic Determination: On the gateway hot path, use Clef-flash to quickly determine whether a crawler is benign or malicious, blocking or allowing it at the millisecond level.
  • Pre-Review of Agent Tool Invocations: Before an Agent performs a high-risk operation, first ask Clef "whether it should be done and which tool to use," and decide whether to execute or request confirmation based on a probability threshold.