Skip to content

Quickstart

Three steps: create a site, run the check on your page, and verify the token on your server.

1. Create a site

In the dashboard, create a site with a name and the hostnames your pages are served from, like shop.example.com or *.example.com. You get two keys:

  • the sitekey (ace_site_…), which is public and goes in your page;
  • the secret (ace_secret_…), which stays on your server. It’s shown once, so store it with your other server secrets right away, for example as ACE_SECRET.

New sites start in shadow mode, so you can roll out safely: nobody sees a check yet, so log each decision, and don’t refuse anything on it yet.

Note

Real keys only run on pages served over https from a hostname listed on the site.

2. Run the check on your page

Load the client with a script tag and place the check in your form. It runs on its own, and the form is sent with a token in ace-token.

login.html
<script src="https://hc.acecaptcha.com/v1/client.js" defer></script><form action="/login" method="post">  <input name="email" type="email" autocomplete="username" required>  <input name="password" type="password" autocomplete="current-password" required>  <div    class="ace-captcha"    data-sitekey="ace_site_xxxxxxxxxxxxxxxxxxxxxx"    data-action="login"  ></div>  <button>Sign in</button></form>

The check takes no space until it’s needed: in enforce mode, when it isn’t clean, a short visible check appears there. Most visitors never see it. Allow hc.acecaptcha.com in your Content Security Policy if you have one: see CSP.

Developing locally? Start with the test keys: they work on localhost and need no site.

3. Verify on your server

Your backend POSTs the token and your secret to siteverify, once per token, and acts on the decision in the reply. Each sample below gives up after 5 seconds, retries a temporary fault once, and lets you choose per action whether an outage fails open or closed.

// verify.mjs (Node 18+)const SITEVERIFY = 'https://hc.acecaptcha.com/v1/siteverify'/** * Redeems a token. Returns 'allow', 'allow_limited' or 'block'. * failOpen: what this action does when AceCaptcha can't answer. */export async function verifyAce(token, { action, remoteip, failOpen = false } = {}) {  const outage = failOpen ? 'allow_limited' : 'block'  const body = JSON.stringify({ secret: process.env.ACE_SECRET, response: token, action, remoteip })  for (let attempt = 0; attempt < 2; attempt++) {    let reply, data    try {      reply = await fetch(SITEVERIFY, {        method: 'POST',        headers: { 'content-type': 'application/json' },        body,        signal: AbortSignal.timeout(5000),      })      data = await reply.json()    } catch {      return outage // network failure, 5 s timeout or unreadable reply    }    if (data['error-codes']?.includes('internal-error')) {      if (attempt === 1) return outage      const wait = Math.min(Number(reply.headers.get('retry-after')) || 1, 5)      await new Promise((resolve) => setTimeout(resolve, wait * 1000))      continue    }    if (!data.success) return 'block' // missing, invalid, expired or used token    if (data.mode === 'shadow') {      console.info('acecaptcha shadow', action, data.decision)      return 'allow'    }    return data.decision // act on decision, never on success alone  }  return outage}// In your route (Express shown)://   const decision = await verifyAce(req.body['ace-token'], { action: 'login', remoteip: req.ip })//   if (decision === 'block') return res.status(403).send('Please try again.')//   if (decision === 'allow_limited') { /* proceed, with tighter limits */ }

Important

success is not a verdict

success: true only means the token is genuine, unexpired and unused. Act on decision: proceed on allow, proceed with tighter limits on allow_limited, refuse on block.

Next steps