detectProvider

fun detectProvider(vararg candidates: ByokFactory): LlmService<*>

Concurrently attempts each candidate ByokFactory and returns the first LlmService that validates successfully. Remaining tasks are cancelled on first success.

Typical usage — sign-up flow (fan-out across all supported BYOK providers):

val service = detectProvider(
AnthropicModelFactory(apiKey = userKey),
OpenAiCompatibleModelFactory.openAi(userKey),
OpenAiCompatibleModelFactory.deepSeek(userKey),
OpenAiCompatibleModelFactory.mistral(userKey),
OpenAiCompatibleModelFactory.gemini(userKey),
)
val detectedProvider = service.provider

Typical usage — settings flow (single known provider):

val service = detectProvider(AnthropicModelFactory(apiKey = userKey))

Return

The LlmService returned by the first successful factory. Call LlmService.provider on the result to retrieve the detected provider name.

Parameters

candidates

One or more ByokFactory instances to race.

Throws

if all candidates fail or no candidates are supplied.