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

  1. Install

    npm install @clearrun/cli
  2. Score 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);
  3. 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

  1. The apiKey option
  2. CLEARRUN_API_KEY
  3. ~/.config/clearrun/config.json, saved by clearrun 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).