> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/ai-in-umbraco/19.latest/add-ons/agent/api/stream.md).

# Stream

Stream agent response updates as Server-Sent Events.

Runs an agent and streams incremental response updates as Server-Sent Events (SSE). Each event carries a serialized `AgentResponseUpdate` from Microsoft.Extensions.AI.

Use [Stream Agent (AG-UI)](/ai-in-umbraco/19.latest/add-ons/agent/api/stream-agui.md) when you need the AG-UI protocol (for example, for CopilotKit-compatible clients). Use [Run Agent](/ai-in-umbraco/19.latest/add-ons/agent/api/run.md) when you only need the final response.

## Request

```http
POST /umbraco/ai/management/api/v1/agents/{agentIdOrAlias}/stream
```

### Path Parameters

| Parameter        | Type   | Description         |
| ---------------- | ------ | ------------------- |
| `agentIdOrAlias` | string | Agent GUID or alias |

### Request Body

{% code title="Request" %}

```json
{
    "messages": [
        {
            "role": "user",
            "content": "Help me write a blog post about AI"
        }
    ]
}
```

{% endcode %}

### Request Properties

| Property                  | Type   | Required | Description                                                      |
| ------------------------- | ------ | -------- | ---------------------------------------------------------------- |
| `messages`                | array  | Yes      | Conversation messages (must contain at least one message)        |
| `messages[].role`         | string | Yes      | Message role: `user`, `assistant`, `system`, `tool`, `developer` |
| `messages[].content`      | string | No       | Plain-text message content                                       |
| `messages[].contentParts` | array  | No       | Multimodal content parts (takes precedence over `content`)       |

## Response

The endpoint returns `Content-Type: text/event-stream`. Each update is emitted as a single SSE `data:` line containing the JSON-serialized update, followed by a blank line:

```
data: {"role":"assistant","contents":[{"$type":"text","text":"Here's"}]}

data: {"role":"assistant","contents":[{"$type":"text","text":" a draft"}]}

data: {"role":"assistant","contents":[{"$type":"text","text":" blog post..."}]}
```

{% hint style="info" %}
The stream uses only `data:` lines - there is no `event:` line. The event payload follows the `AgentResponseUpdate` shape from Microsoft.Extensions.AI, serialized with camelCase property names.
{% endhint %}

### Error Handling

If the agent cannot be resolved, the endpoint returns `404 Not Found` with a problem details response (not SSE). Errors raised during streaming are emitted as a final SSE `data:` line in the form `{"error":"..."}`.

{% code title="404 Not Found" %}

```json
{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
    "title": "AIAgent not found",
    "status": 404,
    "detail": "The specified agent could not be found."
}
```

{% endcode %}

## Examples

### Consume with cURL

{% code title="cURL" %}

```bash
curl -N -X POST "https://your-site.com/umbraco/ai/management/api/v1/agents/content-assistant/stream" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{
    "messages": [
      { "role": "user", "content": "Help me write a title" }
    ]
  }'
```

{% endcode %}

## Related

* [Run Agent](/ai-in-umbraco/19.latest/add-ons/agent/api/run.md) - Non-streaming JSON response
* [Stream Agent (AG-UI)](/ai-in-umbraco/19.latest/add-ons/agent/api/stream-agui.md) - Stream AG-UI protocol events
* [Streaming](/ai-in-umbraco/19.latest/add-ons/agent/streaming.md) - Event handling details


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/ai-in-umbraco/19.latest/add-ons/agent/api/stream.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
