RadzenAIChat component that provides a modern chat interface with AI integration and conversation memory.
IComponent
IHandleEvent
IHandleAfterRender
RadzenComponent.GetIdAttribute
RadzenComponent.RaiseContextMenu
RadzenComponent.RaiseMouseEnter
RadzenComponent.AddContextMenu
RadzenComponent.RaiseMouseLeave
RadzenComponent.OnBecameInvisible
RadzenComponent.DefaultCulture
RadzenComponent.DefaultUICulture
RadzenComponent.IsJSRuntimeAvailable
ComponentBase.OnParametersSet
ComponentBase.StateHasChanged
ComponentBase.ShouldRender
ComponentBase.OnAfterRender
ComponentBase.InvokeAsync
ComponentBase.DispatchExceptionAsync
ComponentBase.RendererInfo
ComponentBase.Assets
ComponentBase.AssignedRenderMode
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
public class RadzenAIChat : RadzenComponent, IComponent, IHandleEvent, IHandleAfterRender<RadzenAIChat Title="AI Assistant" Placeholder="Type your message..." @bind-Messages="@chatMessages" SessionId="@sessionId" />RadzenAIChat component that provides a modern chat interface with AI integration and conversation memory.
public RadzenAIChat()Gets or sets the accepted attachment types as an accept attribute value, for example image/*,.txt,.csv,.pdf. Default is image/*.
public string AcceptedAttachmentTypes { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the accepted attachment types as an accept attribute value, for example image/*,.txt,.csv,.pdf. Default is image/*. |
Gets or sets whether the user can attach files to messages. Images are sent to the model as image content and need a multimodal model; text files (txt, csv, md, json, xml and similar) are sent as text, PDF files as file content for providers that support it. Default is false.
public bool AllowAttachments { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether the user can attach files to messages. Images are sent to the model as image content and need a multimodal model; text files (txt, csv, md, json, xml and similar) are sent as text, PDF files as file content for providers that support it. Default is false. |
Gets or sets whether the model may call several tools in one response. null (the default) leaves it to the provider. Set to false when using tools that require approval so that each call is approved on its own.
public bool? AllowMultipleToolCalls { get; set; }
| Type | Description |
|---|---|
| bool? | Gets or sets whether the model may call several tools in one response. null (the default) leaves it to the provider. Set to false when using tools that require approval so that each call is approved on its own. |
Gets or sets the API key, overriding ApiKey. Blazor Server only: the component throws when a key is set in a WebAssembly application, because it would be visible to every user. Keep the key on the server and use Proxy.
public string ApiKey { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the API key, overriding ApiKey. Blazor Server only: the component throws when a key is set in a WebAssembly application, because it would be visible to every user. Keep the key on the server and use Proxy. |
Gets or sets the header the API key is sent with, overriding ApiKeyHeader.
public string ApiKeyHeader { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the header the API key is sent with, overriding ApiKeyHeader. |
Gets or sets the text displayed in the assistant avatar.
public string AssistantAvatarText { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the text displayed in the assistant avatar. |
Event callback that is invoked with every file the user picks before it is attached. Set Cancel to reject it or replace Attachment, for example with a scaled down image. Files added from code with ChatAttachment) do not raise it.
public EventCallback<ChatAttachmentAddingEventArgs> AttachmentAdding { get; set; }
| Type | Description |
|---|---|
| EventCallback<ChatAttachmentAddingEventArgs> | Event callback that is invoked with every file the user picks before it is attached. Set Cancel to reject it or replace Attachment, for example with a scaled down image. Files added from code with ChatAttachment) do not raise it. |
Event callback that is invoked when the chat is cleared.
public EventCallback ChatCleared { get; set; }
| Type | Description |
|---|---|
| EventCallback | Event callback that is invoked when the chat is cleared. |
Gets or sets the template used to render a source. The default renders a numbered link with the title and the snippet as tooltip.
public RenderFragment<ChatCitation> CitationTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment<ChatCitation> | Gets or sets the template used to render a source. The default renders a numbered link with the title and the snippet as tooltip. |
Gets or sets the format used to render the date separator. Defaults to "D" (long date pattern).
public string DateSeparatorFormat { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the format used to render the date separator. Defaults to "D" (long date pattern). |
Optional template to render the date separator shown between messages when the day changes. Receives the DateTime of the following message.
public RenderFragment<DateTime> DateSeparatorTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment<DateTime> | Optional template to render the date separator shown between messages when the day changes. Receives the DateTime of the following message. |
Gets or sets whether the chat is disabled.
public bool Disabled { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether the chat is disabled. |
Gets or sets the message displayed when there are no messages.
public string EmptyMessage { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the message displayed when there are no messages. |
Gets or sets the empty template shown when there are no messages.
public RenderFragment EmptyTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment | Gets or sets the empty template shown when there are no messages. |
Gets or sets the endpoint URL of the AI provider, overriding Endpoint. In a WebAssembly application use Proxy instead, so the request goes through your server.
public string Endpoint { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the endpoint URL of the AI provider, overriding Endpoint. In a WebAssembly application use Proxy instead, so the request goes through your server. |
Event callback that is invoked when an attachment cannot be read, for example because it exceeds MaxAttachmentSize.
public EventCallback<Exception> Error { get; set; }
| Type | Description |
|---|---|
| EventCallback<Exception> | Event callback that is invoked when an attachment cannot be read, for example because it exceeds MaxAttachmentSize. |
Gets or sets the content rendered in the chat header between Title and the clear button, for example a conversation switcher. The header is rendered when a title, the clear button or this template is set.
public RenderFragment HeaderTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment | Gets or sets the content rendered in the chat header between Title and the clear button, for example a conversation switcher. The header is rendered when a title, the clear button or this template is set. |
Gets or sets the text of the input. Bind it with @bind-Input to read what the user has typed or to set the text from code, for example to offer a prompt.
public string Input { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the text of the input. Bind it with @bind-Input to read what the user has typed or to set the text from code, for example to offer a prompt. |
Specifies additional custom attributes that will be rendered by the input.
public IReadOnlyDictionary<string, object> InputAttributes { get; set; }
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, object> | Specifies additional custom attributes that will be rendered by the input. |
Event callback that is invoked when the text of the input changes.
public EventCallback<string> InputChanged { get; set; }
| Type | Description |
|---|---|
| EventCallback<string> | Event callback that is invoked when the text of the input changes. |
Gets or sets the content rendered in the input area above the text box, below the pending attachments, for example a status line or a notice about the attachments.
public RenderFragment InputHeaderTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment | Gets or sets the content rendered in the input area above the text box, below the pending attachments, for example a status line or a notice about the attachments. |
Gets or sets the maximum size of an attachment in bytes. Default is 4 MB.
public long MaxAttachmentSize { get; set; }
| Type | Description |
|---|---|
| long | Gets or sets the maximum size of an attachment in bytes. Default is 4 MB. |
Gets or sets the maximum number of messages to keep in the chat.
public int MaxMessages { get; set; }
| Type | Description |
|---|---|
| int | Gets or sets the maximum number of messages to keep in the chat. |
Gets or sets the max tokens.
public int? MaxTokens { get; set; }
| Type | Description |
|---|---|
| int? | Gets or sets the max tokens. |
Gets or sets the maximum total size in bytes of the attachments of a message. A file the user picks that would push the pending attachments over it is not attached and Error is raised. Checked after AttachmentAdding, on the attachment it leaves. Attachments added from code with ChatAttachment) are not checked. Default is null: no limit.
public long? MaxTotalAttachmentSize { get; set; }
| Type | Description |
|---|---|
| long? | Gets or sets the maximum total size in bytes of the attachments of a message. A file the user picks that would push the pending attachments over it is not attached and Error is raised. Checked after AttachmentAdding, on the attachment it leaves. Attachments added from code with ChatAttachment) are not checked. Default is null: no limit. |
Event callback that is invoked when a new message is added.
public EventCallback<ChatMessage> MessageAdded { get; set; }
| Type | Description |
|---|---|
| EventCallback<ChatMessage> | Event callback that is invoked when a new message is added. |
Event callback that is invoked when a message is sent.
public EventCallback<string> MessageSent { get; set; }
| Type | Description |
|---|---|
| EventCallback<string> | Event callback that is invoked when a message is sent. |
Gets or sets the template that renders every message in place of the default rendering. Call ChatMessage) from it to keep the default rendering for some messages, for example to render only the entries the application adds with ChatMessage) your way, or to add content under a message.
public RenderFragment<ChatMessage> MessageTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment<ChatMessage> | Gets or sets the template that renders every message in place of the default rendering. Call ChatMessage) from it to keep the default rendering for some messages, for example to render only the entries the application adds with ChatMessage) your way, or to add content under a message. |
Gets or sets the model name.
public string Model { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the model name. |
Gets the attachments that will be sent with the next message.
public IReadOnlyList<ChatAttachment> PendingAttachments { get; }
| Type | Description |
|---|---|
| IReadOnlyList<ChatAttachment> | Gets the attachments that will be sent with the next message. |
Gets or sets the placeholder text for the input field.
public string Placeholder { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the placeholder text for the input field. |
Gets or sets the URL of a server endpoint that forwards the requests to the AI provider and adds the API key, overriding Proxy.
public string Proxy { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the URL of a server endpoint that forwards the requests to the AI provider and adds the API key, overriding Proxy. |
Gets or sets whether messages sent while a response is being generated are accepted instead of ignored. Default is false. Such a message appears in the conversation right away, marked as queued, and is offered to the service with CancellationToken) as a request whose MessageId is the Id of the displayed message. A service that takes it tells the chat when the model reads it by yielding a ChatResponseUpdate with User and that id: the message then moves to the end of the conversation, loses the queued mark and the rest of the response goes into a new assistant message under it. A service that does not take the message is sent it with the next request once the response completes; Stop drops the messages waiting for that and returns their text to the input, while messages a service took stay for the service to remove with ChatMessage). The send button stays next to the stop button while the response streams.
public bool QueueMessages { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether messages sent while a response is being generated are accepted instead of ignored. Default is false. Such a message appears in the conversation right away, marked as queued, and is offered to the service with CancellationToken) as a request whose MessageId is the Id of the displayed message. A service that takes it tells the chat when the model reads it by yielding a ChatResponseUpdate with User and that id: the message then moves to the end of the conversation, loses the queued mark and the rest of the response goes into a new assistant message under it. A service that does not take the message is sent it with the next request once the response completes; Stop drops the messages waiting for that and returns their text to the input, while messages a service took stay for the service to remove with ChatMessage). The send button stays next to the stop button while the response streams. |
Gets the messages waiting to be sent once the current response completes. See QueueMessages.
public IReadOnlyList<ChatMessage> QueuedMessages { get; }
| Type | Description |
|---|---|
| IReadOnlyList<ChatMessage> | Gets the messages waiting to be sent once the current response completes. See QueueMessages. |
Gets or sets whether the input is read-only.
public bool ReadOnly { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether the input is read-only. |
Event callback that is invoked when the AI response is received.
public EventCallback<string> ResponseReceived { get; set; }
| Type | Description |
|---|---|
| EventCallback<string> | Event callback that is invoked when the AI response is received. |
Gets or sets the icon of the send button. Default is send.
public string SendButtonIcon { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the icon of the send button. Default is send. |
Gets or sets the text of the send button. Default is null: the button shows only its icon.
public string SendButtonText { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the text of the send button. Default is null: the button shows only its icon. |
Gets or sets the session ID for maintaining conversation memory. If null, a new session will be created.
public string SessionId { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the session ID for maintaining conversation memory. If null, a new session will be created. |
Event callback that is invoked when a session ID is created or retrieved.
public EventCallback<string> SessionIdChanged { get; set; }
| Type | Description |
|---|---|
| EventCallback<string> | Event callback that is invoked when a session ID is created or retrieved. |
Gets or sets whether the avatars of the user and the assistant are rendered next to the messages. Default is true.
public bool ShowAvatars { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether the avatars of the user and the assistant are rendered next to the messages. Default is true. |
Gets or sets whether the sources of an answer are rendered under it. Default is true. Sources are the CitationAnnotation annotations the provider attaches to the response and the ChatCitation instances tools return.
public bool ShowCitations { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether the sources of an answer are rendered under it. Default is true. Sources are the CitationAnnotation annotations the provider attaches to the response and the ChatCitation instances tools return. |
Gets or sets whether to show the clear chat button.
public bool ShowClearButton { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether to show the clear chat button. |
Gets or sets whether a date separator is rendered between messages when the day changes.
public bool ShowDateSeparator { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether a date separator is rendered between messages when the day changes. |
Gets or sets whether the reasoning of models that expose it is rendered as a collapsible block in assistant messages. Default is true.
public bool ShowReasoning { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether the reasoning of models that expose it is rendered as a collapsible block in assistant messages. Default is true. |
Gets or sets whether tool calls are rendered in assistant messages. Default is true.
public bool ShowToolCalls { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether tool calls are rendered in assistant messages. Default is true. |
Gets or sets whether the token usage reported by the model is shown next to the time of assistant messages. Default is false.
public bool ShowUsage { get; set; }
| Type | Description |
|---|---|
| bool | Gets or sets whether the token usage reported by the model is shown next to the time of assistant messages. Default is false. |
Gets or sets the icon of the stop button. Default is stop_circle.
public string StopButtonIcon { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the icon of the stop button. Default is stop_circle. |
Gets or sets the text of the stop button shown while a response streams. Default is null: the button shows only its icon.
public string StopButtonText { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the text of the stop button shown while a response streams. Default is null: the button shows only its icon. |
Gets or sets the system prompt.
public string SystemPrompt { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the system prompt. |
Gets or sets the temperature.
public double? Temperature { get; set; }
| Type | Description |
|---|---|
| double? | Gets or sets the temperature. |
Gets or sets the format used to render the timestamp shown next to each message. Defaults to "HH:mm".
public string TimestampFormat { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the format used to render the timestamp shown next to each message. Defaults to "HH:mm". |
Gets or sets the title displayed in the chat header.
public string Title { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the title displayed in the chat header. |
Event callback that is invoked when a tool call completes, fails or is rejected.
public EventCallback<ChatToolCall> ToolCallCompleted { get; set; }
| Type | Description |
|---|---|
| EventCallback<ChatToolCall> | Event callback that is invoked when a tool call completes, fails or is rejected. |
Gets or sets the template used to render a tool call. The template is responsible for rendering approval UI for calls in the AwaitingApproval state; call ChatToolCall) or ChatToolCall) to answer them.
public RenderFragment<ChatToolCall> ToolCallTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment<ChatToolCall> | Gets or sets the template used to render a tool call. The template is responsible for rendering approval UI for calls in the AwaitingApproval state; call ChatToolCall) or ChatToolCall) to answer them. |
Gets or sets the tools the model can call. Create them with AIFunctionFactory; wrap a tool in ApprovalRequiredAIFunction to ask the user before it runs. Tools are invoked automatically and rendered in the assistant message; use ToolCallTemplate to customize how.
public IEnumerable<Microsoft.Extensions.AI.AITool> Tools { get; set; }
| Type | Description |
|---|---|
| IEnumerable<Microsoft.Extensions.AI.AITool> | Gets or sets the tools the model can call. Create them with AIFunctionFactory; wrap a tool in ApprovalRequiredAIFunction to ask the user before it runs. Tools are invoked automatically and rendered in the assistant message; use ToolCallTemplate to customize how. |
Gets or sets the template rendered next to the time of an assistant message instead of the default token count, when ShowUsage is true and the message has Usage. Use it to show what AdditionalCounts carries, for example credits.
public RenderFragment<ChatMessage> UsageTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment<ChatMessage> | Gets or sets the template rendered next to the time of an assistant message instead of the default token count, when ShowUsage is true and the message has Usage. Use it to show what AdditionalCounts carries, for example credits. |
Gets or sets the text displayed in the user avatar.
public string UserAvatarText { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the text displayed in the user avatar. |
Gets or sets the user the conversation belongs to. Stored in UserId so that IConversationStore implementations can list the conversations of a user.
public string UserId { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the user the conversation belongs to. Stored in UserId so that IConversationStore implementations can list the conversations of a user. |
Adds an attachment to the next message as it is: AttachmentAdding, MaxAttachmentSize and MaxTotalAttachmentSize apply only to files the user picks.
public void AddAttachment(ChatAttachment attachment)
| Type | Name | Description |
|---|---|---|
| ChatAttachment | attachment | The attachment. |
Adds a message to the chat.
public ChatMessage AddMessage(string content, bool isUser)
| Type | Name | Description |
|---|---|---|
| string | content | The message content. |
| bool | isUser | Whether the message is from the user. |
| Type | Description |
|---|---|
| ChatMessage | The created message. |
Adds a message to the chat.
public ChatMessage AddMessage(ChatMessage message)
| Type | Name | Description |
|---|---|---|
| ChatMessage | message |
| Type | Description |
|---|---|
| ChatMessage | The created message. |
Approves a tool call that is awaiting the user's approval. The tool is invoked and the model continues its response. When the same message holds other calls that still await approval the answer is sent once all of them are answered.
public Task ApproveToolCall(ChatToolCall call)
| Type | Name | Description |
|---|---|---|
| ChatToolCall | call | The tool call. |
| Type | Description |
|---|---|
| Task |
protected override void BuildRenderTree(Rendering.RenderTreeBuilder __builder)
| Type | Name | Description |
|---|---|---|
| Rendering.RenderTreeBuilder | __builder |
Removes all pending attachments.
public void ClearAttachments()Clears all messages from the chat.
public Task ClearChat()
| Type | Description |
|---|---|
| Task |
Focuses the input.
public ValueTask FocusAsync()
| Type | Description |
|---|---|
| ValueTask |
protected override string GetComponentCssClass()
| Type | Description |
|---|---|
| string |
Gets the current list of messages.
public IReadOnlyList<ChatMessage> GetMessages()
| Type | Description |
|---|---|
| IReadOnlyList<ChatMessage> |
Gets the current session ID.
public string GetSessionId()
| Type | Description |
|---|---|
| string |
Loads conversation history from the AI service session.
public Task LoadConversationHistory()
| Type | Description |
|---|---|
| Task |
Loads messages into the chat, replacing any existing ones. Preserves the timestamp of each message — use this to restore conversation history.
public Task LoadMessages(IEnumerable<ChatMessage> messages)
| Type | Name | Description |
|---|---|---|
| IEnumerable<ChatMessage> | messages | The messages to load. |
| Type | Description |
|---|---|
| Task |
protected override Task OnAfterRenderAsync(bool firstRender)
| Type | Name | Description |
|---|---|---|
| bool | firstRender |
| Type | Description |
|---|---|
| Task |
protected override Task OnInitializedAsync()
| Type | Description |
|---|---|
| Task |
protected override Task OnParametersSetAsync()
| Type | Description |
|---|---|
| Task |
Renders the chat again, for example after changing the Content of a message it shows.
public void Refresh()Rejects a tool call that is awaiting the user's approval. The model is told the call was rejected and continues its response.
public Task RejectToolCall(ChatToolCall call)
| Type | Name | Description |
|---|---|---|
| ChatToolCall | call | The tool call. |
| Type | Description |
|---|---|
| Task |
Removes an attachment from the next message.
public void RemoveAttachment(ChatAttachment attachment)
| Type | Name | Description |
|---|---|---|
| ChatAttachment | attachment | The attachment. |
Removes a message from the chat, for example a Progress entry that ended. The conversation sent to the model is not affected.
public bool RemoveMessage(ChatMessage message)
| Type | Name | Description |
|---|---|---|
| ChatMessage | message | The message. |
| Type | Description |
|---|---|
| bool | true when the message was in the chat. |
Renders a message the way the chat does by default: the avatar, time, usage, attachments, reasoning, text and tool calls in order, sources and MessageFooterTemplate, or the status, progress or error entry for the other ChatMessageKind values. Use it in MessageTemplate for the messages you do not render yourself.
public RenderFragment RenderMessage(ChatMessage message)
| Type | Name | Description |
|---|---|---|
| ChatMessage | message | The message. |
| Type | Description |
|---|---|
| RenderFragment |
Sends a message programmatically.
public Task SendMessage(string content)
| Type | Name | Description |
|---|---|---|
| string | content | The message content to send. |
| Type | Description |
|---|---|
| Task |
Sends a message programmatically.
public Task SendMessage(string content, string model, string systemPrompt, double? temperature, int? maxTokens, string endpoint, string proxy, string apiKey, string apiKeyHeader)
| Type | Name | Description |
|---|---|---|
| string | content | The message content to send. |
| string | model | |
| string | systemPrompt | |
| double? | temperature | |
| int? | maxTokens | |
| string | endpoint | |
| string | proxy | |
| string | apiKey | |
| string | apiKeyHeader |
| Type | Description |
|---|---|
| Task |
public override Task SetParametersAsync(ParameterView parameters)
| Type | Name | Description |
|---|---|---|
| ParameterView | parameters |
| Type | Description |
|---|---|
| Task |
Stops the response that is being generated. The text received so far is kept.
public void Stop()