Skip to content

Intermittent AttributeError in beta.messages.stream() with effort parameter: 'dict' object has no attribute 'to_dict' #1088

@SergioHC95

Description

@SergioHC95

Summary

Using client.beta.messages.stream() with Claude Opus 4.5 and the effort-2025-11-24 beta intermittently raises AttributeError: 'dict' object has no attribute 'to_dict' when calling stream.get_final_message().

Environment

  • SDK: anthropic>=0.75.0
  • Python: 3.11+
  • Model: claude-opus-4-5-20251101
  • Betas: code-execution-2025-08-25, effort-2025-11-24

Minimal Reproduction

with client.beta.messages.stream(
    model="claude-opus-4-5-20251101",
    max_tokens=64000,
    messages=[{"role": "user", "content": [{"type": "text", "text": "..."}]}],
    betas=["code-execution-2025-08-25", "effort-2025-11-24"],
    output_config={"effort": "medium"},
) as stream:
    for event in stream:
        pass
    resp = stream.get_final_message()  # Intermittent error here

Observed Behavior

  • Intermittent: Same request fails on attempts 1-3, then succeeds on retry
  • Non-deterministic: Identical code works in one run, fails in another
  • Beta-specific: Only affects Opus 4.5 via client.beta.messages; non-beta streaming works reliably

Error

AttributeError: 'dict' object has no attribute 'to_dict'

Hypothesis

The beta streaming accumulator occasionally returns a raw dict instead of a Pydantic model, causing internal .to_dict() calls to fail. Possibly a race condition in response accumulation.

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