OpenAIConfig

org.llm4s.llmconnect.config.OpenAIConfig
See theOpenAIConfig companion object
@Stable
final case class OpenAIConfig extends ProviderConfig

Configuration for the OpenAI API and providers that implement the OpenAI-compatible REST interface.

baseUrl governs which backend is contacted: "https://api.openai.com/v1" reaches OpenAI directly, while a URL containing "openrouter.ai" causes org.llm4s.llmconnect.LLMConnect to route to OpenRouter. Azure OpenAI uses AzureConfig, not this class.

This config lives in llm4s-openai-compatible, with OpenRouter, and llm4s-openai - whose OpenAI and Requesty providers build it - depends on that module for it (#1132). Its package is unchanged from when it was in llm4s-core.

Prefer OpenAIConfig.fromValues, which validates the values and resolves contextWindow and reserveCompletion from the bundled model catalogue. The constructor is private: build one with the companion apply and adjust it with the with* setters. Java and Kotlin, which cannot see Scala default arguments, use OpenAIConfig.apply(apiKey, model) and the setters, so adding a field never breaks them.

Value parameters

apiKey

OpenAI API key; redacted in toString.

baseUrl

API base URL; determines provider routing in org.llm4s.llmconnect.LLMConnect.

contextWindow

Model's total token capacity (prompt + completion combined).

explicitProviderId

the provider this config belongs to, when a descriptor says so: requesty for Requesty and openrouter for OpenRouter. None - what a config built by hand gets - infers it from baseUrl; see providerId.

model

Model identifier, e.g. "gpt-4o".

organization

Optional OpenAI organisation ID.

reserveCompletion

Tokens held back from prompt history for the completion.

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)

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

The provider this config belongs to: explicitProviderId when set, otherwise openai, or openrouter when baseUrl points at OpenRouter.

The provider this config belongs to: explicitProviderId when set, otherwise openai, or openrouter when baseUrl points at OpenRouter.

OpenAI, OpenRouter and Requesty all use this config, and LLMConnect routes a config to a client by this id. The Requesty and OpenRouter descriptors set it explicitly, so a Requesty config reports requesty - it used to report openai, because its base URL is neither OpenAI's nor OpenRouter's - and an OpenRouter section with a proxy baseUrl still reaches OpenRouter. The inference from baseUrl remains for a config built by hand and for provider = "openai", so an OpenAI section pointed at openrouter.ai reaches OpenRouter as it did before the provider registry (#1131).

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): OpenAIConfig
def withBaseUrl(baseUrl: String): OpenAIConfig
def withContextWindow(contextWindow: Int): OpenAIConfig
def withExplicitProviderId(providerId: Option[ProviderId]): OpenAIConfig
override def withModel(model: String): OpenAIConfig

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

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

Attributes

Definition Classes
def withOrganization(organization: String): OpenAIConfig
def withOrganization(organization: Option[String]): OpenAIConfig
def withReserveCompletion(reserveCompletion: Int): OpenAIConfig
override def withTimeouts(timeouts: ProviderTimeouts): OpenAIConfig

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
def withWorkloadIdentity(workloadIdentity: Option[OpenAIWorkloadIdentity]): OpenAIConfig

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product