LlmGateway

interface LlmGateway

Provider-agnostic LLM gateway.

One interface per provider implementation lives in its own Gradle module (e.g. mojentic-ollama). Gateways are thin Ktor-Client wrappers — they translate between provider HTTP APIs and Mojentic's neutral types. No business logic lives in a gateway.

All methods are suspend or return a Flow. Cancellation of the calling coroutine propagates to the underlying HTTP request.

Functions

Link copied to clipboard
abstract suspend fun availableModels(): List<String>

List models the provider currently advertises.

Link copied to clipboard
abstract suspend fun complete(model: String, messages: List<LlmMessage>, tools: List<LlmTool>? = null, config: CompletionConfig = CompletionConfig()): LlmGatewayResponse

Single-shot completion.

Link copied to clipboard
abstract suspend fun completeJson(model: String, messages: List<LlmMessage>, schema: JsonObject, config: CompletionConfig = CompletionConfig()): JsonObject

Structured-output completion. The provider is instructed to return a JSON object matching schema.

Link copied to clipboard
open suspend fun completeJsonResponse(model: String, messages: List<LlmMessage>, schema: JsonObject, config: CompletionConfig = CompletionConfig()): LlmGatewayResponse

Structured-output completion that also returns provider evidence.

Link copied to clipboard
abstract fun stream(model: String, messages: List<LlmMessage>, tools: List<LlmTool>? = null, config: CompletionConfig = CompletionConfig()): Flow<GatewayStreamEvent>

Streaming completion. Returns a cold Flow that emits one GatewayStreamEvent per chunk. Cancellation tears down the HTTP request.