Skip to main content

Overview

The StreamParser block parses streaming responses (Server-Sent Events) from AI APIs. It extracts text content and tool calls from streaming formats used by OpenAI, Vercel AI SDK, and other providers.

Input Parameters

Required

ParameterTypeDescription
bodystringRaw SSE stream response body

Optional

ParameterTypeDefaultDescription
formatstring'text'Stream format (see supported formats below)

Configuration

ParameterTypeDefaultDescription
formatstring'text'Streaming format to parse

Supported Formats

FormatDescription
sseGeneric Server-Sent Events
sse-openaiOpenAI streaming format (ChatGPT API)
sse-vercelVercel AI SDK streaming format
textPlain text (no parsing)

Output Fields

FieldTypeDescription
textstringCombined text content from all chunks
toolCallsarrayTool/function calls made by the AI
chunksarrayIndividual stream chunks (for debugging)
metadataobjectParse metadata (format, counts, errors)

Tool Call Format

Examples

Parse OpenAI Streaming Response

Parse Vercel AI SDK Stream

Extract Tool Calls

Generic SSE Stream

Common Patterns

OpenAI Chat with Function Calling

Vercel AI SDK Stream

Multi-Turn Conversation

Stream Metadata

The metadata output includes useful information:
Use for debugging or assertions:

Chunks Array

The chunks array contains individual stream events:
Useful for debugging stream parsing issues.

Error Handling

If parsing fails, StreamParser returns empty data:
Check for errors:

Custom Parsers

You can register custom parsers programmatically:
Then use in tests:

Full Example

Tips

Map outputs to descriptive names:
Then access as ${aiMessage} and ${tools}.
  • sse-openai - For OpenAI, Azure OpenAI
  • sse-vercel - For Vercel AI SDK apps
  • sse - For generic SSE streams
Combine with ValidateTools:
Output chunks for debugging stream issues:
Then inspect ${debugChunks} to see individual events.

When to Use

Use StreamParser when:
  • Parsing streaming responses from AI APIs
  • Extracting tool calls from function-calling models
  • Testing real-time AI responses
  • Working with Server-Sent Events (SSE)
Don’t use when:
  • Response is regular JSON (use JsonParser)
  • Non-streaming HTTP response
  • Testing non-AI APIs

Next Steps

ValidateTools

Validate extracted tool calls

LLMJudge

Validate AI message quality