Skip to content

fix(relay): preserve xhigh/max intent when mapping Claude thinking budgets #438

Closed

Description

@LIghtJUNction

Upstream tracking: QuantumNous/new-api#7522
Related upstream bug: QuantumNous/new-api#7508

What changed upstream

new-api found that Anthropic-native thinking.type=enabled + thinking.budget_tokens was being collapsed at high, so larger budgets could never produce xhigh or max. PR #7522 changes the shared budget→effort ladder to:

  • 0 → none
  • <=1024 → low
  • <=8192 → medium
  • <16000 → high
  • <32000 → xhigh
  • >=32000 → max

It also adjusts Gemini 2.5 high to a 12288 token budget so the effort↔budget round trip does not cross the new xhigh threshold.

Gap in api.lmm.best

main currently uses an older Claude Messages → OpenAI compatibility mapper in:

apps/api-go/relaykit/relayconvert/internal/claude_messages/to_oai_chat_req.go

Current behavior:

  • mapClaudeThinkingToReasoningEffort() maps enabled budgets only to low / medium / high, with every budget above 3072 saturating at high.
  • mapClaudeReasoningEffortFromEffort() also explicitly downgrades xhigh to high.
  • The newer shared relayconvert/reasoning.EffortFromBudget implementation changed by upstream does not exist in this fork yet, so #7522 cannot be cherry-picked cleanly.

That means Claude-format callers using larger manual-thinking budgets cannot express stronger reasoning intent through LMM's GPT-compatibility path.

Why not copy #7522 directly yet

The upstream PR is still open, and the compatibility boundary differs here. In upstream issue #7508 the tested OpenAI-compatible provider accepts xhigh but rejects max; blindly emitting max for every >=32000 budget could turn requests that currently succeed as high into provider-side 400s. LMM also has an older converter where explicit xhigh is intentionally collapsed today, so the supported outbound effort set needs to be defined once instead of changing one helper in isolation.

Suggested LMM-native approach

  1. Introduce one small budget→effort helper for the Claude Messages → OpenAI compatibility path, using the upstream ladder as the semantic source of truth.
  2. Preserve xhigh when the target OpenAI-compatible path supports it instead of unconditionally collapsing it to high.
  3. Gate or clamp max according to the actual outbound dialect/model capability; do not make a previously accepted request fail only because its budget crossed 32000.
  4. Keep OpenRouter's native reasoning.max_tokens behavior unchanged.
  5. Keep billing, model-price locks, groups, /fast, OAuth restrictions, provider selection and administrator-assistant settings untouched.

Acceptance criteria

  • Regression tests cover budget boundaries 0, 1024, 8192, 8193, 15999, 16000, 31999, 32000, 64000.
  • A supported GPT-compatible target can receive xhigh from sufficiently large Claude budget_tokens.
  • max is emitted only when the target path declares/supports it; otherwise behavior is explicitly clamped/fallback-tested rather than failing silently or producing an upstream 400.
  • Explicit output_config.effort and inferred thinking.budget_tokens follow the same capability policy.
  • Existing low/medium/high mappings, OpenRouter reasoning payloads, pricing/group/model-lock/fast/OAuth/custom assistant behavior remain unchanged.
  • go test passes for the affected relaykit converter package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions