What is MissingApiKeyError?
MissingApiKeyError means the SDK found no API key. The first score, evaluate or chat call rejects with it when no key is set and you did not ask for mock mode. Creating the client does not throw, and verify, forceMock and mock need no key. Its code is MISSING_API_KEY.
Last updated
Applies to version 1.2.0 of @clearrun/sdk and @clearrun/cli.
Where the SDK looks
hosted.apiKeyCLEARRUN_API_KEY- The file saved by
clearrun login(~/.config/clearrun/config.json)
Fix
- Set
CLEARRUN_API_KEY, or passhosted.apiKey. - Or run
npx @clearrun/cli loginonce on that computer. - For tests, use
createKernelClient({ forceMock: true }).
Catch it
import { MissingApiKeyError } from '@clearrun/sdk';
const client = createKernelClient();
try {
await client.score({ responseText });
} catch (err) {
if (err instanceof MissingApiKeyError) console.error(err.message);
}