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. Anexecutewithout a container givesallow.
Secrets
ace_secret_test- Redeems any test token, with the normal reply shape.
ace_secret_test_spent- Answers every test token with
success: falseandtimeout-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
# Your machine only: never commit or deploy these values.ACE_SITEKEY=ace_site_test_allowACE_SECRET=ace_secret_testKeep 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><?php// ace_keys.php (PHP 8): both keys come from the environment, never from code.const ACE_TEST_SECRETS = ['ace_secret_test', 'ace_secret_test_spent'];function ace_is_test_key(string $key): bool{ return str_starts_with($key, 'ace_site_test_') || in_array($key, ACE_TEST_SECRETS, true);}$aceSitekey = getenv('ACE_SITEKEY') ?: ''; // public: render it into your page$aceSecret = getenv('ACE_SECRET') ?: ''; // server only: ace_verify reads itif ($aceSitekey === '' || $aceSecret === '') { throw new RuntimeException('Set ACE_SITEKEY and ACE_SECRET');}if (getenv('APP_ENV') === 'production' && (ace_is_test_key($aceSitekey) || ace_is_test_key($aceSecret))) { throw new RuntimeException('AceCaptcha test keys must not run in production');}// In your page, inside the form:// <div class="ace-captcha" data-sitekey="<?= htmlspecialchars($aceSitekey) ?>" data-action="login"></div># ace_keys.py: both keys come from the environment, never from code.import osTEST_SECRETS = {"ace_secret_test", "ace_secret_test_spent"}def is_test_key(key): return key.startswith("ace_site_test_") or key in TEST_SECRETSACE_SITEKEY = os.environ.get("ACE_SITEKEY", "") # public: render it into your pageACE_SECRET = os.environ.get("ACE_SECRET", "") # server only: verify_ace reads itif not ACE_SITEKEY or not ACE_SECRET: raise RuntimeError("Set ACE_SITEKEY and ACE_SECRET")if os.environ.get("APP_ENV") == "production" and (is_test_key(ACE_SITEKEY) or is_test_key(ACE_SECRET)): raise RuntimeError("AceCaptcha test keys must not run in production")# In your view, pass the sitekey to the page (Flask shown):# return render_template("login.html", sitekey=ACE_SITEKEY)# and in the template:# <div class="ace-captcha" data-sitekey="{{ sitekey }}" data-action="login"></div>// keys.go (Go 1.21+): both keys come from the environment, never from code.package aceimport ( "log" "os" "slices" "strings")var testSecrets = []string{"ace_secret_test", "ace_secret_test_spent"}func isTestKey(key string) bool { return strings.HasPrefix(key, "ace_site_test_") || slices.Contains(testSecrets, key)}// Sitekey is public: render it into your page. Verify reads ACE_SECRET itself.var Sitekey = os.Getenv("ACE_SITEKEY")func init() { secret := os.Getenv("ACE_SECRET") if Sitekey == "" || secret == "" { log.Fatal("set ACE_SITEKEY and ACE_SECRET") } if os.Getenv("APP_ENV") == "production" && (isTestKey(Sitekey) || isTestKey(secret)) { log.Fatal("AceCaptcha test keys must not run in production") }}// In your handler, pass the sitekey to the page (html/template shown):// page.Execute(w, map[string]string{"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_limitedallow_limited. Your handler proceeds, with your tighter limits.ace_site_test_blockblock. 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:
{ "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}decisionis the test sitekey’s fixed result.modeis alwaysenforce, so theblockandallow_limitedpaths of your handler run.ip_matchis alwaysnull, even when you sendremoteip.- Sending an
actionthat differs from the token’s still givesaction-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:
{ "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:
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_SITEKEYandACE_SECRETin production hold your site’s real keys.- Nothing in your production config, code or build contains
ace_secret_testor anace_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}// In ace_verify, right after the success check:if (empty($data['success'])) { return 'block'; // missing, invalid, expired or used token}if (getenv('APP_ENV') === 'production' && str_starts_with($data['sitekey'] ?? '', 'ace_site_test_')) { return 'block'; // a test token never passes in production}# In verify_ace, right after the success check:if not data.get("success"): return "block" # missing, invalid, expired or used tokenif os.environ.get("APP_ENV") == "production" and data.get("sitekey", "").startswith("ace_site_test_"): return "block" # a test token never passes in production// Add the sitekey to verifyReply:// Sitekey string `json:"sitekey"`// Then in Verify, right after the success check (and import "strings"):if !reply.Success { return "block" // missing, invalid, expired or used token}if os.Getenv("APP_ENV") == "production" && strings.HasPrefix(reply.Sitekey, "ace_site_test_") { return "block" // a test token never passes in production}