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

# Overview

Integrate AI capabilities into custom backoffice elements.

Umbraco.AI provides TypeScript APIs for integrating AI capabilities into custom backoffice elements. The frontend APIs work within the Umbraco backoffice context.

## Package

The AI APIs are exported from the Umbraco.AI client package:

{% code title="Import" %}

```typescript
import { UaiChatController, UaiChatMessage, UaiChatResult } from "@umbraco-ai/core";
```

{% endcode %}

## Quick Start

{% code title="Using Chat in a Custom Element" %}

```typescript
import { LitElement, html } from "lit";
import { customElement, state } from "lit/decorators.js";
import { UaiChatController, UaiChatMessage, UaiChatResult } from "@umbraco-ai/core";

@customElement("my-ai-element")
export class MyAIElement extends LitElement {
    #chatController = new UaiChatController(this);

    @state()
    private _response?: string;

    @state()
    private _loading = false;

    async #handleSubmit() {
        this._loading = true;

        const messages: UaiChatMessage[] = [{ role: "user", content: "Hello, can you help me?" }];

        const { data, error } = await this.#chatController.complete(messages);

        if (data) {
            this._response = data.message.content;
        } else {
            console.error("Chat error:", error);
        }

        this._loading = false;
    }

    render() {
        return html`
            <button @click=${this.#handleSubmit} ?disabled=${this._loading}>
                ${this._loading ? "Loading..." : "Ask AI"}
            </button>
            ${this._response ? html`<p>${this._response}</p>` : ""}
        `;
    }
}
```

{% endcode %}

## Key Concepts

### Controller Pattern

`UaiChatController` follows the Umbraco backoffice controller pattern. It requires a controller host (typically the element itself) for lifecycle management:

{% code title="Controller Initialization" %}

```typescript
class MyElement extends LitElement {
    // Controller is created with 'this' as the host
    #chatController = new UaiChatController(this);
}
```

{% endcode %}

The controller handles:

* API communication with the Management API
* Request lifecycle management
* Automatic cleanup on element disconnect

### Profile Selection

Specify which AI profile to use via `profileIdOrAlias`:

{% code title="Profile Selection" %}

```typescript
// Use default chat profile
await controller.complete(messages);

// Use specific profile by alias
await controller.complete(messages, { profileIdOrAlias: "content-assistant" });

// Use specific profile by ID
await controller.complete(messages, { profileIdOrAlias: "3fa85f64-5717-4562-b3fc-2c963f66afa6" });
```

{% endcode %}

### Cancellation

Pass an `AbortSignal` to cancel requests:

{% code title="Cancellation" %}

```typescript
const abortController = new AbortController();

// Start the request
const promise = controller.complete(messages, { signal: abortController.signal });

// Later, to cancel:
abortController.abort();
```

{% endcode %}

## In This Section

{% content-ref url="/pages/xPDb1odLYRgPiECQRH8q" %}
[Chat Controller](https://docs.umbraco.com/ai-in-umbraco/frontend/chat-controller.md)
{% endcontent-ref %}

{% content-ref url="/pages/wIYd8i9HraxacAmak28r" %}
[Embeddings Controller](https://docs.umbraco.com/ai-in-umbraco/frontend/embeddings-controller.md)
{% endcontent-ref %}

{% content-ref url="/pages/Rt2GtCG31VaEaaQPsneY" %}
[Speech-to-Text Controller](https://docs.umbraco.com/ai-in-umbraco/frontend/speech-to-text-controller.md)
{% endcontent-ref %}

{% content-ref url="/pages/y7trBX6am9oaF0kFHDY8" %}
[Decision Controller](https://docs.umbraco.com/ai-in-umbraco/frontend/decision-controller.md)
{% endcontent-ref %}

{% content-ref url="/pages/yqaDtxu0OX0z1ZDrTRo3" %}
[Extraction Controller](https://docs.umbraco.com/ai-in-umbraco/frontend/extraction-controller.md)
{% endcontent-ref %}

{% content-ref url="/pages/Px0YfFD3NJk0Sfa62WS4" %}
[Tool Controller](https://docs.umbraco.com/ai-in-umbraco/frontend/tool-controller.md)
{% endcontent-ref %}

{% content-ref url="/pages/nb6HHeaRTl3LLihQPieK" %}
[Chat Repository](https://docs.umbraco.com/ai-in-umbraco/frontend/chat-repository.md)
{% endcontent-ref %}

{% content-ref url="/pages/3TSHLmzpuTYg64YiFRii" %}
[Types](https://docs.umbraco.com/ai-in-umbraco/frontend/types.md)
{% endcontent-ref %}


---

# 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/frontend/frontend.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.
