Creating a key

This page explains how to create a reCAPTCHA Key.

Keys, also known as site keys, represent a configuration for a site or app. The configuration includes important options such as whether or not to show CAPTCHA challenges.

reCAPTCHA Keys should not be confused with API keys, which are used for authentication rather than configuration. reCAPTCA Enterprise does not support API keys for authentication, and instead uses service accounts to authenticate requests made by apps.

Before you begin

Set up your GCP project and authentication

Create a Key

The simplest way to create a key is through Cloud Console. Alternatively, you can use the Key API or the gcloud SDK as demonstrated below.

REST & CMD LINE

Before using any of the request data below, make the following replacements:

  • project-id: your GCP project ID
  • display-name: display name for Key
  • domain: domains or subdomains of websites allowed to use the Key

HTTP method and URL:

POST https://recaptchaenterprise.googleapis.com/v1/projects/project-id/keys

Request JSON body:

{
  "displayName": "display-name",
  "webSettings": {
    "allowedDomains": "domain",
    "integrationType": "SCORE"
  }
}

To send your request, choose one of these options:

curl

Save the request body in a file called request.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://recaptchaenterprise.googleapis.com/v1/projects/project-id/keys

PowerShell

Save the request body in a file called request.json, and execute the following command:

$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://recaptchaenterprise.googleapis.com/v1/projects/project-id/keys" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "name": "projects/project-id/keys/6Ldqgs0UAAAAAIn4k7YxEB-LwEh5S9-Gv6IIWB8m",
  "displayName": "display-name",
  "webSettings": {
    "allowAllDomains": false,
    "allowedDomains": [
      domain
    ],
    "allowAmpTraffic": false,
    "integrationType": "SCORE",
    "challengeSecurityPreference": "CHALLENGE_SECURITY_PREFERENCE_UNSPECIFIED"
  }
}

gcloud command

Use the gcloud alpha recaptcha keys create command as shown in the following example:

gcloud alpha recaptcha keys create \
  --web \
  --display-name="My Key" \
  --integration-type=score \
  --domains=example.com \

What's next