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.
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".
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.
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.