AbstractOpenAILLMClient

abstract class AbstractOpenAILLMClient<TResponse : OpenAIBaseLLMResponse, TStreamResponse : OpenAIBaseLLMStreamResponse>(settings: OpenAIBaseSettings, httpClient: KoogHttpClient, clock: KoogClock = KoogClock.System, logger: KLogger, toolsConverter: OpenAICompatibleToolDescriptorSchemaGenerator) : LLMClient(source)

Abstract base class for OpenAI-compatible LLM clients. Provides common functionality for communicating with OpenAI and OpenAI-compatible APIs.

Parameters

settings

Configuration settings including base URL, API paths, and timeout configuration.

httpClient

A fully configured KoogHttpClient for making API requests. Must have authentication and other request defaults (base URL, timeouts, headers) already embedded. To use a factory-backed client with standard OpenAI-compatible defaults, use the secondary constructor that accepts a KoogHttpClient.Factory and an API key.

clock

KoogClock used for tracking response metadata timestamps. Defaults to KoogClock.System.

Constructors

Link copied to clipboard
constructor(settings: OpenAIBaseSettings, httpClient: KoogHttpClient, clock: KoogClock = KoogClock.System, logger: KLogger, toolsConverter: OpenAICompatibleToolDescriptorSchemaGenerator)
constructor(apiKey: String, settings: OpenAIBaseSettings, httpClientFactory: KoogHttpClient.Factory, clientName: String, clock: KoogClock = KoogClock.System, logger: KLogger, toolsConverter: OpenAICompatibleToolDescriptorSchemaGenerator)

Secondary constructor for creating a client backed by a KoogHttpClient.Factory. Configures authentication, base URL, timeouts, and JSON serialization automatically from apiKey and settings.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val clientName: String

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open suspend fun embed(text: String, model: LLModel): List<Double>
open suspend fun embed(inputs: List<String>, model: LLModel): List<List<Double>>
Link copied to clipboard
open suspend override fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): Message.Assistant
Link copied to clipboard
open suspend override fun executeMultipleChoices(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<Message.Assistant>
Link copied to clipboard
open fun executeStreaming(prompt: Prompt, model: LLModel): Flow<StreamFrame>
open override fun executeStreaming(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): Flow<StreamFrame>
Link copied to clipboard
abstract fun llmProvider(): LLMProvider
Link copied to clipboard
open suspend fun models(): List<LLModel>
Link copied to clipboard
abstract suspend fun moderate(prompt: Prompt, model: LLModel): ModerationResult