RadzenAIChat component that provides a modern chat interface with AI integration and conversation memory.
IComponent
IHandleEvent
IHandleAfterRender
RadzenComponent.GetIdAttribute
RadzenComponent.SetParametersAsync
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 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. |
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. |
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. |
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 message template.
public RenderFragment<ChatMessage> MessageTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment<ChatMessage> | Gets or sets the message template. |
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 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 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 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 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 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.
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. |
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 |
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 |
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. |
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 |
Stops the response that is being generated. The text received so far is kept.
public void Stop()