Heuristic:Openai Openai python Warning Deprecated Legacy Response
| Knowledge Sources | |
|---|---|
| Domains | SDK_Infrastructure, Deprecation |
| Last Updated | 2026-02-15 10:00 GMT |
Overview
Deprecation warning for the LegacyAPIResponse class and its stream_to_file / astream_to_file methods, which are superseded by the modern APIResponse class and .with_streaming_response pattern.
Description
The LegacyAPIResponse class in _legacy_response.py provides backward compatibility with the pre-refactor response handling. Two methods are explicitly decorated with @deprecated from typing_extensions:
- stream_to_file() — Does not actually stream content; use .with_streaming_response.method() instead.
- astream_to_file() — Async variant with the same bug and deprecation.
The entire LegacyAPIResponse class is a compatibility shim. New code should use APIResponse and AsyncAPIResponse from _response.py instead.
Usage
This warning applies when you encounter code using LegacyAPIResponse, HttpxBinaryResponseContent, or calling stream_to_file() / astream_to_file(). Migrate to the modern .with_streaming_response pattern.
The Insight (Rule of Thumb)
- Action: Replace LegacyAPIResponse usage with APIResponse / AsyncAPIResponse.
- Action: Replace stream_to_file() calls with .with_streaming_response.method() pattern.
- Trade-off: Migration requires updating response handling code but eliminates the streaming bug.
Reasoning
The stream_to_file methods have a known bug where they do not actually stream the response content — they buffer the entire response in memory first. The modern .with_streaming_response pattern correctly streams content to disk.