Verifying Agents (Service)

Protect your API by verifying agent requests against the on-chain registry

This guide shows how to add Self Agent ID verification to your API. After setup, only registered, human-backed agents can access your protected endpoints.

1. Install the SDK

npm install @selfxyz/agent-sdk    # TypeScript
pip install selfxyz-agent-sdk      # Python
cargo add self-agent-sdk           # Rust

2. Create a Verifier

Use the builder pattern to configure verification policy:

import { SelfAgentVerifier } from "@selfxyz/agent-sdk";

const verifier = SelfAgentVerifier.create()
  .network("mainnet")
  .requireAge(18)
  .requireOFAC()
  .requireSelfProvider()   // Ensure Self Protocol proofs (default: true)
  .sybilLimit(3)           // Max 3 agents per human
  .rateLimit({ perMinute: 10 })
  .build();

Builder Options

Method
Description
Default

.network(name)

"mainnet" or "testnet"

"testnet"

.requireAge(n)

Minimum age (18 or 21)

None

.requireOFAC()

OFAC sanctions screening

Off

.requireNationality(...codes)

Allowed ISO country codes

Any

.requireSelfProvider()

Require Self Protocol proofs

true

.sybilLimit(n)

Max agents per human (0 = unlimited)

1

.rateLimit(config)

Per-agent rate limiting

None

.replayProtection(enabled?)

Signature replay detection

true

.includeCredentials()

Attach credentials to request

false

.maxAge(ms)

Max signature age

300000 (5 min)

.cacheTtl(ms)

On-chain query cache

60000 (1 min)

3. Add Middleware

4. Request Shape After Verification

After successful verification, req.agent (or equivalent) contains:

Field
Type
Description

address

string

Agent's Ethereum address

agentId

number

On-chain NFT token ID

agentKey

string

Derived bytes32 key

isVerified

boolean

On-chain verification status

proofProvider

string

Provider contract address

credentials

object

ZK-attested credentials (if includeCredentials())

5. Credential-Based Access Control

Use credentials to gate by age, OFAC status, or nationality:

6. Sybil Resistance

Control how many agents one human can use against your API:

Setting
Behavior

.sybilLimit(1)

Strict — one agent per human (default)

.sybilLimit(5)

Moderate — up to 5 agents per human

.sybilLimit(0)

Detection only — unlimited, but sameHuman() available

The verifier checks getAgentCountForHuman(nullifier) on-chain.

7. Provider Verification

triangle-exclamation

The verifier checks that getProofProvider(agentId) matches Self Protocol's provider address.

8. Replay Protection + Rate Limiting

Replay protection (enabled by default):

  • Caches {signature + timestamp} hashes (10,000 entries)

  • Same signature cannot be used twice

Rate limiting (optional):

Per-agent sliding-window rate limits.

9. Error Handling

The middleware returns standard HTTP errors:

Status
Meaning

401

Missing or invalid signature headers

403

Agent not verified, failed policy check, or rate limited

500

On-chain query failed

Handle these in your client:

Next Steps

Last updated