Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Heuristic:Openai Openai python Warning Deprecated Legacy Response

From Leeroopedia
Revision as of 10:50, 16 February 2026 by Admin (talk | contribs) (Auto-imported from heuristics/Openai_Openai_python_Warning_Deprecated_Legacy_Response.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

Related Pages

Page Connections

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