Skip to content

Auto-instrumentation via node hook breaks Anthropic messages.stream() #1592

@lforst

Description

@lforst

Summary

Under node --import braintrust/hook.mjs, Anthropic client.messages.stream(...) breaks even though the equivalent messages.create({ stream: true }) flow still works.

What is broken

In auto-instrumented mode, messages.stream(...) fails because the helper path goes through an internal create(...).withResponse() flow that no longer behaves correctly once instrumented.

Why this matters

This is an API-compatibility bug in the auto-instrumented path. Valid Anthropic SDK code works normally, but breaks when Braintrust auto-instrumentation is enabled.

Repro

The aligned e2e coverage in e2e/scenarios/anthropic-auto-instrumentation-node-hook reproduces this. The failure we hit was:

  • messages.create(...).withResponse is not a function

The current e2e workaround is to avoid messages.stream(...) in auto mode and use messages.create({ stream: true }) instead.

Expected

client.messages.stream(...) should continue to work under the node-hook auto-instrumented path without requiring a scenario-specific fallback.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions