AttributeError: ‘ThinkingConfigEnabled’ object has no attribute ‘budget_tokens’ (2026)

When you use Anthropic’s extended thinking mode in the Claude SDK and try to access config.budget_tokens, Python raises AttributeError: 'ThinkingConfigEnabled' object has no attribute 'budget_tokens'. The fix is simple once you know the reason: the SDK expects a dict literal, not a constructor call. Here is the exact fix, why it happens, and how to avoid it in production.

AttributeError 'ThinkingConfigEnabled' object has no attribute 'budget_tokens' (2026)

Why the AttributeError happens

Anthropic’s SDK ships ThinkingConfigEnabled as a TypedDict, not a full Python class with attribute access. When you write ThinkingConfigEnabled(type="enabled", budget_tokens=16000), Python creates the object but the resulting instance does not expose .budget_tokens as an attribute. It only exposes dictionary keys.

The recommended pattern in 2026 is to pass a dict literal directly. This works because the SDK does its own key validation and never needs attribute access on the config object.

The fix: use a dict literal

import anthropic

client = anthropic.Anthropic()

# WRONG (raises AttributeError when SDK accesses .budget_tokens internally)
# from anthropic.types import ThinkingConfigEnabled
# thinking = ThinkingConfigEnabled(type="enabled", budget_tokens=16000)

# CORRECT (2026 recommended pattern)
message = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=32000,
    thinking={
        "type": "enabled",
        "budget_tokens": 16000
    },
    messages=[{"role": "user", "content": "Solve this problem step by step"}]
)

for block in message.content:
    if block.type == "thinking":
        print("Reasoning:", block.thinking)
    elif block.type == "text":
        print("Answer:", block.text)

Debugging checklist

  • Confirm your Anthropic SDK version: python -c "import anthropic; print(anthropic.__version__)". Extended thinking requires SDK 0.42+ from 2026.
  • Confirm the model supports thinking. Only Opus 4.8+, Sonnet 5, and later models support extended thinking. Haiku 4.5 does not.
  • Confirm budget_tokens is at least 1024 and less than max_tokens. The SDK returns a validation error if these constraints are violated.
  • If you built a wrapper around the SDK, check that your wrapper is passing the thinking parameter as a plain dict, not a constructor call.

Real-world example: extended thinking in a math tutor

Here is a working production pattern for an AI math tutor that uses extended thinking to solve multi-step problems.

import anthropic

def solve_with_reasoning(problem: str, thinking_budget: int = 16000):
    """Solve a math problem with visible chain-of-thought reasoning."""
    client = anthropic.Anthropic()

    resp = client.messages.create(
        model="claude-opus-4-8",
        max_tokens=32000,
        thinking={"type": "enabled", "budget_tokens": thinking_budget},
        messages=[{
            "role": "user",
            "content": f"Solve step by step: {problem}"
        }]
    )

    reasoning = ""
    answer = ""
    for block in resp.content:
        if block.type == "thinking":
            reasoning += block.thinking
        elif block.type == "text":
            answer += block.text

    return {"reasoning": reasoning, "answer": answer}

result = solve_with_reasoning("If a train leaves NYC at 60mph and another leaves Chicago at 70mph...")
print("Chain of thought:\n", result["reasoning"][:500])
print("\nFinal answer:\n", result["answer"])

Common mistakes with extended thinking

  • Setting budget_tokens higher than max_tokens. The SDK rejects this immediately with a validation error, not an AttributeError.
  • Using a model that does not support thinking. Sending the thinking parameter to Haiku or older Sonnet models returns a 400 error.
  • Trying to stream thinking blocks the same way as text blocks. Thinking blocks arrive in a separate event type when streaming.
  • Assuming thinking output is user-facing. Anthropic explicitly recommends showing thinking to developers for debugging only, not to end users by default.

Frequently Asked Questions

Why does the SDK reject constructor-style ThinkingConfigEnabled?

The SDK’s TypedDict definition does not expose fields as class attributes. Constructor calls succeed but downstream code that reads .budget_tokens raises AttributeError. Passing a dict literal skips that failure path.

What is the minimum budget_tokens value?

1,024. Below that the SDK returns a validation error. Typical values in production are 8,000-32,000 depending on task complexity.

Does extended thinking increase token costs?

Yes. Thinking tokens are billed at the same rate as output tokens. Budget accordingly. A budget of 16,000 thinking tokens can add $0.20-$0.40 per Claude Opus request depending on the tier.

Which models support extended thinking in 2026?

Claude Opus 4.7 and 4.8, Claude Sonnet 5, and later. Haiku 4.5 does not currently support thinking. Check the Anthropic model matrix for the latest support list.

Should I show thinking to end users?

Anthropic recommends against showing thinking blocks to end users by default. Thinking output is meant for developer debugging and safety review. Only expose thinking when your product design specifically calls for chain-of-thought visibility.

Leave a Comment