Skip to content

Captcha

Captcha token verification and widget issuance.

Overview

Base path: /v1/captcha
Python namespace: infra.captcha
text
# Python
from infrai import infra

# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.captcha

Methods

captcha.verify

POST /v1/captcha/verify

Verify a captcha token from the browser.

Python

python
infra.captcha.verify(token=..., vendor=None, remote_ip=None, min_score=None)

TypeScript

typescript
client.captcha.verify(opts: CaptchaVerifyOptions): Promise<CaptchaVerifyResult>

Parameters

NameTypeRequiredDescription
tokenstring
Required
Token returned by the captcha widget.
vendor"hcaptcha" | "recaptcha" | "turnstile" | "infrai"OptionalPin a specific vendor instead of auto-routing.
remote_ipstringOptionalClient IP for risk scoring.
min_scorenumberOptionalMinimum acceptable score (score-based vendors).

Returns

CaptchaVerifyResult { valid, score?, vendor, hostname?, action? }

Example

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

res = infra.captcha.verify(token=user_submitted_token, remote_ip="203.0.113.7")
print("valid:", res.get("valid"), "| score:", res.get("score"))

captcha.widget.create

POST /v1/captcha/widgets

Issue a captcha widget snippet and script URL.

Python

python
infra.captcha.widget.create(vendor=None, site_key_id=None)

TypeScript

typescript
client.captcha.widget(opts): Promise<{ html, script_url }>

Parameters

NameTypeRequiredDescription
vendorstringOptionalPin a specific vendor instead of auto-routing.
site_key_idstringOptionalConfigured site-key id.

Returns

{ html, script_url }

Example

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

w = infra.captcha.widget.create(vendor="turnstile")
print("embed script:", w.get("script_url"))