Skip to content

CAPTCHA Result Validation

When a visitor solves the TrustCaptcha widget, your form receives a verification token. Your server exchanges that token for the verification result and decides whether to accept the request. This page shows the whole server side in every language we support: pick yours in any code example, and the choice applies to the whole documentation.

You need a project with the TrustCaptcha module, the widget on your page (see the widget guide) and an API key of the project, created in the dashboard under API / Integration of the project. Keep the key on your server; it never belongs in the browser. The examples write it as <your_api_key>: load it the way your application loads its other secrets, from an environment variable, your framework’s configuration or a secret manager, and never commit it.

Install the SDK:

Install
Terminal window
# cURL calls the REST API directly, nothing to install.
Install
Terminal window
npm install @trustcomponent/sdk
Install
Terminal window
composer require trustcomponent/trustcomponent-php
Install
Terminal window
pip install trustcomponent
Install
<!-- Maven; Gradle: implementation("com.trustcomponent:trustcomponent-java:1.0.1") -->
<dependency>
<groupId>com.trustcomponent</groupId>
<artifactId>trustcomponent-java</artifactId>
<version>1.0.1</version>
</dependency>
Install
Terminal window
dotnet add package TrustComponent
Install
Terminal window
go get github.com/trustcomponent/trustcomponent-go
Install
Terminal window
gem install trustcomponent
Install
Terminal window
cargo add trustcomponent

Then turn the token from the form field tc-verification-token into the result:

Check the verification result
Terminal window
# The verification id is inside the token (see "The verification token" below).
curl "https://api.trustcomponent.com/captcha/v3/verifications/{verificationId}/results" \
-H "Authorization: Bearer <your_api_key>"
Check the verification result
import { TrustComponent } from '@trustcomponent/sdk';
const tc = new TrustComponent('<your_api_key>');
const result = await tc.captcha.getVerificationResult(request.body['tc-verification-token']);
if (!result.isVerificationPassed) {
// reject the request
}
Check the verification result
use TrustComponent\TrustComponent;
$tc = new TrustComponent('<your_api_key>');
$result = $tc->captcha()->getVerificationResult($_POST['tc-verification-token']);
if (!$result->isVerificationPassed()) {
// reject the request
}
Check the verification result
from trustcomponent import TrustComponent
tc = TrustComponent("<your_api_key>")
result = tc.captcha.get_verification_result(request.form["tc-verification-token"])
if not result.is_verification_passed:
... # reject the request
Check the verification result
import com.trustcomponent.sdk.TrustComponent;
import com.trustcomponent.sdk.model.CaptchaVerificationResult;
TrustComponent tc = new TrustComponent("<your_api_key>");
CaptchaVerificationResult result = tc.captcha().getVerificationResult(request.getParameter("tc-verification-token"));
if (!result.isVerificationPassed()) {
// reject the request
}
Check the verification result
using TrustComponent;
using var tc = new TrustComponentClient("<your_api_key>");
var result = await tc.Captcha.GetVerificationResultAsync(Request.Form["tc-verification-token"]);
if (!result.IsVerificationPassed)
{
// reject the request
}
Check the verification result
import trustcomponent "github.com/trustcomponent/trustcomponent-go"
tc := trustcomponent.New("<your_api_key>")
result, err := tc.Captcha.GetVerificationResult(ctx, r.FormValue("tc-verification-token"))
if err != nil || !result.IsVerificationPassed {
// reject the request (see "Errors" for err)
}
Check the verification result
require 'trustcomponent'
tc = TrustComponent::Client.new('<your_api_key>')
result = tc.captcha.get_verification_result(params['tc-verification-token'])
unless result.is_verification_passed
# reject the request
end
Check the verification result
let tc = trustcomponent::TrustComponent::new("<your_api_key>");
let result = tc.captcha.get_verification_result(&form.verification_token).await?;
if !result.is_verification_passed {
// reject the request
}

That is the whole integration. The rest of this page explains the token, the result, how to judge it, the errors and the options.


When the widget is solved, it writes the verification token into the hidden input field tc-verification-token and also hands it over with the captchaSolved JavaScript event (see the widget overview). Send it to your server together with the form, or separately through your own API.

