Skip to content

Captcha generate

FREE with proof-of-workor $0.001 in USDCPOST /api/captcha-generate

Mint a stateless captcha challenge to gate your OWN endpoint: returns a human prompt plus a salted sha256 answer hash you keep and verify later (sha256(salt + normalized answer) === answerHash)...

Category: API primitivesTags: captcha challenge bot-protection verification signup gate anti-abuse

Try in playground →

Details

Mint a stateless captcha challenge to gate your OWN endpoint: returns a human prompt plus a salted sha256 answer hash you keep and verify later (sha256(salt + normalized answer) === answerHash) - no server state, no shared secret. Types: math (arithmetic) or alnum (character code), difficulty 1–3. Deterministic tooling for running bot protection, not defeating it.

Parameters

NameTypeRequiredDescription
typestringnomath | alnum (default math) The example sends math.
difficultyintegerno1–3 (default 1) The example sends 1.

Free call, no wallet

Fetch a challenge, solve its sha256 puzzle (16 leading zero bits), resend with X-Pow-Solution.

import { createHash } from "node:crypto";
const lz = (b) => { let t = 0; for (const x of b) { if (!x) { t += 8; continue; } t += Math.clz32(x) - 24; break; } return t; };
const c = await (await fetch("https://agent402.tools/api/pow/challenge?slug=captcha-generate")).json();
let n = 0;
while (lz(createHash("sha256").update(c.challenge + ":" + n).digest()) < c.difficulty) n++;
await fetch("https://agent402.tools/api/captcha-generate", { method: "POST", headers: { "X-Pow-Solution": c.token + ":" + n, "Content-Type": "application/json" }, body: JSON.stringify({"type":"math","difficulty":1}) });

Python:

import hashlib, json, urllib.request

def zero_bits(digest):
    n = 0
    for b in digest:
        if b:
            return n + 8 - b.bit_length()
        n += 8
    return n

c = json.load(urllib.request.urlopen("https://agent402.tools/api/pow/challenge?slug=captcha-generate"))
n = 0
while zero_bits(hashlib.sha256(f"{c['challenge']}:{n}".encode()).digest()) < c["difficulty"]:
    n += 1
req = urllib.request.Request("https://agent402.tools/api/captcha-generate", method="POST", data="{\"type\":\"math\",\"difficulty\":1}".encode(), headers={"X-Pow-Solution": f"{c['token']}:{n}", "Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(req)))

Example request

curl -i -X POST https://agent402.tools/api/captcha-generate \
  -H "Content-Type: application/json" \
  -d '{"type":"math","difficulty":1}'

Watch a call get paid

RequestPOST /api/captcha-generate
402$0.001 USDC
SignPAYMENT-SIGNATURE
Settleon 14 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

Example response

{
  "type": "math",
  "prompt": "What is 3 + 4?",
  "salt": "…",
  "answerHash": "…",
  "algo": "sha256",
  "verify": "sha256(salt + answer.trim().toLowerCase().replace(/\\s+/g,'')) === answerHash"
}
FieldTypeAlways presentIn the example
typestringyesmath
promptstringyesWhat is 3 + 4?
saltstringyes…
answerHashstringyes…
algostringyessha256
verifystringyessha256(salt + answer.trim().toLowerCase().replace(/\s+/g,'')) === answerHash

From an MCP client

catalog.call {
  "slug": "captcha-generate",
  "params": {
    "type": "math",
    "difficulty": 1
  }
}

Hosted connector (https://agent402.tools/mcp): free, rate-limited. Stdio package: npx -y agent402-mcp@0.19.2.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.001" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/captcha-generate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "type": "math",
    "difficulty": 1
  }),
});

Get a wallet or run npx -y agent402-mcp@0.19.2 wallet new.

Related tools