Skip to main content

Config options

Pass these to init():
OptionTypeDefaultDescription
apiKeystringrequiredYour site API key
siteIdstringSite ID (usually inferred from API key)
endpointstring'/api/v1/events'API endpoint URL
onDetection(result: DetectionOutput) => voidCallback fired on every detection update
debugbooleanfalseLog detection info to console

Detection callback

The onDetection callback fires every time the detection probability updates — which happens progressively as the SDK gathers more signals.
const toffee = init({
  apiKey: 'YOUR_API_KEY',
  endpoint: 'https://api.toffee.at',
  onDetection: (result) => {
    console.log(result.riskTier)     // 'definite-human', 'suspicious', 'likely-bot', etc.
    console.log(result.probability)  // 0.0 – 1.0
    console.log(result.isAgent)      // true if probability >= 0.50

    if (result.riskTier === 'likely-bot' || result.riskTier === 'definite-bot') {
      // show captcha, block form submission, rate-limit, etc.
    }
  },
})
The callback receives a DetectionOutput object. See the detection page for how risk tiers work and the reference for the full type definition.

Debug mode

Enable debug: true to log detection results to the browser console. Useful during integration:
const toffee = init({
  apiKey: 'YOUR_API_KEY',
  endpoint: 'https://api.toffee.at',
  debug: true,
})