Captcha generate
POST /api/captcha-generateMint 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)...
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
| Name | Type | Required | Description |
|---|---|---|---|
type | string | no | math | alnum (default math) The example sends math. |
difficulty | integer | no | 1–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
POST /api/captcha-generate$0.001 USDCPAYMENT-SIGNATUREon 14 chains200 OKAgent402-ReceiptEd25519Example response
{
"type": "math",
"prompt": "What is 3 + 4?",
"salt": "…",
"answerHash": "…",
"algo": "sha256",
"verify": "sha256(salt + answer.trim().toLowerCase().replace(/\\s+/g,'')) === answerHash"
}| Field | Type | Always present | In the example |
|---|---|---|---|
type | string | yes | math |
prompt | string | yes | What is 3 + 4? |
salt | string | yes | … |
answerHash | string | yes | … |
algo | string | yes | sha256 |
verify | string | yes | sha256(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
- Pay $0.001 per call over x402 or MPP, or free with proof-of-work (16 leading zero bits of sha256): this tool makes no outbound network call.
- Every field is optional; a rejected input answers 4xx with
error,tool,expected,requiredandexample. - On this route, a call ending in any status of 400 or above is not charged over x402, MPP or a credits key. A Tempo push credential pays before the call; a failure is a refund owed.
- A bodyless
GETorHEADreturns the same 402 quote. - An
Idempotency-Keyreplays the first 200 uncharged (an answer larger than 1 MB is not replayed).
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.