OpenAICompatibleProvider

org.llm4s.llmconnect.provider.OpenAICompatibleProvider

Registration for the generic openai-compatible provider: any endpoint speaking the OpenAI /chat/completions API, with no module and no code.

A named provider section with provider = "openai-compatible" needs a baseUrl and a model; apiKey and headers are optional (local servers need no key). It also accepts four provider-specific keys: contextWindow and reserveCompletion (whole numbers; the model's window cannot be known from an arbitrary endpoint, so these default to org.llm4s.llmconnect.config.OpenAICompatibleConfig.DEFAULT_CONTEXT_WINDOW and a quarter of the window up to org.llm4s.llmconnect.config.OpenAICompatibleConfig.DEFAULT_RESERVE_COMPLETION), registryProvider, and streamUsage (default true), which controls whether a streaming request asks for token usage with stream_options.include_usage; set it to false for a server that rejects that field.

'''Where the context window comes from.''' In this order: the section's contextWindow; else the model registry's entry for model under the registryProvider the section names (groq, together_ai, fireworks_ai, xai, perplexity, ...); else, when the section names none, the entry under the provider inferred from the baseUrl host; else the default. An explicit registryProvider is an instruction, so it switches the inference off. The host is inferred only by an exact match on the URL's host (api.groq.com, api.together.xyz, api.together.ai, api.fireworks.ai, api.x.ai, api.perplexity.ai), never by a substring, so a look-alike host such as api.groq.com.evil.example gets no registry window. Only the window is taken from the registry: reserveCompletion keeps its own rule (a quarter of the window, up to 2048) because a registry entry's output limit can be as large as the whole window. The lookup is strict - only the named provider's own entry for exactly that model id counts, never a substring match or another provider's entry for the same name - and a model the registry does not know, or lists with no input limit, gets the default. A registry window below the default is ignored too: many entries (most of Fireworks' older and newer models, Perplexity's retired ones) carry a 4096 placeholder for input, output and total alike, which would shrink an 80k-context model's prompt budget below the default and reject a reserveCompletion that fits it. The registry can therefore only enlarge the window, never shrink it; a model whose window really is smaller sets contextWindow. Several sections can use it side by side:

llm4s.providers {
 databricks {
   provider = "openai-compatible"
   baseUrl  = "https://ws.cloud.databricks.com/serving-endpoints"
   model    = "databricks-meta-llama-3-3-70b-instruct"
   auth {   // workload identity: no apiKey
     identityTokenFile = "/var/run/secrets/spiffe/svid.jwt"
     tokenUrl          = "https://ws.cloud.databricks.com/oidc/v1/token"
     clientId          = "<service principal UUID>"
     scope             = "all-apis"
   }
 }
 groq-main {
   provider = "openai-compatible"
   baseUrl  = "https://api.groq.com/openai/v1"
   model    = "openai/gpt-oss-120b"
   apiKey   = ${?GROQ_API_KEY}
   contextWindow = 131072
 }
 local-vllm {
   provider = "openai-compatible"
   baseUrl  = "http://localhost:8000/v1"
   model    = "Qwen/Qwen2.5-7B-Instruct"
 }
}

The client is OpenAICompatibleClient with the standard dialect: no reasoning parameters and no provider-specific decoding. A provider that needs those gets its own OpenAICompatibleDialect and descriptor in this module.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

Constructs the client for a ProviderConfig this provider produced.

Constructs the client for a ProviderConfig this provider produced.

config is whatever the caller passed, so implementations must check the type rather than cast — ProviderDescriptor.expectConfig does that and produces the standard mismatch error.

Attributes

def buildConfig(providerName: String, section: NamedProviderConfig)(using ContextWindowResolver): Result[ProviderConfig]

Turns a validated config section into the runtime ProviderConfig for this provider.

Turns a validated config section into the runtime ProviderConfig for this provider.

The section has already been checked against configSpec, so required fields are present and section.extras holds exactly the declared provider-specific keys that have a value (defaults applied, deprecated aliases resolved). A Left here means something configSpec cannot express (a malformed value, say).

Value parameters

providerName

the user's instance name (llm4s.providers.<name>), for error messages.

Attributes

Inherited methods

def aliases: Set[String]

Alternative spellings accepted in provider = "...", folded onto id.

Alternative spellings accepted in provider = "...", folded onto id.

For example Gemini accepts "google". Aliases are matched after the same trim/lowercase canonicalisation as id itself.

Attributes

Inherited from:
ProviderDescriptor

What this provider's client implements. Defaults to the full interface.

What this provider's client implements. Defaults to the full interface.

Attributes

Inherited from:
ProviderDescriptor

Concrete fields

val ContextWindowKey: String

The key giving the model's context window. It was a field of NamedProviderConfig, read by this provider alone, until #1133.

The key giving the model's context window. It was a field of NamedProviderConfig, read by this provider alone, until #1133.

Attributes

val RegistryProviderKey: String

The key naming the model registry provider (groq, together_ai, fireworks_ai, xai, perplexity, ...) whose entry for model supplies the context window when contextWindow is not set. Without it the provider is inferred from the baseUrl host for the hosts in RegistryHosts; with it, no inference happens.

The key naming the model registry provider (groq, together_ai, fireworks_ai, xai, perplexity, ...) whose entry for model supplies the context window when contextWindow is not set. Without it the provider is inferred from the baseUrl host for the hosts in RegistryHosts; with it, no inference happens.

Attributes

val ReserveCompletionKey: String

The key giving the tokens held back for the reply; a field of NamedProviderConfig until #1133.

The key giving the tokens held back for the reply; a field of NamedProviderConfig until #1133.

Attributes

val StreamUsageKey: String

The key that turns stream_options.include_usage off for a server that rejects it.

The key that turns stream_options.include_usage off for a server that rejects it.

Attributes

Which config fields this provider requires, its default endpoint, and the provider-specific keys (ProviderConfigSpec.extras) its section accepts.

Which config fields this provider requires, its default endpoint, and the provider-specific keys (ProviderConfigSpec.extras) its section accepts.

Attributes

val id: ProviderId

Canonical id, e.g. ProviderId("openai"). Must be unique within a registry.

Canonical id, e.g. ProviderId("openai"). Must be unique within a registry.

Attributes

override val modelLister: Option[ProviderModelLister]

Live model discovery, when the provider's API offers it.

Live model discovery, when the provider's API offers it.

Attributes