---
title: "Stream free-text answers and replace with the final result"
description: "Stream a free-text answer from Duale AI in real time, then replace the displayed text with the validated final result from await response.model()."
lang: en
status: public-preview
lastUpdated: 2026-10-21
url: https://duale.ai/en/docs/sdk/streaming
---

## AI-generated summary

This page covers prerequisites, ordered chunk display, and replacing streamed text with the final result when streaming a free-text answer.

- Streaming prerequisites and supported answer formats.
- Ordered chunk display using generation and sequence.
- Replacing streamed text with the final result from model().

Summaries were generated by AI.

---

Stream a free-text answer to show it while Duale AI writes it, then replace the streamed text with the final result
from `await response.model()`.

## Before you stream

- Complete [Install the SDK](https://duale.ai/en/docs/sdk.md#install-the-sdk) and the first typed request.
- Only free-text answers stream. Pass no `res` or `response_format`, or pass the `text` or `markdown` format.
- The example submits a real Task and can incur Platform and model-provider usage. Use non-sensitive input.

## Show the chunks in order

Chunks can arrive out of order. Each `BridgeContentDeltaResponse` carries a `generation` and a `sequence`, and a
`BridgeContentResetResponse` starts a new `generation`. A new generation starts when Duale AI restarts the answer, for
example after it retries a provider request.

1. Keep only events from the highest `generation`. A higher generation replaces everything shown from earlier ones.
2. Show that generation's deltas sorted by `sequence`.

```python runnable
import asyncio

from dualeai import BridgeContentDeltaResponse, ask, create_sdk

async def main() -> None:
    async with create_sdk() as sdk:
        response = await ask("Write a short poem", streaming=True, sdk=sdk)
        print(response.task_id)

        generation, parts = 0, {}
        async for event in response.stream():
            if event.generation < generation:
                continue
            if event.generation > generation:
                generation, parts = event.generation, {}
            if isinstance(event, BridgeContentDeltaResponse):
                parts[event.sequence] = event.delta
            # Display "".join(parts[sequence] for sequence in sorted(parts)).

        print(await response.model())

asyncio.run(main())
```

Save the example as `stream_answer.py`, then run it:

```bash
python stream_answer.py
```

The script prints the Task identifier, consumes the stream, then prints the final answer. Your display shows the
ordered text of the highest generation while the stream runs.

## Replace the stream with the final result

Streamed text is a live view of the answer, for display only. When the stream ends, replace it with
`await response.model()`, the validated final result. For an answer with no format or the `text` format, the final
result is the only copy that can carry the [content mark](https://duale.ai/en/docs/content-marking.md). Do not store, index, or forward
the streamed text.

**Check.** After the stream ends, the text your application keeps is the value that `model()` returned, not the
assembled chunks.

[Streaming events](https://duale.ai/en/docs/sdk/reference.md#streaming-events) lists the event types and their fields.

## Related content

- [AI that takes on real work, with and for your people](https://duale.ai/index.md)
- [Troubleshoot missing answers and handle extraction failures](https://duale.ai/en/docs/libraries/patterns.md)
- [Sales: bids and briefs sourced before the deadline](https://duale.ai/en/use-cases/sales.md)
- [AI agents for R&D, every claim sourced before your review](https://duale.ai/en/use-cases/research-and-development.md)
- [Shared responsibility: platform and customer duties](https://duale.ai/en/docs/security/shared-responsibility.md)
- [AI due diligence from press and data room to one memo](https://duale.ai/en/use-cases/finance/due-diligence.md)

---

## Sitemap

See the full [Markdown sitemap](https://duale.ai/sitemap.md) for all pages.