The token is Base64-encoded JSON:

Sample verification token (encoded)
eyJ2ZXJpZmljYXRpb25JZCI6IjA3YjAxOTIyLTNmYWEtNDY2Ny1hNGE2LTkxMGE3NmNiOGFiNyIsImV4cGlyZXNBdCI6IjIwMjYtMDUtMDNUMTM6NDU6MDguMjE0WiJ9
Decoded sample token
{
"verificationId": "07b01922-3faa-4667-a4a6-910a76cb8ab7",
"expiresAt": "2026-05-03T13:45:08.214Z"
}
KeyValueDescription
verificationIdUUIDId of the verification, used to retrieve its result.
expiresAtTimestamp (UTC)When the token, and with it the result, can no longer be retrieved.
clientFailoverBooleanOptional. true when the widget could not reach TrustCaptcha and built the token itself. See Failover behavior.

The SDK reads the token for you: getVerificationResult takes the token as it comes from the form and passes clientFailover on when it is set. A string that is not a TrustCaptcha token raises a token error before any request is sent. If you call the REST API yourself, decode the token, take verificationId, and add ?clientFailover=true to the request when the token carries it.


By default a result can be retrieved for 15 minutes after the widget was solved, and only a limited number of times. Both can be changed in the CAPTCHA settings.

Verification result
{
"captchaId": "cc2e2d5e-d1ef-4a7f-a7bd-dec5b37df47a",
"verificationId": "07b01922-3faa-4667-a4a6-910a76cb8ab7",
"isVerificationPassed": true,
"score": 0.3,
"decisionType": "STANDARD",
"decisionAction": "ALLOW",
"isGatewayFailoverActive": false,
"isRiskScoringEnabled": true,
"isMinimalDataModeEnabled": false,
"origin": "https://www.your-website.com/sub-page",
"ipAddress": "2a01:123:33bb:1a1a:0:0:0:1",
"countryCode": "DE",
"deviceFamily": "Other",
"operatingSystem": "Windows 10",
"browser": "Chrome 119.0.0",
"verificationStartedAt": "2026-05-03T13:30:05.941Z",
"verificationFinishedAt": "2026-05-03T13:30:08.214Z",
"resultExpiresAt": "2026-05-03T13:45:08.214Z",
"resultFirstFetchedAt": "2026-05-03T13:30:09.001Z",
"resultLastFetchedAt": "2026-05-03T13:30:09.001Z"
}

The SDK returns the same fields in the naming of your language (isVerificationPassed, is_verification_passed, IsVerificationPassed, …). Every field and every status code is described in the API reference; for the check itself you need isVerificationPassed and score, explained next.


Two fields carry the decision: isVerificationPassed says whether the CAPTCHA was passed, score how likely the request is automated (0 = probably human, 1 = probably automated). A good starting point is to accept a request only when it passed and its score is at most 0.5:

Starting point
if (!result.isVerificationPassed || result.score > 0.5) {
// failed or likely automated: reject
}
Starting point
if (!$result->isVerificationPassed() || $result->getScore() > 0.5) {
// failed or likely automated: reject
}
Starting point
if not result.is_verification_passed or result.score > 0.5:
... # failed or likely automated: reject
Starting point
if (!result.isVerificationPassed() || result.getScore() > 0.5) {
// failed or likely automated: reject
}
Starting point
if (!result.IsVerificationPassed || result.Score > 0.5)
{
// failed or likely automated: reject
}
Starting point
if !result.IsVerificationPassed || result.Score > 0.5 {
// failed or likely automated: reject
}
Starting point
if !result.is_verification_passed || result.score > 0.5
# failed or likely automated: reject
end
Starting point
if !result.is_verification_passed || result.score > 0.5 {
// failed or likely automated: reject
}

Adapt this to your own risk. Always check isVerificationPassed; leave out the score check if you only want the proof of work. Raise the threshold (for example to 0.75) when a wrongly rejected visitor costs you more than a spam message, lower it for sensitive actions. Or decide in steps, so that a higher risk leads to an extra check instead of a rejection:

