Skip to content

[Bug]: Anthropic integration doesn't accumulate streaming outputs with context manager get_final_output #5782

@DanielPolatajko

Description

@DanielPolatajko

Describe the bug

When using Weave with the Anthropic integration, I would expect the outputs of async streaming API calls to be accumulated and passed to Weave when the stream is consumed. I found that when using the stream as a context manager and calling get_final_output, the call finishes but the outputs are not available on the trace. I've included a repro and a screenshot of the trace.

I'm using Weave 0.52.17, Python 3.12.11, Windows 11

Repro:

import weave
from anthropic import AsyncAnthropic
from dotenv import load_dotenv
import asyncio

load_dotenv()

weave.init(project_name="danielpolatajko-mars/test")

async def test_anthropic_streaming():
    client = AsyncAnthropic()
    async with client.messages.stream(
        model="claude-sonnet-4-0",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Say hello and tell me a short joke!"}]
    ) as stream:
        response = await stream.get_final_message()
    print(response.content[0].text)
    return response

asyncio.run(test_anthropic_streaming())

Weave Project Link

https://wandb.ai/danielpolatajko-mars/test/weave/traces?view=traces_default&peekPath=%2Fdanielpolatajko-mars%2Ftest%2Fcalls%2F019aabcc-19fa-77f0-9caf-2c0ce50b0e09%3FhideTraceTree%3D0

Screenshots

Screenshot of the trace:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions