openclaw - ✅(Solved) Fix pi-ai: || 1024 fallback silently activates deprecated thinking on every Anthropic API call [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#63016Fetched 2026-04-09 07:59:31
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1referenced ×1

The || 1024 fallback in pi-ai/dist/providers/anthropic.js silently activates deprecated budget-based thinking on every Anthropic API call when no valid thinking configuration is present. There is no log warning, no schema error, and no documentation indicating this will happen.

Error Message

The || 1024 fallback in pi-ai/dist/providers/anthropic.js silently activates deprecated budget-based thinking on every Anthropic API call when no valid thinking configuration is present. There is no log warning, no schema error, and no documentation indicating this will happen.

  1. params.thinking in the model entryparams is not a recognised key in the ModelDefinitionSchema. The schema is declared .strict(), so the block is silently discarded on gateway start. No error or warning is surfaced.

Root Cause

The || 1024 fallback in pi-ai/dist/providers/anthropic.js silently activates deprecated budget-based thinking on every Anthropic API call when no valid thinking configuration is present. There is no log warning, no schema error, and no documentation indicating this will happen.

Fix Action

Fix / Workaround

Correct configuration (workaround)

PR fix notes

PR #63057: fix(anthropic): replace || 1024 fallback with safe budget_tokens guard

Description (problem / solution / changelog)

Problem — issue #63016

In buildAnthropicParams (src/agents/anthropic-transport-stream.ts), the legacy budget-based thinking block was built with:

params.thinking = {
  type: "enabled",
  budget_tokens: options.thinkingBudgetTokens || 1024,
};

The || operator coerces any falsy value — including the legitimate 0 produced by adjustMaxTokensForThinking when maxTokens is too small — to 1024. This silently activates deprecated type: "enabled" thinking with a non-zero budget on every API call, even trivial ones (file reads, short messages), wasting tokens and bypassing user intent.

A secondary problem: when adjustMaxTokensForThinking returns thinkingBudget: 0, sending budget_tokens: 0 to the Anthropic API results in a HTTP 400 error.

Fix

Two-line change in buildAnthropicParams:

// Before
params.thinking = {
  type: "enabled",
  budget_tokens: options.thinkingBudgetTokens || 1024,
};

// After
const budgetTokens = options.thinkingBudgetTokens ?? 1024;
if (budgetTokens > 0) {
  params.thinking = {
    type: "enabled",
    budget_tokens: budgetTokens,
  };
}
  1. ?? 1024 — nullish coalescing preserves an explicit 0 instead of coercing it to 1024.
  2. if (budgetTokens > 0) — when the token envelope is too small for thinking (budget = 0), the thinking block is omitted entirely rather than sending an API-rejecting budget_tokens: 0.

All well-formed thinking configurations (explicit positive budgets, resolved non-zero budgets) are unaffected.

Changed files

  • src/agents/anthropic-transport-stream.ts (modified, +13/-4)

Code Example

params.thinking = {
  type: "enabled",
  budget_tokens: options.thinkingBudgetTokens || 1024,
};

---

{
  "agents": {
    "defaults": {
      "thinkingDefault": "medium"
    }
  }
}
RAW_BUFFERClick to expand / collapse

Bug: || 1024 fallback silently activates deprecated budget-based thinking on every Anthropic API call

Description

The || 1024 fallback in pi-ai/dist/providers/anthropic.js silently activates deprecated budget-based thinking on every Anthropic API call when no valid thinking configuration is present. There is no log warning, no schema error, and no documentation indicating this will happen.

What happens

In anthropic.js, when thinkingBudgetTokens is undefined (i.e., no valid thinking config exists), the following code path executes on every API call:

params.thinking = {
  type: "enabled",
  budget_tokens: options.thinkingBudgetTokens || 1024,
};

The || 1024 fallback fires, sending type: "enabled" with budget_tokens: 1024 (the minimum non-zero value) to the Anthropic API on every request — including trivial actions such as file reads and short messages.

Why the thinking config ends up undefined

Two common configuration attempts fail silently:

  1. params.thinking in the model entryparams is not a recognised key in the ModelDefinitionSchema. The schema is declared .strict(), so the block is silently discarded on gateway start. No error or warning is surfaced.

  2. thinkingBudgets as a top-level key — does not exist in the schema. openclaw config validate catches this one, but users may not run it.

In both cases, the user believes they've configured thinking, but the config is inert, and the || 1024 fallback takes over.

Impact

  • Every API call to claude-opus-4-6 (or any model where supportsAdaptiveThinking() returns false in the fallback path) gets budget_tokens: 1024 thinking overhead.
  • This wastes tokens on trivial actions (reading files, short replies).
  • The deprecated type: "enabled" / budget_tokens model is sent instead of the current type: "adaptive" / effort model for Opus 4.6.
  • Affects any OpenClaw installation running claude-opus-4-6 without a correctly configured thinkingDefault.

Expected behavior

When thinkingBudgetTokens is not explicitly set (i.e., undefined), the fallback should either:

  • Omit the thinking block entirely (no thinking unless explicitly configured), or
  • Require an explicit opt-in rather than silently defaulting to budget_tokens: 1024.

At minimum, a warning log should be emitted when the fallback fires, so users know thinking is being activated by default.

Correct configuration (workaround)

The correct way to enable adaptive thinking for Opus 4.6 is:

{
  "agents": {
    "defaults": {
      "thinkingDefault": "medium"
    }
  }
}

This routes through mapThinkingLevelToEffort("medium")supportsAdaptiveThinking("claude-opus-4-6") returns true → Anthropic API receives { thinking: { type: "adaptive" }, output_config: { effort: "medium" } }.

Valid thinkingDefault values from the Zod schema: off, minimal, low, medium, high, xhigh.

How we found it

  1. Located pi-ai provider file at the installed path.
  2. Read the supportsAdaptiveThinking(), mapThinkingLevelToEffort(), and streamSimpleAnthropic() call chain in anthropic.js.
  3. Read the ModelDefinitionSchema Zod definition in daemon-cli.js — confirmed reasoning is a boolean, thinkingDefault is a valid string enum, and neither thinkingBudgets nor params.thinking exist in the schema.
  4. Confirmed with openclaw config validate and clean gateway restart.

Environment

  • OpenClaw 2026.4.5
  • Model: anthropic/claude-opus-4-6
  • macOS (arm64)

extent analysis

TL;DR

To fix the issue, update the anthropic.js file to omit the thinking block when thinkingBudgetTokens is undefined or add a warning log when the fallback fires.

Guidance

  • Identify and correct the invalid configuration attempts that cause thinkingBudgetTokens to be undefined, such as using params.thinking in the model entry or thinkingBudgets as a top-level key.
  • Update the anthropic.js file to either omit the thinking block when thinkingBudgetTokens is undefined or require an explicit opt-in instead of silently defaulting to budget_tokens: 1024.
  • Verify the correct configuration by setting thinkingDefault to a valid value (e.g., "medium") in the agents section of the configuration file.
  • Test the API calls to ensure the thinking block is not sent with budget_tokens: 1024 when thinkingBudgetTokens is undefined.

Example

// Update anthropic.js to omit the thinking block when thinkingBudgetTokens is undefined
if (options.thinkingBudgetTokens !== undefined) {
  params.thinking = {
    type: "enabled",
    budget_tokens: options.thinkingBudgetTokens,
  };
}

Notes

The issue is specific to the anthropic/claude-opus-4-6 model and OpenClaw version 2026.4.5. The correct configuration and workaround may vary depending on the model and version being used.

Recommendation

Apply the workaround by updating the anthropic.js file to omit the thinking block when thinkingBudgetTokens is undefined or add a warning log when the fallback fires, as this will prevent the deprecated budget-based thinking from being activated silently.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

When thinkingBudgetTokens is not explicitly set (i.e., undefined), the fallback should either:

  • Omit the thinking block entirely (no thinking unless explicitly configured), or
  • Require an explicit opt-in rather than silently defaulting to budget_tokens: 1024.

At minimum, a warning log should be emitted when the fallback fires, so users know thinking is being activated by default.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING