Heuristic:Anthropics Anthropic sdk python Warning Deprecated LegacyAPIResponse
| 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:
LegacyAPIResponseis the older response wrapper class, replaced byAPIResponse/AsyncAPIResponsefrom_response.py. While still functional, all new code should use the modern response classes.HttpxBinaryResponseContent.stream_to_file()is marked with@deprecatedbecause it does not actually stream the response content. Use.with_streaming_response.method()instead.HttpxBinaryResponseContent.astream_to_file()is the async equivalent, also marked@deprecatedfor 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
LegacyAPIResponseusage withAPIResponse/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.