ResponseEventStream Class

Definition

Top-level scope for building a streaming response event sequence. Manages the global sequence counter and output index counter, and provides factory methods for creating child scopes (message builders, function call builders). Owns a private Response object that is embedded in emitted events.

public class ResponseEventStream
type ResponseEventStream = class
Public Class ResponseEventStream
Inheritance
ResponseEventStream

Constructors

Name Description
ResponseEventStream()

Initializes a new instance of ResponseEventStream for mocking.

ResponseEventStream(ResponseContext, CreateResponse)

Creates a new event stream that builds its own Response from the request.

Properties

Name Description
Response

Gets the ResponseObject object being constructed. Allows the handler to set any ResponseObject property (e.g. Metadata, Instructions, Temperature) before calling EmitCreated(ResponseStatus).

Methods

Name Description
AddOutputItem<T>(String)

Creates an output item scope with the next output index. Use for output item types that have no dedicated Add*() factory and no streaming sub-events (no deltas, no status transitions). Call EmitAdded(T) and EmitDone(T) on the returned builder, passing the item to each call.

AddOutputItemApplyPatchCall()

Creates an apply-patch call output item scope with the next output index and an auto-generated item ID.

AddOutputItemApplyPatchCallOutput()

Creates an apply-patch call output result scope with the next output index and an auto-generated item ID.

AddOutputItemCodeInterpreterCall()

Creates a code interpreter call output item scope with the next output index and an auto-generated item ID.

AddOutputItemCompaction()

Creates a compaction output item scope with the next output index and an auto-generated item ID.

AddOutputItemComputerCall()

Creates a computer tool call output item scope with the next output index and an auto-generated item ID.

AddOutputItemComputerCallOutput()

Creates a computer tool call output result scope with the next output index and an auto-generated item ID.

AddOutputItemCustomToolCall(String, String)

Creates a custom tool call output item scope with the next output index and an auto-generated item ID.

AddOutputItemCustomToolCallOutput()

Creates a custom tool call output result scope with the next output index and an auto-generated item ID.

AddOutputItemFileSearchCall()

Creates a file search call output item scope with the next output index and an auto-generated item ID.

AddOutputItemFunctionCall(String, String)

Creates a function call output item scope with the next output index and an auto-generated item ID.

AddOutputItemFunctionShellCall()

Creates a function shell call output item scope with the next output index and an auto-generated item ID.

AddOutputItemFunctionShellCallOutput()

Creates a function shell call output result scope with the next output index and an auto-generated item ID.

AddOutputItemImageGenCall()

Creates an image generation call output item scope with the next output index and an auto-generated item ID.

AddOutputItemLocalShellCall()

Creates a local shell call output item scope with the next output index and an auto-generated item ID.

AddOutputItemLocalShellCallOutput()

Creates a local shell call output result scope with the next output index and an auto-generated item ID.

AddOutputItemMcpApprovalRequest()

Creates an MCP approval request output item scope with the next output index and an auto-generated item ID.

AddOutputItemMcpApprovalResponse()

Creates an MCP approval response output item scope with the next output index and an auto-generated item ID.

AddOutputItemMcpCall(String, String)

Creates an MCP tool call output item scope with the next output index and an auto-generated item ID.

AddOutputItemMcpListTools(String)

Creates an MCP list-tools output item scope with the next output index and an auto-generated item ID.

AddOutputItemMessage()

Creates a message output item scope with the next output index and an auto-generated item ID.

AddOutputItemReasoningItem()

Creates a reasoning output item scope with the next output index and an auto-generated item ID.

AddOutputItemStructuredOutputs()

Creates a structured outputs item scope with the next output index and an auto-generated item ID.

AddOutputItemWebSearchCall()

Creates a web search call output item scope with the next output index and an auto-generated item ID.

EmitCompleted(ResponseUsage)

Produces a response.completed event. Sets Status = Completed, CompletedAt, and Usage before creating the event.

EmitCreated(ResponseStatus)

Produces a response.created event. Sets Status to the specified value before creating the event. Use Queued when the response will go through a queued phase before processing; use InProgress (the default) to start processing immediately.

EmitFailed(ResponseErrorCode, String, ResponseUsage)

Produces a response.failed event. Sets Status = Failed, CompletedAt, Error, and Usage (if provided) before creating the event.

EmitFailed(String, ResponseUsage)

Produces a response.failed event with a ServerError code.

EmitIncomplete(Nullable<ResponseIncompleteDetailsReason>, ResponseUsage)

Produces a response.incomplete event. Sets Status = Incomplete, CompletedAt, IncompleteDetails, and Usage (if provided) before creating the event.

EmitInProgress()

Produces a response.in_progress event. Sets Status = InProgress before creating the event.

