RadzenAIChat Class

RadzenAIChat component that provides a modern chat interface with AI integration and conversation memory.

Inheritance

Object

ComponentBase

RadzenComponent

RadzenAIChat

Implements

IComponent

IHandleEvent

IHandleAfterRender

Namespace: Radzen.Blazor

Assembly: Radzen.Blazor.dll

Syntax

public class RadzenAIChat : RadzenComponent, IComponent, IHandleEvent, IHandleAfterRender

Examples

<RadzenAIChat Title="AI Assistant" Placeholder="Type your message..." @bind-Messages="@chatMessages" SessionId="@sessionId" />

Constructors

RadzenAIChatLink to this section

RadzenAIChat component that provides a modern chat interface with AI integration and conversation memory.

Declaration
public RadzenAIChat()

Properties

AcceptedAttachmentTypesLink to this section

Gets or sets the accepted attachment types as an accept attribute value, for example image/*,.txt,.csv,.pdf. Default is image/*.

Declaration
public string AcceptedAttachmentTypes { get; set; }
Property Value
Type Description
stringGets or sets the accepted attachment types as an accept attribute value, for example image/*,.txt,.csv,.pdf. Default is image/*.

AllowAttachmentsLink to this section

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.

Declaration
public bool AllowAttachments { get; set; }
Property Value
Type Description
boolGets 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.

AllowMultipleToolCallsLink to this section

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.

Declaration
public bool? AllowMultipleToolCalls { get; set; }
Property Value
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.

ApiKeyLink to this section

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.

Declaration
public string ApiKey { get; set; }
Property Value
Type Description
stringGets 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.

ApiKeyHeaderLink to this section

Gets or sets the header the API key is sent with, overriding ApiKeyHeader.

Declaration
public string ApiKeyHeader { get; set; }
Property Value
Type Description
stringGets or sets the header the API key is sent with, overriding ApiKeyHeader.

AssistantAvatarTextLink to this section

Gets or sets the text displayed in the assistant avatar.

Declaration
public string AssistantAvatarText { get; set; }
Property Value
Type Description
stringGets or sets the text displayed in the assistant avatar.

ChatClearedLink to this section

Event callback that is invoked when the chat is cleared.

Declaration
public EventCallback ChatCleared { get; set; }
Property Value
Type Description
EventCallbackEvent callback that is invoked when the chat is cleared.

CitationTemplateLink to this section

Gets or sets the template used to render a source. The default renders a numbered link with the title and the snippet as tooltip.

Declaration
public RenderFragment<ChatCitation> CitationTemplate { get; set; }
Property Value
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.

DateSeparatorFormatLink to this section

Gets or sets the format used to render the date separator. Defaults to "D" (long date pattern).

Declaration
public string DateSeparatorFormat { get; set; }
Property Value
Type Description
stringGets or sets the format used to render the date separator. Defaults to "D" (long date pattern).

DateSeparatorTemplateLink to this section

Optional template to render the date separator shown between messages when the day changes. Receives the DateTime of the following message.

Declaration
public RenderFragment<DateTime> DateSeparatorTemplate { get; set; }
Property Value
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.

DisabledLink to this section

Gets or sets whether the chat is disabled.

Declaration
public bool Disabled { get; set; }
Property Value
Type Description
boolGets or sets whether the chat is disabled.

EmptyMessageLink to this section

Gets or sets the message displayed when there are no messages.

Declaration
public string EmptyMessage { get; set; }
Property Value
Type Description
stringGets or sets the message displayed when there are no messages.

EmptyTemplateLink to this section

Gets or sets the empty template shown when there are no messages.

Declaration
public RenderFragment EmptyTemplate { get; set; }
Property Value
Type Description
RenderFragmentGets or sets the empty template shown when there are no messages.

EndpointLink to this section

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.

Declaration
public string Endpoint { get; set; }
Property Value
Type Description
stringGets 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.

ErrorLink to this section

Event callback that is invoked when an attachment cannot be read, for example because it exceeds MaxAttachmentSize.

Declaration
public EventCallback<Exception> Error { get; set; }
Property Value
Type Description
EventCallback<Exception>Event callback that is invoked when an attachment cannot be read, for example because it exceeds MaxAttachmentSize.

InputAttributesLink to this section

Specifies additional custom attributes that will be rendered by the input.

Declaration
public IReadOnlyDictionary<string, object> InputAttributes { get; set; }
Property Value
Type Description
IReadOnlyDictionary<string, object>Specifies additional custom attributes that will be rendered by the input.

MaxAttachmentSizeLink to this section

Gets or sets the maximum size of an attachment in bytes. Default is 4 MB.

Declaration
public long MaxAttachmentSize { get; set; }
Property Value
Type Description
longGets or sets the maximum size of an attachment in bytes. Default is 4 MB.

MaxMessagesLink to this section

Gets or sets the maximum number of messages to keep in the chat.

Declaration
public int MaxMessages { get; set; }
Property Value
Type Description
intGets or sets the maximum number of messages to keep in the chat.

MaxTokensLink to this section

Gets or sets the max tokens.

Declaration
public int? MaxTokens { get; set; }
Property Value
Type Description
int?Gets or sets the max tokens.

MessageAddedLink to this section

Event callback that is invoked when a new message is added.

Declaration
public EventCallback<ChatMessage> MessageAdded { get; set; }
Property Value
Type Description
EventCallback<ChatMessage>Event callback that is invoked when a new message is added.

MessageSentLink to this section

Event callback that is invoked when a message is sent.

Declaration
public EventCallback<string> MessageSent { get; set; }
Property Value
Type Description
EventCallback<string>Event callback that is invoked when a message is sent.

MessageTemplateLink to this section

Gets or sets the message template.

Declaration
public RenderFragment<ChatMessage> MessageTemplate { get; set; }
Property Value
Type Description
RenderFragment<ChatMessage>Gets or sets the message template.

ModelLink to this section

Gets or sets the model name.

Declaration
public string Model { get; set; }
Property Value
Type Description
stringGets or sets the model name.

PendingAttachmentsLink to this section

Gets the attachments that will be sent with the next message.

Declaration
public IReadOnlyList<ChatAttachment> PendingAttachments { get; }
Property Value
Type Description
IReadOnlyList<ChatAttachment>Gets the attachments that will be sent with the next message.

PlaceholderLink to this section

Gets or sets the placeholder text for the input field.

Declaration
public string Placeholder { get; set; }
Property Value
Type Description
stringGets or sets the placeholder text for the input field.

ProxyLink to this section

Gets or sets the URL of a server endpoint that forwards the requests to the AI provider and adds the API key, overriding Proxy.

Declaration
public string Proxy { get; set; }
Property Value
Type Description
stringGets or sets the URL of a server endpoint that forwards the requests to the AI provider and adds the API key, overriding Proxy.

ReadOnlyLink to this section

Gets or sets whether the input is read-only.

Declaration
public bool ReadOnly { get; set; }
Property Value
Type Description
boolGets or sets whether the input is read-only.

ResponseReceivedLink to this section

Event callback that is invoked when the AI response is received.

Declaration
public EventCallback<string> ResponseReceived { get; set; }
Property Value
Type Description
EventCallback<string>Event callback that is invoked when the AI response is received.

SessionIdLink to this section

Gets or sets the session ID for maintaining conversation memory. If null, a new session will be created.

Declaration
public string SessionId { get; set; }
Property Value
Type Description
stringGets or sets the session ID for maintaining conversation memory. If null, a new session will be created.

SessionIdChangedLink to this section

Event callback that is invoked when a session ID is created or retrieved.

Declaration
public EventCallback<string> SessionIdChanged { get; set; }
Property Value
Type Description
EventCallback<string>Event callback that is invoked when a session ID is created or retrieved.

ShowCitationsLink to this section

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.

Declaration
public bool ShowCitations { get; set; }
Property Value
Type Description
boolGets 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.

ShowClearButtonLink to this section

Gets or sets whether to show the clear chat button.

Declaration
public bool ShowClearButton { get; set; }
Property Value
Type Description
boolGets or sets whether to show the clear chat button.

ShowDateSeparatorLink to this section

Gets or sets whether a date separator is rendered between messages when the day changes.

Declaration
public bool ShowDateSeparator { get; set; }
Property Value
Type Description
boolGets or sets whether a date separator is rendered between messages when the day changes.

ShowReasoningLink to this section

Gets or sets whether the reasoning of models that expose it is rendered as a collapsible block in assistant messages. Default is true.

Declaration
public bool ShowReasoning { get; set; }
Property Value
Type Description
boolGets or sets whether the reasoning of models that expose it is rendered as a collapsible block in assistant messages. Default is true.

ShowToolCallsLink to this section

Gets or sets whether tool calls are rendered in assistant messages. Default is true.

Declaration
public bool ShowToolCalls { get; set; }
Property Value
Type Description
boolGets or sets whether tool calls are rendered in assistant messages. Default is true.

ShowUsageLink to this section

Gets or sets whether the token usage reported by the model is shown next to the time of assistant messages. Default is false.

Declaration
public bool ShowUsage { get; set; }
Property Value
Type Description
boolGets or sets whether the token usage reported by the model is shown next to the time of assistant messages. Default is false.

SystemPromptLink to this section

Gets or sets the system prompt.

Declaration
public string SystemPrompt { get; set; }
Property Value
Type Description
stringGets or sets the system prompt.

TemperatureLink to this section

Gets or sets the temperature.

Declaration
public double? Temperature { get; set; }
Property Value
Type Description
double?Gets or sets the temperature.

TimestampFormatLink to this section

Gets or sets the format used to render the timestamp shown next to each message. Defaults to "HH:mm".

Declaration
public string TimestampFormat { get; set; }
Property Value
Type Description
stringGets or sets the format used to render the timestamp shown next to each message. Defaults to "HH:mm".

TitleLink to this section

Gets or sets the title displayed in the chat header.

Declaration
public string Title { get; set; }
Property Value
Type Description
stringGets or sets the title displayed in the chat header.

ToolCallCompletedLink to this section

Event callback that is invoked when a tool call completes, fails or is rejected.

Declaration
public EventCallback<ChatToolCall> ToolCallCompleted { get; set; }
Property Value
Type Description
EventCallback<ChatToolCall>Event callback that is invoked when a tool call completes, fails or is rejected.

ToolCallTemplateLink to this section

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.

Declaration
public RenderFragment<ChatToolCall> ToolCallTemplate { get; set; }
Property Value
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.

ToolsLink to this section

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.

Declaration
public IEnumerable<Microsoft.Extensions.AI.AITool> Tools { get; set; }
Property Value
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.

UserAvatarTextLink to this section

Gets or sets the text displayed in the user avatar.

Declaration
public string UserAvatarText { get; set; }
Property Value
Type Description
stringGets or sets the text displayed in the user avatar.

UserIdLink to this section

Gets or sets the user the conversation belongs to. Stored in UserId so that IConversationStore implementations can list the conversations of a user.

Declaration
public string UserId { get; set; }
Property Value
Type Description
stringGets or sets the user the conversation belongs to. Stored in UserId so that IConversationStore implementations can list the conversations of a user.

Methods

AddAttachmentLink to this section

Adds an attachment to the next message.

Declaration
public void AddAttachment(ChatAttachment attachment)
Parameters
Type Name Description
ChatAttachment attachment The attachment.

AddMessageLink to this section

Adds a message to the chat.

Declaration
public ChatMessage AddMessage(string content, bool isUser)
Parameters
Type Name Description
string content The message content.
bool isUser Whether the message is from the user.
Returns
Type Description
ChatMessageThe created message.

ApproveToolCallLink to this section

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.

Declaration
public Task ApproveToolCall(ChatToolCall call)
Parameters
Type Name Description
ChatToolCall call The tool call.
Returns
Type Description
Task

BuildRenderTreeLink to this section

Declaration
protected override void BuildRenderTree(Rendering.RenderTreeBuilder __builder)
Parameters
Type Name Description
Rendering.RenderTreeBuilder __builder

ClearAttachmentsLink to this section

Removes all pending attachments.

Declaration
public void ClearAttachments()

ClearChatLink to this section

Clears all messages from the chat.

Declaration
public Task ClearChat()
Returns
Type Description
Task

DisposeLink to this section

Declaration
public override void Dispose()

GetComponentCssClassLink to this section

Declaration
protected override string GetComponentCssClass()
Returns
Type Description
string

GetMessagesLink to this section

Gets the current list of messages.

Declaration
public IReadOnlyList<ChatMessage> GetMessages()
Returns
Type Description
IReadOnlyList<ChatMessage>

GetSessionIdLink to this section

Gets the current session ID.

Declaration
public string GetSessionId()
Returns
Type Description
string

LoadConversationHistoryLink to this section

Loads conversation history from the AI service session.

Declaration
public Task LoadConversationHistory()
Returns
Type Description
Task

LoadMessagesLink to this section

Loads messages into the chat, replacing any existing ones. Preserves the timestamp of each message — use this to restore conversation history.

Declaration
public Task LoadMessages(IEnumerable<ChatMessage> messages)
Parameters
Type Name Description
IEnumerable<ChatMessage> messages The messages to load.
Returns
Type Description
Task

OnAfterRenderAsyncLink to this section

Declaration
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
Type Name Description
bool firstRender
Returns
Type Description
Task

OnInitializedAsyncLink to this section

Declaration
protected override Task OnInitializedAsync()
Returns
Type Description
Task

OnParametersSetAsyncLink to this section

Declaration
protected override Task OnParametersSetAsync()
Returns
Type Description
Task

RejectToolCallLink to this section

Rejects a tool call that is awaiting the user's approval. The model is told the call was rejected and continues its response.

Declaration
public Task RejectToolCall(ChatToolCall call)
Parameters
Type Name Description
ChatToolCall call The tool call.
Returns
Type Description
Task

RemoveAttachmentLink to this section

Removes an attachment from the next message.

Declaration
public void RemoveAttachment(ChatAttachment attachment)
Parameters
Type Name Description
ChatAttachment attachment The attachment.

SendMessageLink to this section

Sends a message programmatically.

Declaration
public Task SendMessage(string content)
Parameters
Type Name Description
string content The message content to send.
Returns
Type Description
Task

SendMessageLink to this section

Sends a message programmatically.

Declaration
public Task SendMessage(string content, string model, string systemPrompt, double? temperature, int? maxTokens, string endpoint, string proxy, string apiKey, string apiKeyHeader)
Parameters
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
Returns
Type Description
Task

StopLink to this section

Stops the response that is being generated. The text received so far is kept.

Declaration
public void Stop()
An error has occurred. This app may no longer respond until reloaded. Reload 🗙