Home / Class/ StreamAlreadyConsumed Class — anthropic-sdk-python Architecture

StreamAlreadyConsumed Class — anthropic-sdk-python Architecture

Architecture documentation for the StreamAlreadyConsumed class in _response.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  4f52ffb4_64ae_2d69_4dea_c95441688201["StreamAlreadyConsumed"]
  145ee5ba_422d_688e_ca30_dbf4a26bf47f["AnthropicError"]
  4f52ffb4_64ae_2d69_4dea_c95441688201 -->|extends| 145ee5ba_422d_688e_ca30_dbf4a26bf47f
  2e9c15bb_de03_aa91_93be_0e05db0a552e["_response.py"]
  4f52ffb4_64ae_2d69_4dea_c95441688201 -->|defined in| 2e9c15bb_de03_aa91_93be_0e05db0a552e
  e3320dc2_62d3_bc8e_ae86_ed2c72167e98["__init__()"]
  4f52ffb4_64ae_2d69_4dea_c95441688201 -->|method| e3320dc2_62d3_bc8e_ae86_ed2c72167e98

Relationship Graph

Source Code

src/anthropic/_response.py lines 605–636

class StreamAlreadyConsumed(AnthropicError):
    """
    Attempted to read or stream content, but the content has already
    been streamed.

    This can happen if you use a method like `.iter_lines()` and then attempt
    to read th entire response body afterwards, e.g.

    ```py
    response = await client.post(...)
    async for line in response.iter_lines():
        ...  # do something with `line`

    content = await response.read()
    # ^ error
    ```

    If you want this behaviour you'll need to either manually accumulate the response
    content or call `await response.read()` before iterating over the stream.
    """

    def __init__(self) -> None:
        message = (
            "Attempted to read or stream some content, but the content has "
            "already been streamed. "
            "This could be due to attempting to stream the response "
            "content more than once."
            "\n\n"
            "You can fix this by manually accumulating the response content while streaming "
            "or by calling `.read()` before starting to stream."
        )
        super().__init__(message)

Extends

Frequently Asked Questions

What is the StreamAlreadyConsumed class?
StreamAlreadyConsumed is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_response.py.
Where is StreamAlreadyConsumed defined?
StreamAlreadyConsumed is defined in src/anthropic/_response.py at line 605.
What does StreamAlreadyConsumed extend?
StreamAlreadyConsumed extends AnthropicError.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free