Automatic AI instrumentation eagerly observes custom API promises, which can consume the response body before application code reads it. The request succeeds, but reading the raw response fails:
const response = await client.messages.create(body).asResponse();
await response.json(); // TypeError: Body is unusable: Body has already been read
Confirmed affected automatic instrumentation paths:
- Anthropic:
messages.create(...).asResponse()
- Groq and Together:
chat.completions.create(...).asResponse()
- OpenAI:
embeddings.create(...).asResponse() and conversations.create(...).asResponse()
Ordinary await create(...) works. Anthropic messages.parse() and beta.messages.parse() also worked in the tested version; this is not a general failure of structured output helpers.
Anthropic's APIPromise extends the native Promise. Its .then() triggers parsing, whereas .asResponse() accesses the underlying HTTP response without parsing. Sentry's automatic instrumentation uses Auto for Anthropic, Groq/Together, and the remaining OpenAI methods, which starts parsing through promise observation.
Follow up on #24783, which fixes automatic OpenAI chat/responses parsing. Preserve lazy body consumption across the affected integrations while retaining span completion and streaming behavior. Add regression tests that actually read .asResponse() bodies and verify spans, alongside normal and structured output calls.
Reproduced with OpenAI 5.18.1, Anthropic 0.63.0 and 0.129.0, Groq 1.6.0, and Together 0.54.0. No equivalent failure reproduced in the tested Google GenAI, Vercel AI, LangChain, LangGraph, Mistral, or TypeSafe paths. Scope: automatic instrumentation; manual wrapper issues are separate.
Automatic AI instrumentation eagerly observes custom API promises, which can consume the response body before application code reads it. The request succeeds, but reading the raw response fails:
Confirmed affected automatic instrumentation paths:
messages.create(...).asResponse()chat.completions.create(...).asResponse()embeddings.create(...).asResponse()andconversations.create(...).asResponse()Ordinary
await create(...)works. Anthropicmessages.parse()andbeta.messages.parse()also worked in the tested version; this is not a general failure of structured output helpers.Anthropic's APIPromise extends the native Promise. Its
.then()triggers parsing, whereas.asResponse()accesses the underlying HTTP response without parsing. Sentry's automatic instrumentation usesAutofor Anthropic, Groq/Together, and the remaining OpenAI methods, which starts parsing through promise observation.Follow up on #24783, which fixes automatic OpenAI chat/responses parsing. Preserve lazy body consumption across the affected integrations while retaining span completion and streaming behavior. Add regression tests that actually read
.asResponse()bodies and verify spans, alongside normal and structured output calls.Reproduced with OpenAI 5.18.1, Anthropic 0.63.0 and 0.129.0, Groq 1.6.0, and Together 0.54.0. No equivalent failure reproduced in the tested Google GenAI, Vercel AI, LangChain, LangGraph, Mistral, or TypeSafe paths. Scope: automatic instrumentation; manual wrapper issues are separate.