Skip to content

Testing locally

Build and test your integration on localhost with fixed test keys. They need no account, return the result you pick, and never count toward your quota.

The test keys

Test keys are fixed and public: the same for everyone. They need no account, work on any hostname, including localhost and 127.0.0.1 over plain http, run no detection, and never count toward your quota or show up in your usage.

Sitekeys

Pick the sitekey for the result you want to test.

ace_site_test_allow
Always allow.
ace_site_test_limited
Always allow_limited.
ace_site_test_block
Always block.
ace_site_test_widget
Shows the visible check, and any completed hold gives allow. Use it to test placement, theme and words. An execute without a container gives allow.

Secrets

ace_secret_test
Redeems any test token, with the normal reply shape.
ace_secret_test_spent
Answers every test token with success: false and timeout-or-duplicate, so you can test the “already used” path.

Important

Never ship the test secret

A backend using ace_secret_test in production accepts anyone. Keep the test keys to development, and go through the production checklist before you deploy.

Develop locally

Keep both keys out of your code. Local development and production then run the same code, and only the environment changes.

1. Set the test keys on your machine

Local environment
# Your machine only: never commit or deploy these values.ACE_SITEKEY=ace_site_test_allowACE_SECRET=ace_secret_test

Keep this file out of your repository and your deploys. In production, ACE_SITEKEY and ACE_SECRET hold your site’s real keys from the dashboard.

2. Read the keys from the environment

The sitekey goes into your page, and the secret stays on your server, where the siteverify samples already read it from ACE_SECRET. Each sample refuses to start in production with a test key.

// ace-keys.mjs (Node 18+): both keys come from the environment, never from code.const TEST_SECRETS = ['ace_secret_test', 'ace_secret_test_spent']const isTestKey = (key) => key.startsWith('ace_site_test_') || TEST_SECRETS.includes(key)export const ACE_SITEKEY = process.env.ACE_SITEKEY ?? '' // public: render it into your pageconst secret = process.env.ACE_SECRET ?? '' // server only: verifyAce reads itif (!ACE_SITEKEY || !secret) throw new Error('Set ACE_SITEKEY and ACE_SECRET')if (process.env.NODE_ENV === 'production' && (isTestKey(ACE_SITEKEY) || isTestKey(secret))) {  throw new Error('AceCaptcha test keys must not run in production')}// In your route, pass the sitekey to the page (Express with EJS shown)://   res.render('login', { sitekey: ACE_SITEKEY })// and in the template://   <div class="ace-captcha" data-sitekey="<%= sitekey %>" data-action="login"></div>

The samples treat NODE_ENV or APP_ENV set to production as production; use whatever your app already goes by. In a single-page app, pass only the sitekey through your bundler’s public variables, like VITE_ACE_SITEKEY or NEXT_PUBLIC_ACE_SITEKEY. The secret never goes there.

3. Walk every path

Swap the sitekey (and, for the last row, the secret) and check that your handler does the right thing each time:

ace_site_test_allow
Siteverify answers allow. Your handler proceeds.
ace_site_test_limited
allow_limited. Your handler proceeds, with your tighter limits.
ace_site_test_block
block. Your handler refuses, with a generic error.
ace_site_test_widget
Your page shows the visible check. Complete the hold to get allow.
ace_secret_test_spent
With any test sitekey: timeout-or-duplicate. Your handler treats it as a failed token and asks the visitor to try again.

What siteverify answers

With ace_secret_test, a test token gets a reply with the same fields as production:

200 OK
{  "success": true,  "error-codes": [],  "sitekey": "ace_site_test_allow",  "hostname": "localhost",  "challenge_ts": "2026-11-21T10:00:00.000Z",  "action": "login",  "decision": "allow",  "mode": "enforce",  "ip_match": null}
  • decision is the test sitekey’s fixed result.
  • mode is always enforce, so the block and allow_limited paths of your handler run.
  • ip_match is always null, even when you send remoteip.
  • Sending an action that differs from the token’s still gives action-mismatch.

Expiry, but no single use

Test tokens expire after 5 minutes, like real ones, but can be redeemed more than once. So they can’t test the “already used” path. Use ace_secret_test_spent for that. It answers every test token with:

200 OK
{  "success": false,  "error-codes": ["timeout-or-duplicate"]}

Test and real keys fail closed

Test keys and real keys never mix, in either direction:

  • a real (production) secret rejects test tokens with invalid-input-response;
  • both test secrets reject real tokens with invalid-input-response.

So forgetting to swap one of the two keys fails instead of letting bots through. If every verification fails with invalid-input-response after a deploy, check that both keys were swapped.

Why real keys never work on localhost

Sitekeys are public. If real keys passed on localhost, anyone could mint passing tokens for your site on their own machine, so real keys only work over https on the hostnames listed on your site.

Content Security Policy

Local development needs the same Content Security Policy as production. If your page sends one, allow https://hc.acecaptcha.com:

CSP directives
script-src 'self' https://hc.acecaptcha.com 'wasm-unsafe-eval';frame-src https://hc.acecaptcha.com;connect-src 'self' https://hc.acecaptcha.com;

Production checklist

  • ACE_SITEKEY and ACE_SECRET in production hold your site’s real keys.
  • Nothing in your production config, code or build contains ace_secret_test or an ace_site_test_ sitekey.
  • Your backend refuses replies from test sitekeys in production (below).
  • Every hostname that serves the check is listed on the site, over https.
  • Your Content Security Policy allows https://hc.acecaptcha.com.
  • Your handler acts on decision, and you’ve walked every path with the test keys.

Refuse test tokens in production

As a second guard, have your backend refuse any reply whose sitekey starts with ace_site_test_ when it runs in production. Real sitekeys never start with it. Add this to the verify function from the siteverify samples:

// In verifyAce, right after the success check:if (!data.success) return 'block' // missing, invalid, expired or used tokenif (process.env.NODE_ENV === 'production' && data.sitekey?.startsWith('ace_site_test_')) {  return 'block' // a test token never passes in production}