OpenAIConfig

org.llm4s.llmconnect.config.OpenAIConfig
See theOpenAIConfig companion object
case class OpenAIConfig(apiKey: String, model: String, organization: Option[String], baseUrl: String, contextWindow: Int, reserveCompletion: Int) 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.

Prefer OpenAIConfig.fromValues over the primary constructor; it resolves contextWindow and reserveCompletion from the model name automatically.

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

model

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

organization

Optional OpenAI organisation ID.

reserveCompletion

Tokens held back from prompt history for the completion.

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

openai, or openrouter when baseUrl points at OpenRouter.

openai, or openrouter when baseUrl points at OpenRouter.

OpenRouter reuses this config but has its own client, and the base URL is the only thing distinguishing the two. Deriving the id here keeps that knowledge with the config rather than in a special case inside org.llm4s.llmconnect.LLMConnect, which is how routing worked 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
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

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product