OpenAICompatibleConfig

org.llm4s.llmconnect.config.OpenAICompatibleConfig
See theOpenAICompatibleConfig companion object
@Stable
final case class OpenAICompatibleConfig extends ProviderConfig

Configuration for the generic openai-compatible provider: any endpoint that speaks the OpenAI /chat/completions API, such as Groq, Together, Fireworks, a vLLM, LM Studio or llama.cpp server, or an internal gateway.

Nothing is known about the model up front, so the context window and completion reserve come from config, defaulting to the conservative OpenAICompatibleConfig.DEFAULT_CONTEXT_WINDOW and OpenAICompatibleConfig.DEFAULT_RESERVE_COMPLETION. Set them to the model's real limits so context compression neither truncates early nor overflows.

Prefer OpenAICompatibleConfig.fromValues, which validates the values. The constructor is private: build one with the companion apply, whose defaults cover every field after baseUrl, and adjust it with the with* setters. Java and Kotlin, which cannot see Scala default arguments, use OpenAICompatibleConfig.apply(model, baseUrl) and the setters, so adding a field never breaks them.

Value parameters

apiKey

sent as Authorization: Bearer <key>; None sends no Authorization header, for servers that need none. Redacted in toString.

baseUrl

API base URL; requests go to <baseUrl>/chat/completions.

contextWindow

the model's total token capacity (prompt + completion).

headers

extra headers sent on every request, e.g. a gateway's own auth header. Values are redacted in toString.

model

model identifier sent in every request.

reserveCompletion

tokens held back from prompt history for the completion.

streamUsage

whether a streaming request asks for token usage with "stream_options": {"include_usage": true}. Servers that follow OpenAI (vLLM, Ollama's /v1) stream no usage without it; turn it off for an endpoint that rejects the field. A named section sets it with the streamUsage key.

timeouts

how long a request and a stream may take: the section's timeouts block. An absent value keeps the client's own default (ProviderTimeouts)

tokenExchange

workload-identity auth: the identity token is exchanged here for the bearer token, which replaces apiKey; never set together with apiKey or an Authorization entry in headers, and its tokenUrl and baseUrl must be https (plain http only to a loopback host). The exchanged token goes to baseUrl, a host the user chooses, so no host is allow-listed here. OpenAICompatibleConfig.fromValues checks these, and OpenAICompatibleClient refuses a config built any other way that breaks them.

Attributes

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

Members list

Value members

Concrete methods

override def endpointUrl: Option[String]

The endpoint this config will contact, when it is known statically.

The endpoint this config will contact, when it is known statically.

Used by policy checks and diagnostics that need to know where traffic will go without knowing which provider it belongs to. None means the config carries no single URL — not that it makes no network calls.

Attributes

Definition Classes
override def providerId: ProviderId

Canonical id of the provider this config addresses, e.g. ProviderId("openai").

Canonical id of the provider this config addresses, e.g. ProviderId("openai").

Attributes

Definition Classes
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
def withApiKey(apiKey: String): OpenAICompatibleConfig
def withApiKey(apiKey: Option[String]): OpenAICompatibleConfig
def withBaseUrl(baseUrl: String): OpenAICompatibleConfig
def withContextWindow(contextWindow: Int): OpenAICompatibleConfig
def withHeader(name: String, value: String): OpenAICompatibleConfig

Adds (or replaces) one header, for Java and Kotlin callers that would otherwise build a Scala Map.

Adds (or replaces) one header, for Java and Kotlin callers that would otherwise build a Scala Map.

Attributes

def withHeaders(headers: Map[String, String]): OpenAICompatibleConfig
override def withModel(model: String): OpenAICompatibleConfig

The same provider and credentials, pointed at a different model.

The same provider and credentials, pointed at a different model.

Attributes

Definition Classes
def withReserveCompletion(reserveCompletion: Int): OpenAICompatibleConfig
def withStreamUsage(streamUsage: Boolean): OpenAICompatibleConfig

The same config with the given timeouts.

The same config with the given timeouts.

The loader calls this on every config a descriptor builds, passing the section's timeouts block, so a descriptor does not read the block itself. The default returns this: a config that does not carry timeouts, such as one supplied by another module, ignores them. A config that does overrides this with its own return type.

Attributes

Definition Classes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product