verifyApiKey

View as MarkdownOpen in Claude

Verify an API key against the configured key. Uses a constant-time comparison to prevent timing attacks. Returns false immediately when API key auth is not configured.

Pass only the key value — this method does not parse headers. For full header-based validation (which reads the configured apiKeyHeader, case- insensitive), use validate().

Parameters

key
stringRequired

The API key string to verify.

Returns

booleantrue if the key matches; false if it doesn’t, or if API key auth was not configured.

Example

import { AuthHandler } from '@signalwire/sdk';
const auth = new AuthHandler({
apiKey: 'sk_live_abc123',
apiKeyHeader: 'X-Api-Key',
});
function authorize(headerValue: string | undefined) {
if (!headerValue) return false;
return auth.verifyApiKey(headerValue);
}