← Back

Verify Agents With Node.js

Overview

Use the NPM package to identify and verify legitimate AI agents, crawlers, and bots from a network request. Known Agents verifies agents using Web Bot Auth (HTTP message signatures), IP matching, or other available methods. This can be useful for implementing access policies based on verified agent identity. Please contact us if you need help getting set up.

Step 1: Install the NPM Package

Download the package from NPM using the command line.

npm install @knownagents/sdk

Step 2: Initialize the Client

In your code, create an instance of KnownAgents with your project's access token.

import { KnownAgents } from "@knownagents/sdk"
            
const knownAgents = new KnownAgents("YOUR_ACCESS_TOKEN")

Step 3: Verify an Agent Request

Use the verifyAgent function to check if a request is from a legitimate agent by passing in the incoming request object.

const verification = await knownAgents.verifyAgent(request)

if (verification.result === "verified") {
    // Agent is allowed
} else if (verification.result === "verification_failed") {
    // Agent is not allowed
}

The function returns an object with the following fields: