Function: optionalCredential()
ts
function optionalCredential(key): string | undefined;Defined in: packages/core/src/credentials/credentials.ts:345
Read an optional credential at runtime.
Unlike requireCredential(), this does NOT throw when the credential is absent or empty — it returns undefined instead. Use this for non-mandatory credentials that enhance functionality when present.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The credential key as declared in defineCredentials(). |
Returns
string | undefined
The credential value, or undefined if absent/empty.
Example
ts
const appToken = optionalCredential('BEAGLE_APP_TOKEN');
if (appToken) { headers['X-App-Token'] = appToken; }