Behavioral CAPTCHA integration guide

Add CAPTCHA before actions such as signup, login, sending a code, or submitting content. The browser or mini program presents the challenge. Your business server verifies the one-time ticket before performing the protected action. Try the available challenges on the product page.

Create a CAPTCHA application

  1. Sign in to the IDCD CAPTCHA console and create an application in Verification Management.
  2. Choose Web/App for websites and apps or Mini Program for mini programs. Select the verification mechanism and challenge type for your use case.
  3. Save the application ID and application secret. Store the application secret in your server's secret configuration. Use separate credentials for each application.

After signing in, open the console integration guide for code examples for the selected application.

Integrate the verification flow

  1. Load a challenge. When the user starts a protected action, the client calls your business server. The server determines action and context from the current session and pending operation, calls IDCD, and returns the challenge to the client.
  2. Submit the answer. Send the challenge ID and answer to your business server. The server submits them to IDCD using the same scope and returns the resulting ticket. Invisible verification may return { "type": "invisible", "ticket": "..." } when you request the challenge. In that case, proceed to the next step.
  3. Verify the ticket and perform the action. The client sends its ticket to the actual business endpoint. The server recovers action and context for the same pending operation and verifies the ticket with IDCD. Send the code or perform the protected action only when result is accepted.

Use a stable operation name for action, such as signup.sms.send. Use a server-generated opaque identifier or digest for context and bind it to the session and pending operation. For example, use a send-code request ID stored on your server. Recover the same application, action, and context from the business session throughout the flow.

Server API

The API base URL is https://api-prod.idcd.com. All three operations use JSON and authenticate with Authorization: Bearer <application-secret>. Include app_id, action, and context in each request. Add client_type: "miniapp" for a mini program application. Mini programs always show a challenge and support slider, text click, and graphic click. Audio, one-click, and invisible verification are available for Web/App.

OperationEndpointRequest and response
Load a challengePOST /v1/captcha/challengesSend the common fields. Returns a challenge and challenge_id, or an invisible verification ticket.
Submit an answerPOST /v1/captcha/challenges/{id}/responsesUse the returned challenge ID as id. Send the common fields and one answer field. Success returns { "ticket": "..." }.
Verify a ticketPOST /v1/captcha/verificationsSend the common fields and ticket. Check the returned result.

Use integer position for a slider. For text or graphic click challenges, send three ordered points with integer x and y coordinates. Map coordinates to the challenge dimensions returned in width and height. Use a six-digit string in answer for audio or clicked: true for one-click verification. If you enable invisible verification or related risk controls, obtain client_ip from your trusted application ingress and include it in the relevant calls. See the SDK guide for domain and application-ID enforcement settings.

Ticket verification example

Run this code on your business server. Recover scope from your session record and verify the ticket at the endpoint that performs the protected action.

type CaptchaScope = {
  app_id: string
  action: string
  context: string
  client_type?: 'miniapp'
  client_ip?: string
}

export async function verifyCaptcha(scope: CaptchaScope, ticket: string, appSecret: string) {
  const response = await fetch('https://api-prod.idcd.com/v1/captcha/verifications', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${appSecret}`,
    },
    body: JSON.stringify({ ...scope, ticket }),
    signal: AbortSignal.timeout(4000),
  })

  if (!response.ok) return false
  const { result } = await response.json()
  return result === 'accepted'
}

A ticket can be consumed once. Keep the protected action blocked for already_used, invalid_or_expired, scope_mismatch, or risk_reported. Stop the operation if verification times out or the service is unavailable. If answer submission returns HTTP 422, inspect error. Fetch a new challenge for incorrect or expired. For scope_mismatch or type_mismatch, check the scope saved when you loaded the challenge and the submitted answer field. HTTP 429 indicates rate limiting or a risk block. Ask the user to try again later. HTTP 402 with quota_exhausted means you should check your CAPTCHA quota.

Use the SDK

The TypeScript SDK is currently a source preview. Use the REST API above directly or follow the SDK instructions to build a package from a source checkout you can access. The SDK guide includes examples for the browser widget, server-side CaptchaClient, and Alipay mini program component. Read the TypeScript SDK guide (repository access required)