OpenRouterLLMClient

class OpenRouterLLMClient @JvmOverloads constructor(settings: OpenRouterClientSettings = OpenRouterClientSettings(), httpClient: KoogHttpClient, clock: Clock = Clock.System, toolsConverter: OpenAICompatibleToolDescriptorSchemaGenerator = OpenAICompatibleToolDescriptorSchemaGenerator()) : AbstractOpenAILLMClient<OpenRouterChatCompletionResponse, OpenRouterChatCompletionStreamResponse> (source)

Implementation of LLMClient for OpenRouter API. OpenRouter is an API that routes requests to multiple LLM providers.

Parameters

settings

The base URL and timeouts for the OpenRouter API, defaults to "https://openrouter.ai" and 900s

httpClient

A fully configured KoogHttpClient for making API requests. Use the secondary constructor to create a Ktor-backed client configured with an API key.

clock

Clock instance used for tracking response metadata timestamps.

Constructors

Link copied to clipboard
constructor(settings: OpenRouterClientSettings = OpenRouterClientSettings(), httpClient: KoogHttpClient, clock: Clock = Clock.System, toolsConverter: OpenAICompatibleToolDescriptorSchemaGenerator = OpenAICompatibleToolDescriptorSchemaGenerator())
constructor(apiKey: String, settings: OpenRouterClientSettings = OpenRouterClientSettings(), baseClient: HttpClient = HttpClient(), clock: Clock = Clock.System, toolsConverter: OpenAICompatibleToolDescriptorSchemaGenerator = OpenAICompatibleToolDescriptorSchemaGenerator())

Properties

Link copied to clipboard
open override val clientName: String

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open suspend override fun embed(text: String, model: LLModel): List<Double>

Embeds the given text using the OpenRouter embeddings API.

open suspend override fun embed(inputs: List<String>, model: LLModel): List<List<Double>>

Batch embedding is not supported by the OpenRouter API.

Link copied to clipboard
open suspend override fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<Message.Response>
Link copied to clipboard
open suspend override fun executeMultipleChoices(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<LLMChoice>
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
open override fun llmProvider(): LLMProvider

Returns the specific implementation of the LLMProvider associated with this client.

Link copied to clipboard
open suspend override fun models(): List<LLModel>

Fetches the list of available models from the OpenRouter service. https://openrouter.ai/docs/api/api-reference/models/get-models

Link copied to clipboard
open suspend override fun moderate(prompt: Prompt, model: LLModel): ModerationResult