Decide in steps
const score = result.score;
if (!result.isVerificationPassed || score >= 0.8) {
// reject
} else if (score >= 0.4) {
// elevated risk: ask for an e-mail confirmation or a second factor
} else {
// low risk: proceed
}
Decide in steps
$score = $result->getScore();
if (!$result->isVerificationPassed() || $score >= 0.8) {
// reject
} elseif ($score >= 0.4) {
// elevated risk: ask for an e-mail confirmation or a second factor
} else {
// low risk: proceed
}
Decide in steps
score = result.score
if not result.is_verification_passed or score >= 0.8:
... # reject
elif score >= 0.4:
... # elevated risk: ask for an e-mail confirmation or a second factor
else:
... # low risk: proceed
Decide in steps
double score = result.getScore();
if (!result.isVerificationPassed() || score >= 0.8) {
// reject
} else if (score >= 0.4) {
// elevated risk: ask for an e-mail confirmation or a second factor
} else {
// low risk: proceed
}
Decide in steps
if (!result.IsVerificationPassed || result.Score >= 0.8)
{
// reject
}
else if (result.Score >= 0.4)
{
// elevated risk: ask for an e-mail confirmation or a second factor
}
else
{
// low risk: proceed
}
Decide in steps
switch score := result.Score; {
case !result.IsVerificationPassed || score >= 0.8:
// reject
case score >= 0.4:
// elevated risk: ask for an e-mail confirmation or a second factor
default:
// low risk: proceed
}
Decide in steps
score = result.score
if !result.is_verification_passed || score >= 0.8
# reject
elsif score >= 0.4
# elevated risk: ask for an e-mail confirmation or a second factor
else
# low risk: proceed
end
Decide in steps
let score = result.score;
if !result.is_verification_passed || score >= 0.8 {
// reject
} else if score >= 0.4 {
// elevated risk: ask for an e-mail confirmation or a second factor
} else {
// low risk: proceed
}

Two more fields explain how the outcome came about: decisionType names the mechanism, decisionAction what TrustCaptcha recommends.

decisionTypeDescription
STANDARDThe regular validation decided (proof of work and risk score).
BYPASS_KEYThe CAPTCHA was solved with a bypass key.
CUSTOM_ACCESS_RULEAn access rule of this CAPTCHA matched, for example an allow or block list.
GLOBAL_IP_ACCESS_RULEA global TrustCaptcha access rule matched.
FAILOVERThe CAPTCHA service was unreachable; the gateway answered with a tolerant result.
FAILOVER_TOLERANCEShortly after an outage the service answered “not finished” or “not found”; the gateway still answered with a tolerant result.
decisionActionDescription
ALLOWAllow the request.
BLOCKBlock the request.
CUSTOMA rule with a custom action matched; your CAPTCHA settings tell which one.

Every error answer is a problem object with an English detail and, where a program may react to the reason, a stable code; the SDK raises one error type per kind with the HTTP status and the code. Which statuses and codes the call can answer is listed in the API reference.

Treat every error as “not verified” and reject the request, unless you decided otherwise for the case that TrustCaptcha cannot be reached (see Failover behavior):