EmitQueued()

Produces a response.queued event. Sets Status = Queued before creating the event.

NextSequenceNumber()

Returns the next sequence number for use with manually constructed events. Uses post-increment semantics: returns the current value and then increments.

OutputItemApplyPatchCall(String, ApplyPatchCallStatus, ApplyPatchFileOperation)

Convenience generator that yields the complete apply-patch tool call lifecycle. Apply-patch calls have no intermediate events — only output_item.added and output_item.done.

OutputItemApplyPatchCallOutput(String, ApplyPatchCallOutputStatus)

Convenience generator that yields the complete apply-patch tool call output lifecycle. Apply-patch call outputs have no intermediate events — only output_item.added and output_item.done.

OutputItemCompaction(String)

Convenience generator that yields the complete compaction output-item lifecycle. Compaction items have no intermediate events — only output_item.added and output_item.done.

OutputItemComputerCall(String, ComputerAction, IEnumerable<ComputerCallSafetyCheckParam>, ItemComputerToolCallStatus)

Convenience generator that yields the complete computer tool call output-item lifecycle. Computer call outputs have no intermediate events — only output_item.added and output_item.done.

OutputItemComputerCallOutput(String, ComputerScreenshotImage)

Convenience generator that yields the complete computer tool call output resource lifecycle. Computer call outputs have no intermediate events — only output_item.added and output_item.done.

OutputItemCustomToolCallOutput(String, BinaryData)

Convenience generator that yields the complete custom tool call output lifecycle. Custom tool call outputs have no intermediate events — only output_item.added and output_item.done.

OutputItemFunctionCall(String, String, IAsyncEnumerable<String>, CancellationToken)

Convenience generator that yields the complete function call output-item lifecycle with arguments from streaming chunks (S-056, S-058).

OutputItemFunctionCall(String, String, String)

Convenience generator that yields the complete function call output-item lifecycle with arguments from a complete string (S-056).

OutputItemFunctionCallOutput(String, BinaryData)

Convenience generator that yields the complete function call output item lifecycle (S-056). Function call outputs have no deltas — only output_item.added and output_item.done.

OutputItemFunctionShellCall(String, FunctionShellAction, LocalShellCallStatus, FunctionShellCallEnvironment)

Convenience generator that yields the complete function shell call lifecycle. Function shell calls have no intermediate events — only output_item.added and output_item.done.

OutputItemFunctionShellCallOutput(String, LocalShellCallOutputStatusEnum, IEnumerable<FunctionShellCallOutputContent>, Nullable<Int64>)

Convenience generator that yields the complete function shell call output lifecycle. Function shell call outputs have no intermediate events — only output_item.added and output_item.done.

OutputItemImageGenCall(String)

Convenience generator that yields the complete image generation call output-item lifecycle from a final base64-encoded image result.

OutputItemLocalShellCall(String, LocalShellExecAction, ItemLocalShellToolCallStatus)

Convenience generator that yields the complete local shell tool call lifecycle. Local shell calls have no intermediate events — only output_item.added and output_item.done.

OutputItemLocalShellCallOutput(String)

Convenience generator that yields the complete local shell tool call output lifecycle. Local shell call outputs have no intermediate events — only output_item.added and output_item.done.

OutputItemMcpApprovalRequest(String, String, String)

Convenience generator that yields the complete MCP approval request lifecycle. MCP approval requests have no intermediate events — only output_item.added and output_item.done.

OutputItemMcpApprovalResponse(String, Boolean)

Convenience generator that yields the complete MCP approval response lifecycle. MCP approval responses have no intermediate events — only output_item.added and output_item.done.

OutputItemMessage(IAsyncEnumerable<String>, CancellationToken)

Convenience generator that yields the complete message output-item lifecycle with a single text content part from streaming chunks (S-056, S-058).

OutputItemMessage(String, IEnumerable<Annotation>)

Convenience generator that yields the complete message output-item lifecycle with a single text content part and annotations (S-056).

OutputItemMessage(String)

Convenience generator that yields the complete message output-item lifecycle with a single text content part from a complete string (S-056).

OutputItemReasoningItem(IAsyncEnumerable<String>, CancellationToken)

Convenience generator that yields the complete reasoning output-item lifecycle with a single summary part from streaming chunks (S-056, S-058).

OutputItemReasoningItem(String)

Convenience generator that yields the complete reasoning output-item lifecycle with a single summary part from a complete string (S-056).

OutputItemStructuredOutputs(BinaryData)

Convenience generator that yields the complete structured outputs item lifecycle. Use this to return any open-ended structured information as a JSON object. This is useful when none of the existing output item types (message, function call, image, etc.) fit your use case — for example, returning analytics results, classification labels, form data, or any custom JSON payload.

Applies to