Developer Guide

Everything you need to embed and validate both captchas — from one registration, the same keys.

Quickstart: Register at /hub/get-key to receive a 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 widgethttps://captcha.langlex.com/widget?siteKey=lc_… (siteKey required)
LangCaptcha APIhttps://captcha.langlex.com/api/langcaptcha/
LangCaptcha embed JShttps://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 a captchaValidated DOM event and postMessage. 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/validate to 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.

bash
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:

FieldDescription
langcaptcha.siteKeyYour lc_… key for LangCaptcha embed
langcaptcha.widgetDirect widget URL with siteKey pre-filled
rhythmTrace.siteKeyYour rtc_… key for Rhythm Trace embed & validation
rhythmTrace.apiBaseAPI base for challenge / verify / validate calls

2 · LangCaptcha — Embed

Option A — Embed helper JS (recommended)

html
<!-- 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

html
<iframe
  src="https://captcha.langlex.com/widget?siteKey=YOUR_LC_SITE_KEY"
  style="width:100%;min-height:480px;border:0"
  title="LangCaptcha">
</iframe>
Widget internals: The widget POSTs to /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

OptionTypeDescription
targetstring | ElementCSS selector or DOM element for the captcha container
siteKeystringYour lc_… key
tokenInputstringCSS selector of a hidden input — set to "true" on success
onVerifiedfunction(data)Callback fired when user passes the challenge
onValidatedfunction(data)Callback for every validation attempt (pass or fail)
heightnumberMinimum 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 /

EndpointBodyResult
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 }
bash
# 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}'
Security: The challenge response never includes the correct answer. Always call /validate with consume: true on your server before trusting the user.

PHP validate helper

php
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

js
// 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)

js
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)

js
$(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

RuleValue
Max wrong attempts3
Block duration60 seconds
Fresh page loadResets attempt counter
Session storageFile-based, keyed by session_token

Validation responses: correct / wrong / blocked / error.

6 · Rhythm Trace — Embed

html
<!-- 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

OptionTypeDescription
targetstring | ElementContainer for the challenge UI
apiBasestringRhythm Trace API base URL
siteKeystringYour rtc_… key
tokenInputstringHidden input to receive the signed token
onVerifiedfunction(token)Fired when user passes, with the signed token string

React component

tsx
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.

php
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']);
}
js / node
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:

ModeInteraction
Swipe pathOne continuous mouse/touch trace along the glowing path
Tap dotsTap 3 moving targets in sequence
Audio codeSpoken digits via Web Speech API — type to confirm
Email OTP6-digit code sent to user's email address
KeyboardFocus 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 + PathBodyResponse
POST /api/register { name, domain, email, password } Account + LangCaptcha key + Rhythm Trace key

LangCaptcha — https://captcha.langlex.com/api/langcaptcha

PathBodyReturns
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.

PathBodyReturns
/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:

http
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

SymptomFix
Challenge area blank after script selectionInspect Network → check POST /captcha response for PHP errors
Session token requiredPass session_token from #session_token into /validate_captcha
Options disabled + countdown3 wrong attempts — wait 60s or reload page
postMessage events not received in parentListen for window.message with e.data.type === 'captchaValidated'
Origin not allowed / CORS on embedConfirm the project’s main domain matches the site host (subdomains are fine). Localhost always works.
Unknown or expired challengeChallenge TTL expired — retry; check browser storage permissions
Token already usedUse consume: true exactly once; user must solve captcha again on next action
Rhythm Trace script missingLoad CSS + JS from https://vacha.studio/rhythm-trace-captcha/dist/embed/rhythm-trace-captcha.js