For the complete documentation index, see llms.txt. This page is also available as Markdown.

Chat

Use the chat API for conversational AI, text generation, and completions.

The chat API provides access to conversational AI capabilities. Use it for text generation, question answering, content creation, and more.

IAIChatService

The primary interface for chat operations:

IAIChatService.cs
public interface IAIChatService
{
    // Non-streaming responses
    Task<ChatResponse> GetChatResponseAsync(
        Action<AIChatBuilder> configure,
        IEnumerable<ChatMessage> messages,
        CancellationToken cancellationToken = default);

    // Streaming responses
    IAsyncEnumerable<ChatResponseUpdate> StreamChatResponseAsync(
        Action<AIChatBuilder> configure,
        IEnumerable<ChatMessage> messages,
        CancellationToken cancellationToken = default);

    // Advanced: Create the underlying client
    Task<IChatClient> CreateChatClientAsync(
        Action<AIChatBuilder> configure,
        CancellationToken cancellationToken = default);
}

Basic Usage

Message Roles

Role
Description

ChatRole.System

Instructions for the AI (set behavior, context)

ChatRole.User

Messages from the user

ChatRole.Assistant

Previous responses from the AI

ChatRole.Tool

Results from tool/function calls

Multi-Turn Conversations

Include previous messages to maintain context:

Choosing a Profile

Default Profile

Once you have configured a default chat profile in the backoffice, you can call without specifying a profile:

Specific Profile

Pass the profile ID using the builder:

Or use the profile alias directly:

In This Section

Basic ChatStreamingSystem PromptsAdvanced Options

Last updated

Was this helpful?