{ streaming: true } (TypeScript) or streaming=True (Python) to tell the wrapper not to auto-close the span when the function returns. Then call ctx.complete(output) once the full output is assembled.
- TypeScript — Vercel AI SDK
- TypeScript — manual stream bridge
- Python
The cleanest pattern with the Vercel AI SDK is to call
ctx.complete() inside onFinish and return the data stream response:- Pass
{ streaming: true }/streaming=Trueso the wrapper knows not to auto-close when the function returns. - Call
ctx.complete(output)with the assembled output once the stream ends. - Wait for the wrapped invocation to finish before relying on
runIdor assuming the span is closed. - Replace the queue or
ReadableStreamexample with whatever your framework uses to write SSE events.

