Skip to content

AI SDK calls fail with ReadableStream has already been used when OTEL enabled #701

@parteeksingh24

Description

@parteeksingh24

AI SDK calls in SSE handlers fail with ReadableStream error when OTEL is enabled, despite the #471 fix.

Issue

Error: ReadableStream has already been used
Error: Connection lost

Observed in Model Arena demo within the SDK explorer where Anthropic provider shows the error and connection drops.

Workaround:

OTEL_SDK_DISABLED=true bun run dev

Potential Cause

The #471 fix wraps SSE handlers in ROOT_CONTEXT to bypass OTEL-instrumented fetch. This works for simpler cases but still fails when:

  • Using generateObject (not just generateText)
  • Running multiple AI SDK calls in parallel within an SSE handler

Potential Fixes

  1. Check if generateObject triggers different OTEL instrumentation paths than generateText
  2. Investigate whether parallel AI SDK calls inside SSE handlers need additional handling
  3. Verify ROOT_CONTEXT propagates correctly through Promise.all() with multiple provider calls

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions