Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Heuristic:Anthropics Anthropic sdk python Warning Deprecated LegacyAPIResponse

From Leeroopedia
Knowledge Sources
Domains SDK_Infrastructure, Deprecation
Last Updated 2026-02-15 14:00 GMT

Overview

Deprecation warning: LegacyAPIResponse and its associated stream_to_file() / astream_to_file() methods in HttpxBinaryResponseContent are deprecated and scheduled for removal in a future major version.

Description

The _legacy_response.py module contains deprecated code:

  • LegacyAPIResponse is the older response wrapper class, replaced by APIResponse / AsyncAPIResponse from _response.py. While still functional, all new code should use the modern response classes.
  • HttpxBinaryResponseContent.stream_to_file() is marked with @deprecated because it does not actually stream the response content. Use .with_streaming_response.method() instead.
  • HttpxBinaryResponseContent.astream_to_file() is the async equivalent, also marked @deprecated for the same reason.

Usage

Apply this heuristic when working with raw response handling in the Anthropic SDK. If you encounter code using LegacyAPIResponse or stream_to_file() / astream_to_file(), migrate to the modern alternatives.

The Insight (Rule of Thumb)

  • Action: Replace LegacyAPIResponse usage with APIResponse / AsyncAPIResponse.
  • Action: Replace stream_to_file() with .with_streaming_response.method() pattern.
  • Value: Ensures compatibility with future SDK versions.
  • Trade-off: None; modern classes are drop-in improvements.

Reasoning

The @deprecated decorators in the source code explicitly warn that stream_to_file() and astream_to_file() do not actually stream content due to a bug, and will be removed. The entire LegacyAPIResponse class is the predecessor to the modern APIResponse class and is retained only for backward compatibility.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment