LLMConnect

org.llm4s.llmconnect.LLMConnect
object LLMConnect

Constructs an LLMClient from provider configuration.

Which client is built is decided by the org.llm4s.llmconnect.spi.ProviderRegistry: the config names a provider through org.llm4s.llmconnect.config.ProviderConfig.providerId, and that provider's org.llm4s.llmconnect.spi.ProviderDescriptor builds its own client. LLMConnect itself knows no provider names, so a provider supplied by another module is reached the same way a built-in one is.

Pass a different registry with using to resolve against a custom set of providers; with none in scope, org.llm4s.llmconnect.spi.ProviderRegistry.default is used.

Attributes

See also

org.llm4s.config.Llm4sConfig.defaultProvider to load the configured default named provider

LLMClient for the conversation and completion API

Example
for {
 registry <- Llm4sConfig.modelRegistryService()
 cfg      <- Llm4sConfig.defaultProvider()
 client   <- LLMConnect.getClient(cfg)(using registry)
} yield client
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
LLMConnect.type

Members list

Value members

Concrete methods

Constructs an LLMClient for the provider config names, recording call statistics to metrics.

Constructs an LLMClient for the provider config names, recording call statistics to metrics.

A config whose provider is not registered yields a org.llm4s.error.ConfigurationError listing the providers that are; Left is also returned if the underlying client constructor fails (for example, if the HTTP client library throws during initialisation).

Value parameters

config

Provider configuration; its providerId selects the client. For OpenRouter, supply an OpenAIConfig whose baseUrl contains "openrouter.ai".

metrics

Receives per-call latency and token-usage events. Use org.llm4s.metrics.MetricsCollector.noop when no metrics backend is needed.

Attributes

Constructs an LLMClient using explicit runtime options.

Constructs an LLMClient using explicit runtime options.

This is the preferred extension point for optional client behaviors such as metrics collection and provider exchange logging.

Attributes

Constructs an LLMClient without recording call statistics.

Constructs an LLMClient without recording call statistics.

Suitable for applications that do not integrate with a metrics backend. Switch to the two-argument overload when per-call latency or token-usage data is needed (e.g. for Prometheus or Micrometer).

Value parameters

config

Provider configuration; its providerId selects the client.

Attributes

Constructs an LLMClient, verifying at runtime that provider and config are consistent with each other.

Constructs an LLMClient, verifying at runtime that provider and config are consistent with each other.

Returns Left in two situations: the provider/config pair is mismatched (yields a org.llm4s.error.ConfigurationError), or the underlying client constructor fails during initialisation. Use this overload when the provider is resolved dynamically from user input or external config and you want an explicit error on mismatch rather than silent wrong routing.

Value parameters

config

Provider configuration corresponding to provider.

metrics

Receives per-call latency and token-usage events. Use org.llm4s.metrics.MetricsCollector.noop when no metrics backend is needed.

provider

The provider to build; config must be the config type it expects.

Attributes

Returns

the constructed client, or a org.llm4s.error.ConfigurationError when provider and config describe different providers, or an org.llm4s.error.UnknownError if client initialisation throws.

Constructs an LLMClient, verifying provider/config consistency, using explicit runtime options.

Constructs an LLMClient, verifying provider/config consistency, using explicit runtime options.

Attributes

Constructs an LLMClient, verifying provider/config consistency, without recording call statistics.

Constructs an LLMClient, verifying provider/config consistency, without recording call statistics.

Value parameters

config

Provider configuration corresponding to provider.

provider

The provider to build; config must be the config type it expects.

Attributes

Returns

the constructed client, or a org.llm4s.error.ConfigurationError when provider and config describe different providers, or an org.llm4s.error.UnknownError if client initialisation throws.