> 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/17.latest/add-ons/agent/api/stream.md).

# Stream

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/17.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/17.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/17.latest/add-ons/agent/api/run.md) - Non-streaming JSON response
* [Stream Agent (AG-UI)](/ai-in-umbraco/17.latest/add-ons/agent/api/stream-agui.md) - Stream AG-UI protocol events
* [Streaming](/ai-in-umbraco/17.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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
