---
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,
)
```


---

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

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