OpenAIConfig

org.llm4s.llmconnect.config.OpenAIConfig
See theOpenAIConfig companion class
object OpenAIConfig

Attributes

Companion
class
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type

Members list

Type members

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
type MirroredLabel <: String

The name of the type

The name of the type

Attributes

Inherited from:
Mirror

Value members

Concrete methods

def apply(apiKey: String, model: String, organization: Option[String], baseUrl: String, contextWindow: Int, reserveCompletion: Int, explicitProviderId: Option[ProviderId], workloadIdentity: Option[OpenAIWorkloadIdentity]): OpenAIConfig

Builds a config without validating it; fromValues validates, and OpenAIClient applies validate to whatever it is given. explicitProviderId defaults to None, which infers the provider from baseUrl; workloadIdentity defaults to None, which authenticates with apiKey.

Builds a config without validating it; fromValues validates, and OpenAIClient applies validate to whatever it is given. explicitProviderId defaults to None, which infers the provider from baseUrl; workloadIdentity defaults to None, which authenticates with apiKey.

Attributes

def apply(apiKey: String, model: String): OpenAIConfig

The API key and model, every other field at its default: the entry point for Java and Kotlin, which do not see Scala default arguments. The base URL is DEFAULT_BASE_URL, there is no organisation, and contextWindow and reserveCompletion come from the model name alone (gpt-4o is 128k, an unknown model 8192); set them, and the rest, with the with* setters, or use fromValues to consult the bundled model catalogue.

The API key and model, every other field at its default: the entry point for Java and Kotlin, which do not see Scala default arguments. The base URL is DEFAULT_BASE_URL, there is no organisation, and contextWindow and reserveCompletion come from the model name alone (gpt-4o is 128k, an unknown model 8192); set them, and the rest, with the with* setters, or use fromValues to consult the bundled model catalogue.

Attributes

def fromValues(modelName: String, apiKey: String, organization: Option[String], baseUrl: String, providerId: Option[ProviderId], workloadIdentity: Option[OpenAIWorkloadIdentity])(using resolver: ContextWindowResolver): Result[OpenAIConfig]

Constructs an OpenAIConfig, resolving contextWindow and reserveCompletion from the model name automatically.

Constructs an OpenAIConfig, resolving contextWindow and reserveCompletion from the model name automatically.

The resolver first consults a bundled model-metadata catalogue; if the model is not listed there it falls back to name-pattern matching before defaulting to 8192 tokens. Prefer this factory over the primary constructor so that new models receive correct context-window values without manual lookup.

Value parameters

apiKey

OpenAI API key; must be non-empty, except that it is empty exactly when workloadIdentity is set.

baseUrl

API base URL; must be non-empty. Pass a URL containing "openrouter.ai" to route through OpenRouter.

modelName

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

organization

Optional OpenAI organisation ID.

providerId

the provider the config belongs to, e.g. ProviderId("requesty"); None infers it from baseUrl, as OpenAIConfig.providerId describes.

workloadIdentity

OpenAI workload identity federation instead of apiKey; only for a config belonging to openai whose baseUrl is an OpenAI API host (https://api.openai.com/v1 or a data-residency region such as https://eu.api.openai.com/v1).

Attributes

Returns

Left(ConfigurationError) for a blank field or a config validate refuses.

Concrete fields

val DEFAULT_BASE_URL: String

The OpenAI API base URL, used by the short apply(apiKey, model).

The OpenAI API base URL, used by the short apply(apiKey, model).

Attributes

The declaration of OrganizationKey each of those providers lists in its ProviderConfigSpec.extras.

The declaration of OrganizationKey each of those providers lists in its ProviderConfigSpec.extras.

Attributes

val OrganizationKey: String

The provider-specific key naming the OpenAI organisation ID, organization.

The provider-specific key naming the OpenAI organisation ID, organization.

It was a field of NamedProviderConfig that every provider carried; it is now declared only by the providers that build an OpenAIConfig - OpenAI, Requesty and OpenRouter - and read with section.extra(OrganizationKey) (#1133).

Attributes