New to Telerik UI for ASP.NET CoreStart a free 30-day trial

AI Integration

Updated on Dec 4, 2025

Integrating AI services with the Telerik UI for ASP.NET Core Chat component transforms a simple messaging interface into an intelligent conversational experience. Such integration allows you to create applications that can understand natural language, provide contextual responses, and deliver real-time AI-powered assistance to users.

In this article, you will build a practical, end-to-end example that demonstrates how to wire the Chat component to a lightweight AI chat client. This implementation covers opening a chat session, sending messages or quick replies, and streaming the AI model's response into the chat conversation.

Getting Started

To create an AI chat service that connects to the Chat, follow the steps below:

The example uses a Telerik-hosted AI service for demonstration purposes only. For production applications, you can implement your own AI service that understands your specific domain, data, and business requirements. For a runnable example with an established OpenAI backend integration, visit our GitHub Core Examples repository.

  1. Add references to the AI service client and the required formatting libraries for enhanced message display:

    JS
    <!-- Syntax highlighting for code blocks in AI responses -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/default.min.css">
    
    <!-- Markdown parsing library for formatting AI responses -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/16.2.0/lib/marked.umd.min.js"
        integrity="sha512-iFFK3wF8x/wQX/7dko0SsJeEgxUorBdYHFGRpGhnOsfnuewBBQ9a80cn0q1xjNB3kkBjA15NaRHFT7gQoG+V1g=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    
    <!-- Markdown syntax highlighting integration -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/marked-highlight/2.2.2/index.umd.min.js"
        integrity="sha512-T5TNAGHd65imlc6xoRDq9hARHowETqOlOGMJ443E+PohphJHbzPpwQNBtcpmcjmHmQKLctZ/W3H2cY/T8EGDPA=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    
    <!-- Code syntax highlighting engine -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"
        integrity="sha512-EBLzUL8XLl+va/zAsmXwS7Z2B1F9HUHkZwyS/VKwh3S7T/U0nF4BaU29EP/ZSf6zgiIxYAnKLu6bJ8dqpmX5uw=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    
    <!-- AI service client -->
    <script src="~/ai-service.js"></script>

    How does the AI service client work?

    • Session Management: Creates chat sessions (POST /chat/conversations), loads existing conversations (GET /chat/conversations), and manages individual chat rooms (GET /chat/{chatId}).
    • Message Streaming: Sends messages with optional file attachments to /chat/{chatId} and processes streaming responses in real-time using the Fetch API and ReadableStream.
    • Callback System: Invokes structured callbacks based on stream status: onStart (when streaming begins), onStreaming (for each chunk of data), and onComplete (when finished). Also handles onAbort and onError for cancellation and error scenarios.
    • Request Cancellation: Supports aborting in-flight requests through abortRequest() using AbortController for immediate cancellation.
    • File Support: Handles image file uploads alongside text messages using FormData for multimodal AI interactions.
    • Chat Lifecycle: Provides full CRUD operations including creating new chats and deleting existing conversations (DELETE /chat/conversations/{chatId}).
  2. Define the Chat component with predefined suggestions and a Download file action that will be displayed when the message contains an attachment.

    Razor
    @(Html.Kendo().Chat()
        .Name("chat")
        .SkipSanitization(true)
        .AuthorId("user-123") // Specifies the unique identifier of the current user. If not set, a GUID will be generated automatically.
        .AllowMessageCollapse(true)
        .Suggestions(suggestions => {
            suggestions.Add().Text("Analyse my photo");
            suggestions.Add().Text("Provide CV template");
            suggestions.Add().Text("Generate a cover letter");
        })
        .FileActions(actions =>
        {
            actions.Add().Name("download").Text("Download").Icon("download");
        })
    )
  3. Handle the following Chat client events:

    Razor
    @(Html.Kendo().Chat()
        .Name("chat")
        .Events(events =>
        {
            ev.Download("onDownload");
            ev.SendMessage("onSendMessage");
        })
        ... // Additional configuration.
    )

For the complete example, visit the AI Integration Demo of the Chat component.

See Also

In this article
Getting StartedSee Also
Not finding the help you need?
Contact Support