Handle errors
import { ConnectionError, ServerError, TrustComponentError } from '@trustcomponent/sdk';
try {
const result = await tc.captcha.getVerificationResult(token);
// evaluate the result
} catch (e) {
if (e instanceof ConnectionError || e instanceof ServerError) {
// TrustCaptcha unreachable: apply your failover decision
} else if (e instanceof TrustComponentError) {
// not verified: reject (e.status and e.code tell why)
} else {
throw e;
}
}
Handle errors
use TrustComponent\Exception\ConnectionException;
use TrustComponent\Exception\ServerException;
use TrustComponent\Exception\TrustComponentException;
try {
$result = $tc->captcha()->getVerificationResult($token);
// evaluate the result
} catch (ConnectionException | ServerException $e) {
// TrustCaptcha unreachable: apply your failover decision
} catch (TrustComponentException $e) {
// not verified: reject ($e->getCode() is the HTTP status, $e->errorCode the reason)
}
Handle errors
from trustcomponent import ConnectionError, ServerError, TrustComponentError
try:
result = tc.captcha.get_verification_result(token)
# evaluate the result
except (ConnectionError, ServerError):
... # TrustCaptcha unreachable: apply your failover decision
except TrustComponentError as e:
... # not verified: reject (e.status and e.code tell why)
Handle errors
import com.trustcomponent.sdk.exception.ConnectionException;
import com.trustcomponent.sdk.exception.ServerException;
import com.trustcomponent.sdk.exception.TrustComponentException;
try {
CaptchaVerificationResult result = tc.captcha().getVerificationResult(token);
// evaluate the result
} catch (ConnectionException | ServerException e) {
// TrustCaptcha unreachable: apply your failover decision
} catch (TrustComponentException e) {
// not verified: reject (e.getStatus() and e.getCode() tell why)
}
Handle errors
try
{
var result = await tc.Captcha.GetVerificationResultAsync(token);
// evaluate the result
}
catch (Exception e) when (e is ConnectionException or ServerException)
{
// TrustCaptcha unreachable: apply your failover decision
}
catch (TrustComponentException e)
{
// not verified: reject (e.Status and e.Code tell why)
}
Handle errors
result, err := tc.Captcha.GetVerificationResult(ctx, token)
var connErr *trustcomponent.ConnectionError
var apiErr *trustcomponent.Error
switch {
case err == nil:
// evaluate the result
case errors.As(err, &connErr), errors.As(err, &apiErr) && apiErr.IsServer():
// TrustCaptcha unreachable: apply your failover decision
default:
// not verified: reject
}
Handle errors
begin
result = tc.captcha.get_verification_result(token)
# evaluate the result
rescue TrustComponent::ConnectionError, TrustComponent::ServerError
# TrustCaptcha unreachable: apply your failover decision
rescue TrustComponent::Error => e
# not verified: reject (e.status and e.code tell why)
end
Handle errors
use trustcomponent::Error;
match tc.captcha.get_verification_result(&token).await {
Ok(result) => { /* evaluate the result */ }
Err(Error::Connection(_)) => { /* TrustCaptcha unreachable: apply your failover decision */ }
Err(Error::Api(e)) if e.is_server() => { /* TrustCaptcha unreachable: apply your failover decision */ }
Err(_) => { /* not verified: reject */ }
}

Timeouts, retries, a proxy and the name of your integration are options of the client; every language is listed under Configuration in the API overview. Set the retries to 0 when your form has to answer within a tight time budget.


Fixed verification ids give fixed answers with any API key of a project with TrustCaptcha, so you can test every branch of your code without solving the widget:

Verification idAnswer
00000000-0000-0000-0000-000000000000200, a passed result with score 0.3
00000000-0000-0000-0000-000000000001404, no verification with this id
00000000-0000-0000-0000-000000000002409, result_not_released
00000000-0000-0000-0000-000000000003410, result_expired
00000000-0000-0000-0000-000000000004410, result_retrieval_limit_reached

A token for the SDK is the Base64 of {"verificationId":"<id>"}, for example eyJ2ZXJpZmljYXRpb25JZCI6IjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCJ9 for the passed result. For automated tests of your whole site, see Testing.


Once you have integrated the TrustCaptcha widget into your frontend and the CAPTCHA result validation into your backend, you can use TrustCaptcha to its full extent. However, we still recommend the following additional technical and organizational measures:

  • Security rules: You can find many security settings for your CAPTCHA in the CAPTCHA settings. These include, for example, authorized websites, CAPTCHA bypass for specific IP addresses, bypass keys, IP based blocking, geoblocking, individual difficulty and duration of the CAPTCHA, and much more. Learn more about the security rules.

  • Privacy & GDPR compliance: Include a passage in your privacy policy that refers to the use of TrustCaptcha. We also recommend that you enter into a data processing agreement with us to stay GDPR-compliant. Learn more about data protection.

  • Accessibility & UX: Customize TrustCaptcha to your website so that your website is as accessible as possible and offers the best possible user experience. More about accessibility.

  • Failover behavior: Decide how your backend should behave when our service is temporarily unreachable. This is particularly important for high-availability flows where blocking real users during an outage is worse than letting through a small amount of unverified traffic. Learn more about failover behavior.

  • Testing: If you use automated testing, make sure that the CAPTCHA does not block it. Learn more about testing.