Skip to main content

nearest_effort

Function nearest_effort 

Source
pub fn nearest_effort(
    requested: ReasoningLevel,
    supported: &[ReasoningLevel],
) -> Option<ReasoningLevel>
Expand description

Map a requested reasoning level onto the closest level the model actually supports.

Algorithm (lifted from OpenAI Codex’s nearest_effort):

  1. If the model has no supported levels, return None — caller decides whether to error or silently disable reasoning.
  2. Prefer the highest supported level whose rank is ≤ requested. This is the “graceful downgrade” semantic Claude Code uses (“falls back to the highest supported level at or below the one you set”).
  3. If every supported level is above the requested rank, fall back to the lowest supported level. Better to honor the user’s intent to enable reasoning than to silently disable it.