> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vrin.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# StreamingResponse

> Iterate over streaming query responses with real-time token delivery

`StreamingResponse` wraps a Server-Sent Events (SSE) stream and yields content tokens as they arrive from the backend. It is returned by `client.query(..., stream=True)`.

## Basic usage

```python theme={null}
for token in client.query("Summarize Q4 results", stream=True):
    print(token, end="", flush=True)
```

## Accessing metadata

Metadata (sources, fact counts, entities) is populated during iteration and available after the stream completes:

```python theme={null}
resp = client.query("What is ACME's revenue?", stream=True)

for token in resp:
    print(token, end="", flush=True)

# Available after iteration
print(resp.full_text)
print(resp.total_facts)
print(resp.total_chunks)
print(resp.sources)
print(resp.entities)
```

## Properties

<ResponseField name="full_text" type="str">
  The complete generated text, accumulated from all content deltas.
</ResponseField>

<ResponseField name="session_id" type="Optional[str]">
  Conversation session ID, if conversation context was maintained.
</ResponseField>

<ResponseField name="metadata" type="Dict[str, Any]">
  Full metadata dict from the backend.
</ResponseField>

<ResponseField name="sources" type="List[Dict[str, Any]]">
  Source documents referenced in the answer.
</ResponseField>

<ResponseField name="thinking_steps" type="List[str]">
  Reasoning chain steps (populated in `thinking` and `research` modes).
</ResponseField>

<ResponseField name="entities" type="List[str]">
  Entities identified in the query and used for graph traversal.
</ResponseField>

<ResponseField name="total_facts" type="int">
  Number of knowledge graph facts used to generate the answer.
</ResponseField>

<ResponseField name="total_chunks" type="int">
  Number of vector search chunks used.
</ResponseField>

<ResponseField name="model" type="Optional[str]">
  The LLM model that generated the response.
</ResponseField>

<ResponseField name="search_time" type="Optional[str]">
  Time spent on retrieval (graph + vector search).
</ResponseField>

<ResponseField name="error" type="Optional[str]">
  Error message if the stream encountered an error.
</ResponseField>

<ResponseField name="insufficient_coverage" type="bool">
  `True` if the knowledge base had no relevant facts for the query.
</ResponseField>

## to\_dict()

Convert the completed stream into a dict matching the non-streaming response format:

```python theme={null}
resp = client.query("What is ACME's revenue?", stream=True)
for token in resp:
    pass  # consume the stream

result = resp.to_dict()
# Same shape as client.query("...", stream=False)
```

## Context manager

`StreamingResponse` supports the context manager protocol for explicit cleanup:

```python theme={null}
with client.query("Summarize results", stream=True) as resp:
    for token in resp:
        print(token, end="", flush=True)
# Stream closed automatically
```

## SSE event types

The stream delivers these event types internally:

| Event       | Description                                         |
| ----------- | --------------------------------------------------- |
| `content`   | Text delta -- yielded to the iterator               |
| `metadata`  | Session ID, fact/chunk counts, entities, model info |
| `reasoning` | Thinking steps and reasoning chains                 |
| `sources`   | Source document references                          |
| `done`      | Stream complete, may include final text or error    |
| `error`     | Error occurred -- raises `StreamingError`           |

You do not need to handle these directly -- `StreamingResponse` processes them and exposes the data through properties.
