Skip to main content

Function: getDefaultApiKey()

getDefaultApiKey(provider): string | undefined

Defined in: packages/core/src/providers/api-keys.ts:145

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.

Parameters​

provider​

string

Returns​

string | undefined

Example​

import { getDefaultApiKey } from '@baleybots/core';

const key = getDefaultApiKey('openai');
if (!key) throw new Error('OpenAI API key not configured');