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.
Quick start
Section titled “Quick start”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:
# cURL calls the REST API directly, nothing to install.npm install @trustcomponent/sdkcomposer require trustcomponent/trustcomponent-phppip install trustcomponent<!-- 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>dotnet add package TrustComponentgo get github.com/trustcomponent/trustcomponent-gogem install trustcomponentcargo add trustcomponentThen turn the token from the form field tc-verification-token into the result:
# 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>"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}use TrustComponent\TrustComponent;
$tc = new TrustComponent('<your_api_key>');
$result = $tc->captcha()->getVerificationResult($_POST['tc-verification-token']);if (!$result->isVerificationPassed()) { // reject the request}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 requestimport 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}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}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)}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 requestendlet 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.
The verification token
Section titled “The verification token”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:
eyJ2ZXJpZmljYXRpb25JZCI6IjA3YjAxOTIyLTNmYWEtNDY2Ny1hNGE2LTkxMGE3NmNiOGFiNyIsImV4cGlyZXNBdCI6IjIwMjYtMDUtMDNUMTM6NDU6MDguMjE0WiJ9{ "verificationId": "07b01922-3faa-4667-a4a6-910a76cb8ab7", "expiresAt": "2026-05-03T13:45:08.214Z"}| Key | Value | Description |
|---|---|---|
verificationId | UUID | Id of the verification, used to retrieve its result. |
expiresAt | Timestamp (UTC) | When the token, and with it the result, can no longer be retrieved. |
clientFailover | Boolean | Optional. 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.
The verification result
Section titled “The verification result”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.
{ "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.
Evaluate the result
Section titled “Evaluate the result”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:
if (!result.isVerificationPassed || result.score > 0.5) { // failed or likely automated: reject}if (!$result->isVerificationPassed() || $result->getScore() > 0.5) { // failed or likely automated: reject}if not result.is_verification_passed or result.score > 0.5: ... # failed or likely automated: rejectif (!result.isVerificationPassed() || result.getScore() > 0.5) { // failed or likely automated: reject}if (!result.IsVerificationPassed || result.Score > 0.5){ // failed or likely automated: reject}if !result.IsVerificationPassed || result.Score > 0.5 { // failed or likely automated: reject}if !result.is_verification_passed || result.score > 0.5 # failed or likely automated: rejectendif !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:
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}$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}score = result.scoreif not result.is_verification_passed or score >= 0.8: ... # rejectelif score >= 0.4: ... # elevated risk: ask for an e-mail confirmation or a second factorelse: ... # low risk: proceeddouble 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}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}switch score := result.Score; {case !result.IsVerificationPassed || score >= 0.8: // rejectcase score >= 0.4: // elevated risk: ask for an e-mail confirmation or a second factordefault: // low risk: proceed}score = result.scoreif !result.is_verification_passed || score >= 0.8 # rejectelsif score >= 0.4 # elevated risk: ask for an e-mail confirmation or a second factorelse # low risk: proceedendlet 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}The decision
Section titled “The decision”Two more fields explain how the outcome came about: decisionType names the mechanism, decisionAction what TrustCaptcha recommends.
decisionType | Description |
|---|---|
STANDARD | The regular validation decided (proof of work and risk score). |
BYPASS_KEY | The CAPTCHA was solved with a bypass key. |
CUSTOM_ACCESS_RULE | An access rule of this CAPTCHA matched, for example an allow or block list. |
GLOBAL_IP_ACCESS_RULE | A global TrustCaptcha access rule matched. |
FAILOVER | The CAPTCHA service was unreachable; the gateway answered with a tolerant result. |
FAILOVER_TOLERANCE | Shortly after an outage the service answered “not finished” or “not found”; the gateway still answered with a tolerant result. |
decisionAction | Description |
|---|---|
ALLOW | Allow the request. |
BLOCK | Block the request. |
CUSTOM | A rule with a custom action matched; your CAPTCHA settings tell which one. |
Errors
Section titled “Errors”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):
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; }}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)}from trustcomponent import ConnectionError, ServerError, TrustComponentError
try: result = tc.captcha.get_verification_result(token) # evaluate the resultexcept (ConnectionError, ServerError): ... # TrustCaptcha unreachable: apply your failover decisionexcept TrustComponentError as e: ... # not verified: reject (e.status and e.code tell why)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)}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)}result, err := tc.Captcha.GetVerificationResult(ctx, token)var connErr *trustcomponent.ConnectionErrorvar apiErr *trustcomponent.Errorswitch {case err == nil: // evaluate the resultcase errors.As(err, &connErr), errors.As(err, &apiErr) && apiErr.IsServer(): // TrustCaptcha unreachable: apply your failover decisiondefault: // not verified: reject}begin result = tc.captcha.get_verification_result(token) # evaluate the resultrescue TrustComponent::ConnectionError, TrustComponent::ServerError # TrustCaptcha unreachable: apply your failover decisionrescue TrustComponent::Error => e # not verified: reject (e.status and e.code tell why)enduse 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 */ }}Configuration
Section titled “Configuration”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.
Test your integration
Section titled “Test your integration”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 id | Answer |
|---|---|
00000000-0000-0000-0000-000000000000 | 200, a passed result with score 0.3 |
00000000-0000-0000-0000-000000000001 | 404, no verification with this id |
00000000-0000-0000-0000-000000000002 | 409, result_not_released |
00000000-0000-0000-0000-000000000003 | 410, result_expired |
00000000-0000-0000-0000-000000000004 | 410, 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.