---
title: ai.ui.ai_sdk outbound stream
description: Convert agent streams to AI SDK UI stream parts.
type: reference
summary: Reference for to_sse, to_stream, and UI_MESSAGE_STREAM_HEADERS.
---

# ai.ui.ai_sdk outbound stream



Use outbound stream helpers to send an agent run to an AI SDK UI client.

```python
async for chunk in ai.ui.ai_sdk.to_sse(agent_stream):
    yield chunk
```

```python
async for part in ai.ui.ai_sdk.to_stream(agent_stream):
    yield part
```

Set `UI_MESSAGE_STREAM_HEADERS` as the HTTP response headers when serving the
stream. It is a plain `dict` with the headers the AI SDK UI client expects:

* `x-vercel-ai-ui-message-stream: v1` tells the client the response is a UI
  message stream;
* `Content-Type: text/event-stream` marks the response as
  server-sent events;
* `Cache-Control: no-cache`, `Connection: keep-alive`, `x-accel-buffering: no`
  keep proxies from buffering or caching the response so chunks reach the client
  as they are produced.

```python
return fastapi.responses.StreamingResponse(
    stream_response(),
    headers=ai.ui.ai_sdk.UI_MESSAGE_STREAM_HEADERS,
)
```

## Step boundaries

The adapter starts a UI step with the first model event. When a new
`StreamStart` follows a completed model stream, it finishes the previous step
and starts another. Tool results and approval events emitted between the two
model streams stay in the step that requested them.

The adapter finishes the active step and message when the input event stream
ends.


---

For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md)

For an index of all available documentation, see [/llms.txt](/llms.txt)

For agent-facing discovery, including API and MCP surfaces, see [/agents.md](/agents.md)