# AIPrompt Events

This article explains the events available in the Telerik AIPrompt for Blazor:

* [`OnOutputActionClick`](https://www.telerik.com/blazor-ui/documentation/components/aiprompt/events#onoutputactionclick)
* [`OnPromptRequest`](https://www.telerik.com/blazor-ui/documentation/components/aiprompt/events#onpromptrequest)
* [`OnPromptRequestStop`](https://www.telerik.com/blazor-ui/documentation/components/aiprompt/events#onpromptrequeststop)
* [`OnCommandExecute`](https://www.telerik.com/blazor-ui/documentation/components/aiprompt/events#oncommandexecute)
* [`PromptChanged`](https://www.telerik.com/blazor-ui/documentation/components/aiprompt/events#promptchanged)

## OnOutputActionClick

The `OnOutputActionClick` event fires when the user clicks an output action button in the output view of the AIPrompt component. Use this event to handle custom actions such as copying, retrying, or providing feedback on the generated output.

To define the available output actions, set the `OutputActions` parameter to a list of [`AIPromptOutputActionDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.aipromptoutputactiondescriptor) objects. Each action descriptor configures the appearance and behavior of an action button.

The event handler receives an argument of type `AIPromptOutputActionClickEventArgs`, which provides details about the clicked action, the prompt, the output, and the related command (if any). For a full list of available properties, refer to the [`AIPromptOutputActionClickEventArgs` API reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.aipromptoutputactionclickeventargs).

See the [example below](https://www.telerik.com/blazor-ui/documentation/components/aiprompt/events#example).

## OnPromptRequest

The `OnPromptRequest` event fires when the user clicks on the **Generate** button within the Prompt view or retries a prompt from the Output view.

The event handler receives an argument of type [`AIPromptPromptRequestEventArgs`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.aipromptpromptrequesteventargs). See the [example below](https://www.telerik.com/blazor-ui/documentation/components/aiprompt/events#example).

<style>
    .article table {
        table-layout: auto;
        word-break: normal;
    }
</style>

| Property      | Type                           | Description                                                                                                                                                                                                                                       |
| ------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Prompt`      | `string`                       | The prompt text of the request.                                                                                                                                                                                                                   |
| `Output`      | `string`                       | The output of the request. The output is based on the prompt text.                                                                                                                                                                                |
| `IsCancelled` | `bool`                         | Whether the event is cancelled and the built-in action is prevented.                                                                                                                                                                              |
| `OutputItem`  | `AIPromptOutputItemDescriptor` | The output item. This property will be populated only when the user retries an existing output. See [`AIPromptOutputItemDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.aipromptoutputitemdescriptor). |

> Do not use the `OnPromptRequest` event when [integrating the AIPrompt component with `Microsoft.Extensions.AI`](https://www.telerik.com/blazor-ui/documentation/common-features/microsoft-extensions-ai-integration). The `OnPromptRequest` event disables such integration.

## OnPromptRequestStop

The `OnPromptRequestStop` event fires when the user stops a prompt request by clicking the stop floating action button in the output view. This event allows you to handle the cancellation of an ongoing prompt request.

The event handler receives an `EventCallback` with no arguments.

## OnCommandExecute

The `OnCommandExecute` event fires when the user clicks on a command within the Commands view.

The event handler receives an argument of type [`AIPromptCommandExecuteEventArgs`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.aipromptcommandexecuteeventargs). See the [example below](https://www.telerik.com/blazor-ui/documentation/components/aiprompt/events#example).

<style>
    .article table {
        table-layout: auto;
        word-break: normal;
    }
</style>

| Property      | Type                           | Description                                                                                                                                                                                                                                       |
| ------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Command`     | `AIPromptCommandDescriptor`    | The executed command.                                                                                                                                                                                                                             |
| `Output`      | `string`                       | The output based on the executed command.                                                                                                                                                                                                         |
| `IsCancelled` | `bool`                         | Whether the event is cancelled and the built-in action is prevented.                                                                                                                                                                              |
| `OutputItem`  | `AIPromptOutputItemDescriptor` | The output item. This property will be populated only when the user retries an existing output. See [`AIPromptOutputItemDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.aipromptoutputitemdescriptor). |

## PromptChanged

The `PromptChanged` event fires when the user changes the prompt text. Use the event to update the AIPrompt's prompt when the `Prompt` parameter is set with one-way binding, otherwise, the user action will be ignored.

## Example

> caption Using AIPrompt events

<demo metaUrl="client/aiprompt/events/events/" height="420"></demo>

## See Also

* [Live Demo: AIPrompt](https://demos.telerik.com/blazor-ui/aiprompt/overview)
