Function: getDefaultApiKey()
getDefaultApiKey(
provider):string|undefined
Defined in: packages/core/src/providers/api-keys.ts:185
Get the default API key for a provider.
Resolution order: programmatically-set keys (via setDefaultApiKey /
setDefaultApiKeys) first, then environment variables via the env key
registry (supports ordered fallbacks — first non-empty wins).
Part of the supported public API surface (see codegen-exports.keep.json).
Consumers use this to check whether a key is configured before constructing
a model, or to read the resolved key for proxy/UI flows. Internally, core
calls this from getMergedProviderConfig, Baleybot, and listen to fill
in apiKey when none was supplied explicitly — which is why it is exported
even though most call sites are inside core.
Parameters
provider
string
Provider name (e.g. 'openai', 'anthropic', 'google').
Returns
string | undefined
The resolved key, or undefined if none is set.
Example
import { getDefaultApiKey } from '@baleybots/core';
const key = getDefaultApiKey('openai');
if (!key) throw new Error('OpenAI API key not configured');