org.llm4s.llmconnect.streaming

Members list

Type members

Classlikes

@Stable
object SSEParser

Server-Sent Events (SSE) parser for streaming LLM responses.

Server-Sent Events (SSE) parser for streaming LLM responses.

Handles the SSE format used by both OpenAI and Anthropic streaming endpoints. SSE format consists of fields like:

  • data:
  • event:
  • id:
  • retry:
  • :

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
SSEParser.type
@Stable
final class StreamingAccumulator

Accumulates streaming chunks into a complete response. Handles content accumulation, tool call accumulation, thinking content, and token tracking.

Accumulates streaming chunks into a complete response. Handles content accumulation, tool call accumulation, thinking content, and token tracking.

Mutable and not thread-safe: use one accumulator per stream, fed from the thread that reads it. Tool calls are keyed by id, so every chunk of a streamed tool call - continuations included - must carry its call's id; a tool-call chunk with an empty id is ignored. Clients whose wire format identifies continuations only by index must map them back to the id first.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Factory for creating accumulators

Factory for creating accumulators

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type

Shared boundary parser for streaming tool-call arguments.

Shared boundary parser for streaming tool-call arguments.

  • Empty input yields an empty object sentinel for accumulators.
  • Valid JSON is parsed as-is.
  • Invalid/partial JSON is preserved as a raw string for later assembly.
  • JSON nested more than 512 levels deep is preserved as a raw string too: the arguments are model output, and a value that deep overflows the stack of whatever renders it next (#1562).

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type