Reference
Developer Guide
Everything you need to embed and validate both captchas — from one registration, the same keys.
lc_… key (LangCaptcha) and rtc_… key (Rhythm Trace) in one call.
| Hub host | https://captcha.langlex.com |
|---|---|
| Register (API) | POST https://captcha.langlex.com/api/register |
| LangCaptcha widget | https://captcha.langlex.com/widget?siteKey=lc_… (siteKey required) |
| LangCaptcha API | https://captcha.langlex.com/api/langcaptcha/ |
| LangCaptcha embed JS | https://captcha.langlex.com/assets/langcaptcha-embed.js |
| Rhythm Trace JS | https://vacha.studio/rhythm-trace-captcha/dist/embed/rhythm-trace-captcha.js |
| Rhythm Trace CSS | https://vacha.studio/rhythm-trace-captcha/dist/embed/rhythm-trace-captcha.css |
| Rhythm Trace API | https://vacha.studio/rhythm-trace-captcha/api |
Overview
LangCaptcha hub issues two distinct keys from one registration. Each key gates a different challenge type:
- LangCaptcha — Indic-script glyph matching. The widget is an HTML fragment served from
/captcha. Success is signalled via acaptchaValidatedDOM event andpostMessage. No backend token exchange is required. - Rhythm Trace — motion-path verification. The widget mints a signed token after a successful trace. Your backend must call
/captcha/validateto verify that token before trusting the user action.
1 · Register & get keys
POST once to receive both keys. Provide one main domain (e.g. acme.com). All subdomains (www, test, app, …) plus localhost / 127.0.0.1 are allowed automatically.
curl -sS -X POST https://captcha.langlex.com/api/register \
-H 'Content-Type: application/json' \
-d '{
"name": "Acme Checkout",
"domain": "acme.com",
"email": "dev@acme.com",
"password": "your-password"
}'
The response includes:
| Field | Description |
|---|---|
langcaptcha.siteKey | Your lc_… key for LangCaptcha embed |
langcaptcha.widget | Direct widget URL with siteKey pre-filled |
rhythmTrace.siteKey | Your rtc_… key for Rhythm Trace embed & validation |
rhythmTrace.apiBase | API base for challenge / verify / validate calls |
2 · LangCaptcha — Embed
Option A — Embed helper JS (recommended)
<!-- 1. Placeholder div -->
<div id="langcaptcha"></div>
<input type="hidden" id="lc_ok" name="lc_ok" value="0"/>
<!-- 2. Embed script -->
<script src="https://captcha.langlex.com/assets/langcaptcha-embed.js"></script>
<script>
LangCaptcha.mount({
target: '#langcaptcha',
siteKey: 'YOUR_LC_SITE_KEY', // required — anonymous embeds are rejected
tokenInput:'#lc_ok',
onVerified: function (data) {
document.getElementById('submit-btn').disabled = false;
}
});
</script>
Option B — Direct iframe
<iframe
src="https://captcha.langlex.com/widget?siteKey=YOUR_LC_SITE_KEY"
style="width:100%;min-height:480px;border:0"
title="LangCaptcha">
</iframe>
/captcha to load a challenge and /validate_captcha to check the answer. These are handled automatically — you only need to listen for the success event.
Mount options
| Option | Type | Description |
|---|---|---|
target | string | Element | CSS selector or DOM element for the captcha container |
siteKey | string | Your lc_… key |
tokenInput | string | CSS selector of a hidden input — set to "true" on success |
onVerified | function(data) | Callback fired when user passes the challenge |
onValidated | function(data) | Callback for every validation attempt (pass or fail) |
height | number | Minimum iframe height in px (default 480) |
3 · LangCaptcha — JSON API
Recommended for custom UIs. This path has no built-in script dropdown — call GET /scripts and render your own selector (or omit script on challenge to pick one at random). For the ready-made “Please select the script” UI, use the widget embed instead.
Base: https://captcha.langlex.com/api/langcaptcha/ — discovery GET /
| Endpoint | Body | Result |
|---|---|---|
GET /scripts | — | { scripts: [{ id, script, count }] } |
POST /challenge | { siteKey, script? } | { challengeId, prompt, image:{src}, options:[{id,image:{src}}], expiresAt } — composite challenge image, multiple options, short TTL |
POST /verify | { siteKey, challengeId, optionId } | { token } or wrong/blocked |
POST /validate | { siteKey, token, consume? } | { ok } |
# 0. List scripts (for your dropdown)
curl -sS https://captcha.langlex.com/api/langcaptcha/scripts
# 1. Challenge (pass the script the user selected)
curl -sS -X POST https://captcha.langlex.com/api/langcaptcha/challenge \
-H 'Content-Type: application/json' \
-d '{"siteKey":"YOUR_LC_SITE_KEY","script":"Devanagari"}'
# 2. Verify (user selected optionId)
curl -sS -X POST https://captcha.langlex.com/api/langcaptcha/verify \
-H 'Content-Type: application/json' \
-d '{"siteKey":"YOUR_LC_SITE_KEY","challengeId":"lch_…","optionId":"opt_1"}'
# 3. Backend validate (required)
curl -sS -X POST https://captcha.langlex.com/api/langcaptcha/validate \
-H 'Content-Type: application/json' \
-d '{"siteKey":"YOUR_LC_SITE_KEY","token":"lct_…","consume":true}'
/validate with consume: true on your server before trusting the user.
PHP validate helper
function validate_langcaptcha_token(string $token, string $siteKey): bool {
$payload = json_encode(['token' => $token, 'siteKey' => $siteKey, 'consume' => true]);
$ch = curl_init('https://captcha.langlex.com/api/langcaptcha/validate');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 8,
]);
$raw = curl_exec($ch);
curl_close($ch);
$data = json_decode($raw ?: '', true);
return !empty($data['ok']);
}
4 · LangCaptcha — Success signals (widget)
Three ways to detect a successful solve — pick the one that suits your integration:
a) Hidden field
// Set tokenInput in mount options, then check on form submit:
form.addEventListener('submit', e => {
if (document.getElementById('lc_ok').value !== 'true') {
e.preventDefault();
alert('Please complete the captcha');
}
});
b) postMessage (iframe integration)
window.addEventListener('message', e => {
if (!e.data || e.data.type !== 'captchaValidated') return;
const { status, result, attempts } = e.data.data;
if (result === true) {
submitBtn.disabled = false;
}
});
c) jQuery event (same-document embed)
$(document).on('captchaValidated', (e, payload) => {
if (payload.result === true) submitBtn.disabled = false;
});
// Global backup variable:
// window.captchaResult = { status, result, attempts, timestamp }
5 · LangCaptcha — Attempt limits
| Rule | Value |
|---|---|
| Max wrong attempts | 3 |
| Block duration | 60 seconds |
| Fresh page load | Resets attempt counter |
| Session storage | File-based, keyed by session_token |
Validation responses: correct / wrong / blocked / error.
6 · Rhythm Trace — Embed
<!-- 1. Styles + widget bundle -->
<link rel="stylesheet" href="https://vacha.studio/rhythm-trace-captcha/dist/embed/rhythm-trace-captcha.css"/>
<script src="https://vacha.studio/rhythm-trace-captcha/dist/embed/rhythm-trace-captcha.js" defer></script>
<!-- 2. Markup -->
<form method="post" action="/submit">
<input type="hidden" name="captcha_token" id="captcha_token"/>
<div id="rhythm-captcha"></div>
<button id="go" type="submit" disabled>Submit</button>
</form>
<!-- 3. Mount -->
<script>
document.addEventListener('DOMContentLoaded', () => {
RhythmTraceCaptcha.mount({
target: '#rhythm-captcha',
apiBase: 'https://vacha.studio/rhythm-trace-captcha/api',
siteKey: 'YOUR_RTC_SITE_KEY',
tokenInput: '#captcha_token',
onVerified: () => { document.getElementById('go').disabled = false; }
});
});
</script>
Mount options
| Option | Type | Description |
|---|---|---|
target | string | Element | Container for the challenge UI |
apiBase | string | Rhythm Trace API base URL |
siteKey | string | Your rtc_… key |
tokenInput | string | Hidden input to receive the signed token |
onVerified | function(token) | Fired when user passes, with the signed token string |
React component
import { RhythmTraceCaptcha } from './RhythmTraceCaptcha';
<RhythmTraceCaptcha
apiBase="https://vacha.studio/rhythm-trace-captcha/api"
siteKey="YOUR_RTC_SITE_KEY"
onVerified={(token) => setCaptchaToken(token)}
/>
7 · Rhythm Trace — Backend validation
Always validate the token server-side before trusting the user action. Use consume: true so the token cannot be reused.
function validate_rhythm_token(string $token, string $siteKey): bool {
// Prefer the LangCaptcha hub proxy so successful verifies are metered for billing.
$payload = json_encode(['token' => $token, 'siteKey' => $siteKey, 'consume' => true]);
$ch = curl_init('https://captcha.langlex.com/api/rhythm/validate');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Accept: application/json'],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 8,
]);
$raw = curl_exec($ch);
curl_close($ch);
$data = json_decode($raw ?: '', true);
return !empty($data['ok']);
}
const res = await fetch('https://captcha.langlex.com/api/rhythm/validate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token, siteKey: 'YOUR_RTC_SITE_KEY', consume: true }),
});
const data = await res.json();
if (!data.ok) return res.status(400).json({ error: 'Captcha failed' });
8 · Rhythm Trace — Accessibility
Rhythm Trace includes three accessible alternatives out of the box:
| Mode | Interaction |
|---|---|
| Swipe path | One continuous mouse/touch trace along the glowing path |
| Tap dots | Tap 3 moving targets in sequence |
| Audio code | Spoken digits via Web Speech API — type to confirm |
| Email OTP | 6-digit code sent to user's email address |
| Keyboard | Focus the pad → hold Space / ArrowRight to advance along path |
Retry limit is enforced both client-side and server-side (maxAttempts, default 5).
9 · HTTP API reference
Hub
| Method + Path | Body | Response |
|---|---|---|
POST /api/register |
{ name, domain, email, password } |
Account + LangCaptcha key + Rhythm Trace key |
LangCaptcha — https://captcha.langlex.com/api/langcaptcha
| Path | Body | Returns |
|---|---|---|
GET / | — | discovery |
GET /scripts | — | script list |
POST /challenge | { siteKey, script? } | challenge (no answer) |
POST /verify | { siteKey, challengeId, optionId } | { token } |
POST /validate | { siteKey, token, consume? } | { ok } |
Rhythm Trace — https://vacha.studio/rhythm-trace-captcha/api
Discovery: GET https://vacha.studio/rhythm-trace-captcha/api/ — returns schema + all endpoints.
| Path | Body | Returns |
|---|---|---|
/captcha/register | { name, origins[], contactEmail? } | { siteKey, apiBase, embed } |
/captcha/challenge | { siteKey } | { challengeId, pathKind, pathD, dotProgress, maxAttempts, expiresAt } |
/captcha/verify | { challengeId, siteKey, signals } | { token, expiresAt, score } |
/captcha/validate | { token, siteKey, consume? } | { ok } |
/captcha/alt-request | { challengeId, method, email? } | { ok, message } |
/captcha/alt-verify | { challengeId, method, code, siteKey } | { token } |
signals are derived only (length, duration, speed variance, direction changes, pauses, coverage, touch metadata). Raw coordinates are never stored.
10 · CORS
Both /captcha and /validate_captcha send open CORS headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
LangCaptcha allows your main domain and all its subdomains, plus localhost / 127.0.0.1. Rhythm Trace is registered with a fixed origin set (apex, www, and common local ports).
11 · Troubleshooting
| Symptom | Fix |
|---|---|
| Challenge area blank after script selection | Inspect Network → check POST /captcha response for PHP errors |
Session token required | Pass session_token from #session_token into /validate_captcha |
| Options disabled + countdown | 3 wrong attempts — wait 60s or reload page |
| postMessage events not received in parent | Listen for window.message with e.data.type === 'captchaValidated' |
| Origin not allowed / CORS on embed | Confirm the project’s main domain matches the site host (subdomains are fine). Localhost always works. |
Unknown or expired challenge | Challenge TTL expired — retry; check browser storage permissions |
Token already used | Use consume: true exactly once; user must solve captcha again on next action |
| Rhythm Trace script missing | Load CSS + JS from https://vacha.studio/rhythm-trace-captcha/dist/embed/rhythm-trace-captcha.js |