Whenever a setting can come from multiple sources (explicit per-call config, provider-level overrides, suite/global env, specific env vars, or built-in defaults), the precedence order must be explicit, documented, and verified end-to-end — never silently dropped or confused with a built-in default.
Key practices:
OPENAI_MAX_TOKENS=73 is set, a provider must still forward 73 even if it falls into a “modern model” branch that normally omits the field for defaults — only the synthetic default should be omitted, not a user-supplied value.env folded into providerOptions.env) accidentally rank below a layer that is supposed to be lower priority.numberOfResults convenience field vs. a complete retrieveAndGenerateConfiguration), the more specific/explicit configuration must win, and this must be documented in code comments and user docs.loadApiProvider, not just a direct constructor call) so that merge/precedence behavior is verified the way it will actually run in production.Example of the problem to avoid:
// BAD: drops an explicit user-set env var together with the injected default
maxTokens: assumeModernModel ? undefined : maxTokensDefault,
// GOOD: only omit the synthetic default; keep an explicitly configured value
maxTokens: assumeModernModel
? getEnvInt('OPENAI_MAX_TOKENS') // explicit override still respected
: maxTokensDefault,