Skip to content

Claude extended thinking: max_tokens must be > thinking.budget_tokens #26

@clifton

Description

@clifton

Bug Report

Current Behavior

When using Claude with thinking enabled (any level except Off), the API returns an error:

Invalid request: max_tokens must be greater than thinking.budget_tokens

Expected Behavior

rstructor should automatically ensure max_tokens is set high enough when thinking_level is enabled, or provide a way to configure max_tokens.

Reproduction

let client = AnthropicClient::from_env()?
    .model("claude-sonnet-4-5-20250929")
    .thinking_level(ThinkingLevel::Low);

// This fails with the above error
client.materialize::<MyStruct>(prompt).await?;

Workaround

Currently using ThinkingLevel::Off as a workaround:

.thinking_level(ThinkingLevel::Off)

Suggested Fix

When thinking is enabled, automatically set max_tokens to be greater than the thinking budget, e.g.:

  • ThinkingLevel::Minimalmax_tokens = budget + 4096
  • ThinkingLevel::Lowmax_tokens = budget + 8192
  • ThinkingLevel::Highmax_tokens = budget + 16384

Or expose a .max_tokens() builder method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions