> 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/run.md).

# Run

Runs an agent and returns the complete response as a single JSON payload. This endpoint is non-streaming - use [Stream Agent](/ai-in-umbraco/17.latest/add-ons/agent/api/stream.md) or [Stream Agent (AG-UI)](/ai-in-umbraco/17.latest/add-ons/agent/api/stream-agui.md) when you need incremental updates.

## Request

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

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

Each content part uses a polymorphic shape with a `type` discriminator:

```json
{ "type": "text", "text": "Describe this image:" }
{ "type": "binary", "mimeType": "image/png", "data": "<base64>", "filename": "chart.png" }
```

## Response

### Success

Returns the agent's final `AgentRunResponse` as JSON.

{% code title="200 OK" %}

```json
{
    "messages": [
        {
            "role": "assistant",
            "contents": [
                { "$type": "text", "text": "Here's a draft blog post about AI..." }
            ]
        }
    ],
    "responseId": "...",
    "usage": {
        "inputTokenCount": 42,
        "outputTokenCount": 128,
        "totalTokenCount": 170
    }
}
```

{% endcode %}

### Error Responses

{% 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 %}

{% code title="400 Bad Request" %}

```json
{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "Agent execution failed",
    "status": 400,
    "detail": "Agent is not active"
}
```

{% endcode %}

## Examples

### Basic Run

{% code title="cURL" %}

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

{% endcode %}

### With Conversation History

{% code title="cURL" %}

```bash
curl -X POST "https://your-site.com/umbraco/ai/management/api/v1/agents/content-assistant/run" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      { "role": "user", "content": "Write a title about AI" },
      { "role": "assistant", "content": "Here are some options:\n1. The Rise of AI\n2. AI in Everyday Life" },
      { "role": "user", "content": "I like the second one, expand on it" }
    ]
  }'
```

{% endcode %}

## Related

* [Stream Agent](/ai-in-umbraco/17.latest/add-ons/agent/api/stream.md) - Stream agent response updates as SSE
* [Stream Agent (AG-UI)](/ai-in-umbraco/17.latest/add-ons/agent/api/stream-agui.md) - Stream AG-UI protocol events as SSE
* [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/run.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.
