enterprise_ai.llm.streaming
Source: sdks/python/src/enterprise_ai/llm/streaming/__init__.py. Back to the Python SDK reference index.
This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.
Model ServerSentEvent
One SSE event. data is the raw text; :meth:json decodes it.
Fields:
| Name | Type | Required | Description |
|---|---|---|---|
event | str | no | Event type from the event: field (default message). |
data | str | no | Raw text of the data lines of the event, joined by newlines; json() decodes it. |
id | str | None | no | Last event identifier from the id: field, or None; used as Last-Event-ID to resume. |
retry | int | None | no | Reconnection delay in milliseconds from the retry: field, or None. |
Attributes:
| Name | Type | Required | Description |
|---|---|---|---|
is_done | bool | yes | True when data is the [DONE] terminator. |
ServerSentEvent.json
json() -> Any
Decode data as JSON (None for empty data).
This element takes no parameter.
Returns: Any. Decoded JSON value, or None for empty data.
Class SSEDecoder
Incremental decoder: feed lines, collect complete events.
Constructor SSEDecoder
SSEDecoder() -> None
Create a decoder with no pending event.
This element takes no parameter.
SSEDecoder.feed
feed(line: str) -> ServerSentEvent | None
Process one line (without its newline). Returns an event when a blank line ends one.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
line | str | yes | One line of the event stream; comment lines starting with : are ignored. |
Returns: ServerSentEvent \| None. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.
SSEDecoder.flush
flush() -> ServerSentEvent | None
Emit a trailing event not followed by a blank line.
This element takes no parameter.
Returns: ServerSentEvent \| None. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.
Model ChatAccumulator
Rebuild the assistant message (content, reasoning, tool calls, usage) from chunks.
Fields:
| Name | Type | Required | Description |
|---|---|---|---|
content | str | no | Text content merged so far. |
reasoning | str | no | Reasoning text merged from the reasoning_content deltas. |
finish_reason | str | None | no | Last finish_reason seen in the chunks, such as stop or tool_calls; None until the end. |
usage | dict[str, Any] | no | Usage counters added to the budget consumption, for example input_tokens, output_tokens. |
tool_calls | dict[int, dict[str, Any]] | no | Tool calls being rebuilt, by index: id, type and function with the concatenated name and arguments. |
model | str | None | no | Model named by the last chunk that carried one, or None. |
ChatAccumulator.add
add(chunk: dict[str, Any]) -> str
Merge one chunk and return the text delta it carried.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
chunk | dict[str, Any] | yes | Decoded chat.completion.chunk dict. |
Returns: str. Text content carried by the chunk deltas, empty when the chunk had none.
ChatAccumulator.completion
completion() -> dict[str, Any]
A non streamed chat.completion equivalent.
This element takes no parameter.
Returns: dict[str, Any]. Dict with object chat.completion, model, one choice holding message() and finish_reason, and usage.
ChatAccumulator.message
message() -> dict[str, Any]
The final assistant message in OpenAI format.
This element takes no parameter.
Returns: dict[str, Any]. Dict {role: assistant, content} with tool_calls ordered by index when the model called tools.
Functions
iter_sse
iter_sse(lines: Iterable[str]) -> Iterator[ServerSentEvent]
Parse an iterable of text lines into events.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
lines | Iterable[str] | yes | Iterable of text lines or chunks; a chunk holding several lines is split. |
Returns: Iterator[ServerSentEvent]. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.
aiter_sse
async aiter_sse(lines: AsyncIterator[str]) -> AsyncIterator[ServerSentEvent]
Async variant of :func:iter_sse.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
lines | AsyncIterator[str] | yes | Async iterator of text lines or chunks; a chunk holding several lines is split. |
Returns: AsyncIterator[ServerSentEvent]. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.
chat_chunks
chat_chunks(events: Iterable[ServerSentEvent]) -> Iterator[dict[str, Any]]
Decode OpenAI compatible chat.completion.chunk payloads until [DONE].
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
events | Iterable[ServerSentEvent] | yes | Iterable of ServerSentEvent from a chat completion stream. |
Returns: Iterator[dict[str, Any]]. Iterator of the decoded chunk dicts; stops at [DONE] and skips empty events.
achat_chunks
async achat_chunks(events: AsyncIterator[ServerSentEvent]) -> AsyncIterator[dict[str, Any]]
Async variant of :func:chat_chunks.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
events | AsyncIterator[ServerSentEvent] | yes | Async iterator of ServerSentEvent from a chat completion stream. |
Returns: AsyncIterator[dict[str, Any]]. Async iterator of the decoded chunk dicts; stops at [DONE] and skips empty events.