Overview

djangosdk supports streaming via Server-Sent Events (SSE). Both synchronous (WSGI) and asynchronous (ASGI) streaming are supported.

StreamChunk

Each chunk emitted during streaming is a StreamChunk:

@dataclass
class StreamChunk:
    type: str    # "text_delta" | "thinking_delta" | "tool_call" | "done"
    text: str = ""
    thinking: bool = False
    tool_call: dict | None = None
    usage: UsageInfo | None = None
  • text_delta — A piece of the final response text

  • thinking_delta — A piece of the reasoning trace (requires stream_thinking=True)

  • tool_call — A tool call event

  • done — The final chunk, contains usage info

Sync Streaming (WSGI)

Use agent.stream() in a standard Django view:

This returns a StreamingHttpResponse with Content-Type: text/event-stream.

Async Streaming (ASGI)

Use agent.astream() in an async view:

SSE Format

Each SSE message follows the standard format:

JavaScript Client Example

Configuration

Last updated

Was this helpful?