ReqLLM.StreamEvent (ReqLLM v1.19.0)

View Source

A tagged, provider-neutral projection of one streaming event.

Events are computed from the existing ReqLLM.StreamChunk stream. They do not replace chunks in ReqLLM 1.x and are not stored on ReqLLM.StreamResponse.

The event stream begins with :start and ends with exactly one of :finish, :cancelled, or :error when it is consumed to completion. Output deltas retain their arrival order. Provider-specific metadata is exposed through :provider_event and event metadata without treating raw provider frames as part of the canonical contract.

Event types

  • :start carries the resolved provider and model identity.
  • :text_delta and :reasoning_delta carry string deltas.
  • :tool_call_start and :tool_call_delta carry incremental tool input; :tool_call carries the assembled call before the terminal event.
  • :tool_result carries a result already present in provider metadata. It does not execute a tool or continue a model loop.
  • :source, :file, and :output_item carry ReqLLM.Response.OutputItem projections.
  • :usage carries the final usage map and :warning carries one warning.
  • :finish, :cancelled, and :error are mutually exclusive terminal events.
  • :provider_event carries sanitized extension metadata that has no provider-neutral event type.

Summary

Functions

Builds a canonical stream event.

Returns whether an event carries model output or an output delta.

Returns the Zoi schema for canonical stream events.

Returns whether an event is the terminal event for a consumed stream.

Returns all stable stream event types.

Types

event_type()

@type event_type() ::
  :start
  | :text_delta
  | :reasoning_delta
  | :tool_call_start
  | :tool_call_delta
  | :tool_call
  | :tool_result
  | :source
  | :file
  | :output_item
  | :usage
  | :warning
  | :finish
  | :cancelled
  | :error
  | :provider_event

t()

@type t() :: %ReqLLM.StreamEvent{data: term(), metadata: map(), type: event_type()}

Functions

new(type, data \\ nil, metadata \\ %{})

@spec new(event_type(), term(), map()) :: t()

Builds a canonical stream event.

output?(stream_event)

@spec output?(t()) :: boolean()

Returns whether an event carries model output or an output delta.

schema()

Returns the Zoi schema for canonical stream events.

terminal?(stream_event)

@spec terminal?(t()) :: boolean()

Returns whether an event is the terminal event for a consumed stream.

types()

@spec types() :: [event_type()]

Returns all stable stream event types.