How to use the ClearRun CLI from Node code (scoreText, lookupVerdict)
Import scoreText and lookupVerdict from @clearrun/cli. scoreText uses the apiKey you pass in, then CLEARRUN_API_KEY, then the file saved by clearrun login.
Last updated
Applies to version 1.2.0 of @clearrun/sdk and @clearrun/cli.
Steps
Install
npm install @clearrun/cliScore text
import { scoreText } from '@clearrun/cli'; // pass { apiKey }, or it reads CLEARRUN_API_KEY, // then ~/.config/clearrun/config.json const verdict = await scoreText('The capital of France is Paris.'); console.log(verdict.score, verdict.verdictId);Look up a verdict id
import { lookupVerdict } from '@clearrun/cli'; const { verified, verdict } = await lookupVerdict('6e07586d-e028-43d6-bec3-0f4821b22ca0');
What you get
scoreText returns a short verdict: score, grade, risk, issues, summary, verdictId, timestamp, and signature when present. For the full response, including the receipt, use the SDK.
Where scoreText finds the key
- The
apiKeyoption CLEARRUN_API_KEY~/.config/clearrun/config.json, saved byclearrun login
Pass env to read a different set of variables. The clearrun score command also checks ./clearrun.config.json. scoreText doesn't.
Prefer the SDK for apps
The SDK has score, evaluate, chat and verify, mock mode, and typed errors. See How to create a ClearRun client (createKernelClient).