HttpChatProvider

class HttpChatProvider(httpConfig: HttpChatConfig, engine: HttpClientEngine = httpClientEngine()) : AiProvider(source)

AiProvider over a caller-supplied HTTP endpoint speaking the same data: <json> / data: [DONE] SSE contract as AnthropicProvider/OpenAiProvider/GeminiProvider — the shape cv-siddharth-kmp and Candidai were each hand-rolling their own parser for. Every reply frame decodes as HttpChatStreamEvent; the backend is expected to emit {"text":"..."} per token and close the stream (optionally preceded by a data: [DONE] line, discarded rather than decoded) rather than any vendor-specific event shape. See HttpChatConfig.requireDoneSentinel for a backend whose [DONE] isn't actually optional.

Request body: {"messages":[{"role":"user"|"assistant","content":"..."}],"system"?,"mode"?, "route"?,"maxTokens","temperature"}. system, mode and route are each omitted entirely when absent (explicitNulls = false on the request's Json) rather than sent as "system": null / "mode": null / "route": null — required for a backend that validates mode against a closed allowlist and would 400 a literal null.

Constructors

Link copied to clipboard
constructor(httpConfig: HttpChatConfig, engine: HttpClientEngine = httpClientEngine())

Properties

Link copied to clipboard
open override val displayName: String
Link copied to clipboard
open override val id: String

Functions

Link copied to clipboard
open suspend override fun capabilities(): AiCapabilities

Honest self-report for a capability-aware caller: whether this backend genuinely streams tokens and accepts images, which AiConfig fields it actually reads, and — when it can't run — the real AiFailure reason instead of a bare false. Default answer is conservative (no streaming, no honored config) and blames a missing key, matching every real provider's own isAvailable gate; a provider whose unavailability means something else overrides this.

Link copied to clipboard
open suspend override fun complete(messages: List<AiMessage>, config: AiConfig = AiConfig()): AiResult<String>

No separate HTTP call of its own — collects completeStream under AiConfig.timeoutMs and joins its tokens. One call site for the wire contract instead of a second copy of the request/ response handling that completeStream already has right.

Link copied to clipboard
suspend fun AiProvider.completeOrBlank(messages: List<AiMessage>, config: AiConfig = AiConfig()): String

Bridge for callers not yet migrated off the pre-AiResult complete(): collapses every AiFailure back to "", matching the old runCatching { }.getOrElse { "" } behavior.

Link copied to clipboard
open override fun completeStream(messages: List<AiMessage>, config: AiConfig = AiConfig()): Flow<AiChunk>

Token-by-token variant of complete — so a UI can render the reply as it arrives and a Stop action actually cancels the in-flight request (cancelling the collecting coroutine tears down the underlying HTTP call) instead of leaving it running to completion in the background.

Link copied to clipboard
open suspend override fun isAvailable(): Boolean