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