LLMConnect

org.llm4s.llmconnect.LLMConnect
object LLMConnect

Constructs an LLMClient from provider configuration.

Provider selection is determined entirely by the runtime type of the ProviderConfig supplied: an AnthropicConfig produces an Anthropic client, an OpenAIConfig produces an OpenAI or OpenRouter client (the latter when baseUrl contains "openrouter.ai"), and so on. Azure uses OpenAIClient internally — AzureConfig carries the deployment endpoint and API-version fields that OpenAI does not require.

Attributes

See also

org.llm4s.config.Llm4sConfig.provider to load configuration from environment variables

LLMClient for the conversation and completion API

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

Members list

Value members

Concrete methods

Constructs an LLMClient, routing to the correct provider based on the runtime type of config and recording call statistics to metrics.

Constructs an LLMClient, routing to the correct provider based on the runtime type of config and recording call statistics to metrics.

The dispatch is exhaustive — every ProviderConfig subtype is handled. Returns Left only if the underlying client constructor fails (for example, if the HTTP client library throws during initialisation).

Value parameters

config

Provider configuration; the concrete subtype determines which client is built. 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; the concrete subtype determines which client is built.

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 expected provider; must match the runtime type of config.

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 expected provider; must match the runtime type of config.

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.