Interface RawStreamingEvent

All Superinterfaces:
ChatModelStreamingEvent

@Experimental public interface RawStreamingEvent extends ChatModelStreamingEvent
A provider-specific streaming event that langchain4j's generic event model does not (yet) map to a dedicated ChatModelStreamingEvent type — for example a web-search, citation or reasoning-summary event. This is an escape hatch: rather than silently dropping such events, a provider surfaces them as RawStreamingEvent so callers can consume them — typically by inspecting rawEvent() themselves — even though the library has no typed representation for them.

Consumers must be prepared to receive event types they do not recognize and ignore them (see StreamingChatModel.chat(dev.langchain4j.model.chat.request.ChatRequest)).

This is the reactive (ChatModelStreamingEvent publisher) counterpart of the handler-based StreamingChatResponseHandler.onUnmappedRawEvent(Object) callback: it carries the same raw provider event.

Forward compatibility. This is an interface on purpose. If such an event later graduates to a dedicated typed event, that typed event can also implement RawStreamingEvent (exposing the same rawEvent()). A single emitted object then satisfies both audiences: code that matched instanceof RawStreamingEvent and inspected rawEvent() keeps working, while new code can match the typed event and use its typed accessors.

Since:
1.20.0
  • Method Details

    • rawEvent

      Object rawEvent()
      The raw provider streaming event that LangChain4j does not map to a typed ChatModelStreamingEvent.

      Its type depends on the provider implementation: implementations built on the dev.langchain4j.http.client.HttpClient abstraction (e.g., OpenAI) typically expose a ServerSentEvent; SDK-based implementations may expose the SDK's own event object. The object's shape is the provider's wire format and carries no stability guarantee.

    • of

      static RawStreamingEvent of(Object rawEvent)
      Creates a RawStreamingEvent wrapping the given raw provider event.
      Parameters:
      rawEvent - the raw provider streaming event; see rawEvent()
      Returns:
      a RawStreamingEvent carrying rawEvent