org.llm4s.llmconnect

Members list

Type members

Classlikes

Mixin trait providing standard lifecycle management and metrics wrapping for LLMClient implementations.

Mixin trait providing standard lifecycle management and metrics wrapping for LLMClient implementations.

Tracks whether the client has been closed via an AtomicBoolean and provides:

  • validateNotClosed — a pre-check returning Left(ConfigurationError) once closed.
  • close() — an idempotent close that delegates to releaseResources() exactly once.
  • completeWithMetrics — combines lifecycle validation with metrics recording for Completion results, eliminating boilerplate in complete / streamComplete.

Concrete clients mix in this trait, supply providerName and modelName, and optionally override releaseResources() to free provider-specific resources (HTTP clients, SDK connections, etc.).

Attributes

Supertypes
trait LLMClient
trait AutoCloseable
class Object
trait Matchable
class Any
Show all
Known subtypes
class EmbeddingClient(provider: EmbeddingProvider, tracer: Option[Tracing], operation: String)

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
final case class JsonlProviderExchangeSink(path: Path) extends ProviderExchangeSink

Appends provider exchanges as JSON Lines to a local file.

Appends provider exchanges as JSON Lines to a local file.

This is intended as the first practical debugging sink for development. It creates parent directories on demand and writes one redacted JSON object per line.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
trait LLMClient extends AutoCloseable

Core interface for interacting with Large Language Model providers.

Core interface for interacting with Large Language Model providers.

Abstracts communication with various LLM APIs (OpenAI, Azure OpenAI, Anthropic, etc.), providing a unified interface for completion requests, streaming responses, and token management. Implementations handle provider-specific authentication, message formatting, and tool calling.

Attributes

Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any
Known subtypes

Stateless helper functions for retrying LLM completion and streaming calls.

Stateless helper functions for retrying LLM completion and streaming calls.

Retries only on recoverable errors (e.g. rate limit, timeout). Fails immediately on non-recoverable errors.

'''Retry delay precedence''' (honors upstream backpressure):

  • If the error provides a provider retry-delay hint (e.g. retryDelay on org.llm4s.error.RateLimitError, org.llm4s.error.ServiceError) and it is present and positive, that value is used so we do not retry before the server is ready.
  • Otherwise we fall back to local exponential backoff (baseDelay * 2^attempt) to avoid tight retry loops.
  • The chosen delay is always capped at 30 seconds so waits remain bounded.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
object LLMConnect

Constructs an LLMClient from provider configuration.

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
Supertypes
class Object
trait Matchable
class Any
Self type
LLMConnect.type
final case class LlmClientOptions(metrics: MetricsCollector, exchangeLogging: ProviderExchangeLogging)

Client-construction options for LLMConnect.

Client-construction options for LLMConnect.

This lets library users opt into runtime behaviors such as metrics and provider exchange logging without folding those concerns into org.llm4s.llmconnect.config.ProviderConfig.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
final case class ProviderExchange(exchangeId: String, provider: String, model: Option[String], requestId: Option[String], correlationId: Option[String], startedAt: Instant, completedAt: Instant, durationMs: Long, outcome: ProviderExchangeOutcome, requestBody: String, responseBody: Option[String], errorMessage: Option[String])

Minimal first-pass representation of a captured provider exchange.

Minimal first-pass representation of a captured provider exchange.

This intentionally starts small, but now carries enough timing and correlation metadata to serve as a low-level debugging record that higher level tracing or tooling can reference later.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Runtime configuration for capturing raw LLM provider exchanges.

Runtime configuration for capturing raw LLM provider exchanges.

Exchange logging is disabled by default. Applications can opt in by supplying a ProviderExchangeSink through ProviderExchangeLogging.Enabled when constructing a client.

Attributes

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Sink for completed provider exchanges.

Sink for completed provider exchanges.

Library code emits completed exchanges here when exchange logging is enabled. Sinks are deliberately simple and synchronous in the first version; callers can always wrap them later if they want batching or async behavior.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type