ChatClient

interface ChatClient

Provider-agnostic contract for chat-based LLM clients.

Implementations of this interface handle communication with a specific LLM provider (e.g. OpenAI, Ollama, Groq) while exposing a unified API for sending messages, streaming responses, and listing available models.

Three overloads are provided for both blocking and streaming chat:

Functions

Link copied to clipboard
abstract suspend fun chat(request: ChatRequest): ChatResponse

Sends a chat request to the LLM provider and returns a non-streaming response.

abstract suspend fun chat(block: ChatRequestBuilder.() -> Unit): ChatResponse

Sends a chat using full DSL configuration.

abstract suspend fun chat(model: String, blocks: ChatBuilder.() -> Unit): ChatResponse

Sends a chat using DSL-style message construction.

Link copied to clipboard

Sends a chat request and wraps the result in a Result.

inline suspend fun ChatClient.chatCatching(noinline request: ChatRequestBuilder.() -> Unit): Result<ChatResponse>

Sends a chat request using the request DSL and wraps the result in a Result.

inline suspend fun ChatClient.chatCatching(model: String, noinline chat: ChatBuilder.() -> Unit): Result<ChatResponse>

Sends a chat request using the message DSL and wraps the result in a Result.

Link copied to clipboard
abstract fun chatStream(request: ChatRequest): Flow<ChatChunk>

Streams a chat request, returning chunks as they arrive.

abstract fun chatStream(block: ChatRequestBuilder.() -> Unit): Flow<ChatChunk>

Streams a chat using full DSL configuration.

abstract fun chatStream(model: String, blocks: ChatBuilder.() -> Unit): Flow<ChatChunk>

Streams a chat using DSL-style message construction.

Link copied to clipboard
abstract suspend fun listModels(): List<Model>

Lists all available models from the provider.