Skip to content

Castle

Generate the request token for your account-security flow. Capture the publishable Castle.configure object and the page where the SDK runs. Preserve site-specific configuration and the identity of the protected action.

POST /createTask · example
{
  "clientKey": "capzy_YOUR_API_KEY",
  "task": {
    "type": "CastleTask",
    "websiteURL": "https://your-target-site.com/signup",
    "config_json": {
      "pk": "pk_XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "wUrl": "https://cdn.your-target-site.com/castle/cw.js",
      "swUrl": "https://cdn.your-target-site.com/castle/csw.js",
      "avoidCookies": true
    },
    "proxyType": "http",
    "proxyAddress": "123.45.67.89",
    "proxyPort": "8080",
    "proxyLogin": "user",
    "proxyPassword": "pass"
  }
}

Illustrative values. Replace the inputs with values from your current integration.

Page URL + SDK configurationProxyless or your own proxyCastle token + client identity

Capture the Castle SDK configuration.

Capture the publishable Castle.configure object and the page where the SDK runs. Preserve site-specific configuration and the identity of the protected action.

Your API key authenticates Capzy.
Provider keys, challenge IDs, images, and session values belong inside task.

Copy the complete publishable configuration.

  1. Search Sources or your application code for Castle.configure. Copy its configuration object into config_json.
  2. Keep pk and supplied wUrl, swUrl, avoidCookies, and other site options with their original types.
  3. Use the exact page URL where Castle runs as websiteURL. For a bundled SDK needing an explicit loader, place its URL inside config_json.sdkUrl.
Input collection example - replace illustrative values
{
  "websiteURL": "https://example.com/signup",
  "config_json": {
    "pk": "YOUR_PUBLISHABLE_PK",
    "wUrl": "https://example.com/YOUR_CW_SCRIPT",
    "swUrl": "https://example.com/YOUR_CSW_SCRIPT"
  }
}

config_json must be an object. Only send script overrides your actual integration uses.

How Castle works

Castle (castle.io) is an account-security and fraud-prevention SDK used by gaming platforms, fintech, and e-commerce sites. It is not a traditional captcha — there is no visible puzzle. Instead, Castle's JavaScript SDK silently collects behavioral fingerprints and device signals, then exposes a createRequestToken() method that produces a short-lived risk-scored token. The token is sent from the client to the site's backend as the HTTP header x-castle-request-token or the hidden form field castle_request_token. The backend validates it against Castle's API, which returns a risk action: allow, challenge, or deny. Castle is commonly used at login, signup, checkout, and password-reset flows on gaming, fintech, and e-commerce sites. Tokens expire after 120 seconds and are single-use. They are bound to the __cuid session cookie — a persistent 16-byte random device identifier Castle stores in the browser. For cookie-enabled configurations, send the matching __cuid alongside the token. When avoidCookies is enabled and the result cuid is empty, keep the configured cookie-free flow.

Send websiteURL with the site's Castle.configure object, including its publishable pk and worker options. The default engine generates the request token in the configured SDK context; a browser fallback or backend=browser override loads the target page when needed. We return token, cuid, and userAgent. Use the merchant's request-token header or form field with the returned identity and the original session. Install cuid as __cuid when nonempty; avoidCookies configurations can legitimately return an empty cuid.

  • Navigates the real target page so Castle's SDK initialises exactly as for a real user
  • Works on modern bundled integrations (no window.Castle global), not just legacy global-SDK sites
  • Passes your full config_json including custom wUrl/swUrl worker scripts
  • Returns token, __cuid cookie, and matching User-Agent as a ready-to-use triple
  • Average solve time ~1 second
  • Works on all Castle-protected flows: login, signup, checkout, password reset

Know what goes in.

Choose a field to see its purpose, where to get it, and its place in the request. Optional values omitted from the example can be added when your flow uses them.

The request below follows your selected task configuration.

Request authentication

Required task inputs

Optional context

Proxy connection

websiteURL

stringRequired

The exact page URL where Castle is active (e.g. the login or signup page). Castle's SDK must load on this page.

Where it comes from

Copy the full page URL from the address bar or the document request in Network, including the path where this flow runs.

Open the input guide
Example valuehttps://your-target-site.com/signup
POST /createTask · selected configuration
{
  "clientKey": "capzy_YOUR_API_KEY",
  "task": {
    "type": "CastleTask",
    "websiteURL": "https://your-target-site.com/signup",
    "config_json": {
      "pk": "pk_XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "wUrl": "https://cdn.your-target-site.com/castle/cw.js",
      "swUrl": "https://cdn.your-target-site.com/castle/csw.js",
      "avoidCookies": true
    },
    "proxyType": "http",
    "proxyAddress": "123.45.67.89",
    "proxyPort": "8080",
    "proxyLogin": "user",
    "proxyPassword": "pass"
  }
}

The selected field is highlighted when present. Preserve the declared value type and current challenge context.

Make your first request.

Create the task, keep its taskId, and poll until status is ready. Then read the selected variant's solution.

More examples
  1. Create the task

    Send clientKey and the selected task to /createTask from your server. Keep the returned taskId.

  2. Wait for the solution

    Send that same key and ID to /getTaskResult. While processing, wait two seconds before checking again. Stop on Ready or an error.

  3. Apply the result

    Send solution.token in the application's Castle request-token transport, commonly x-castle-request-token. Preserve solution.cuid as __cuid when expected, and solution.userAgent with the original session.

CastleTask · $1.00 / 1,000
solve_castle.py
import json, os, time
import requests

API = "https://api.capzy.ai"
KEY = os.environ["CAPZY_API_KEY"]
task = json.loads("{\"type\":\"CastleTask\",\"websiteURL\":\"https://your-target-site.com/signup\",\"config_json\":{\"pk\":\"pk_XXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"wUrl\":\"https://cdn.your-target-site.com/castle/cw.js\",\"swUrl\":\"https://cdn.your-target-site.com/castle/csw.js\",\"avoidCookies\":true},\"proxyType\":\"http\",\"proxyAddress\":\"123.45.67.89\",\"proxyPort\":\"8080\",\"proxyLogin\":\"user\",\"proxyPassword\":\"pass\"}")

def call(path, payload):
    response = requests.post(f"{API}/{path}", json={"clientKey": KEY, **payload}, timeout=30)
    response.raise_for_status()
    data = response.json()
    if data.get("errorId", 0) or data.get("status") == "failed":
        raise RuntimeError(data.get("errorDescription") or data.get("errorCode") or "Task failed")
    return data

created = call("createTask", {"task": task})
for attempt in range(60):
    result = call("getTaskResult", {"taskId": created["taskId"]})
    if result.get("status") == "ready":
        solution = result["solution"]
        print(solution)
        break
    time.sleep(2)
else:
    raise TimeoutError("Task is still processing; keep the taskId to check it later.")

Before runningReplace all illustrative inputs with your captured values. Set CAPZY_API_KEY in your environment. Install requests with pip install requests.

Polling and failuresThe example checks HTTP/API failures, uses 30-second request timeouts, and stops after 60 result checks. Retain taskId if your task is still processing.

Understand what comes back.

Follow this task from creation to completion. Response fields and usage follow your selected request variant.

Castle token + client identity

Send solution.token in the application's Castle request-token transport, commonly x-castle-request-token. Preserve solution.cuid as __cuid when expected, and solution.userAgent with the original session.

string
The Castle request token. Set this as the x-castle-request-token header (or castle_request_token form field) on your follow-up request. 120-second TTL, single-use.
string
Value of the __cuid cookie bound to the token. You must send Cookie: __cuid=<cuid> on the same request as the token, or Castle will flag it as spoofed. Empty when the site uses avoidCookies: true.
string
The User-Agent of the browser that generated the token. Set this on your follow-up request to keep the fingerprint coherent.
POST /getTaskResult · example response
{
  "errorId": 0,
  "status": "ready",
  "solution": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdWlkIjoiYWJjMTIzZGVmNDU2Nzg5MCIsImlhdCI6MTcyMDAwMDAwMCwiZXhwIjoxNzIwMDAwMTIwfQ.SigPlaceholder",
    "cuid": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
  }
}

Illustrative values. Additional metadata may be returned; only Ready contains a completed solution.

Attach the Castle request identity

Send the request token with its matching user-agent and __cuid cookie when present. Use the header or form field expected by your application. For avoidCookies integrations, an empty cuid does not require a cookie. Node.js uses your existing browser context and headers.

Execution context result is the parsed Ready response from the polling example. session, when referenced, is your existing requests.Session (or browser-compatible session) with the original cookie jar, headers, and solving proxy configured in session.proxies for both http and https. Keep this client for the complete flow. task is the task object you submitted. For Shape, action_body is the original protected request body as bytes or a string, with its original Content-Type in session.headers. Install curl_cffi when the fragment imports it; match the target's required browser/TLS identity.

Use the result · Python
sol = result["solution"]
headers = {"x-castle-request-token": sol["token"], "User-Agent": sol["userAgent"]}
cookies = {"__cuid": sol["cuid"]} if sol.get("cuid") else {}
# session is your existing client with the original network configuration.
response = session.post("https://target.example.com/signup", headers=headers,
    cookies=cookies, json={"email": "YOUR_EMAIL"}, timeout=30)

When something doesn't work.

Check your captured values, the selected variant, and the response before starting another task.

Where do I find the publishable key (pk)?

Inspect the page source or Network tab. The pk appears in the Castle SDK script URL as a query parameter (e.g. cdn.castle.io/v2/castle.js?pk_XXXX) or in a Castle.configure() call in the page's own JavaScript. It always starts with pk_.

What is the config_json field?

It is the object passed to Castle.configure() on the target site. The pk field is the minimum requirement. Some sites add wUrl / swUrl (custom CDN paths for Castle's worker scripts) or avoidCookies: true. Copy these values from the site's source — they vary per site and are required for the solver to replicate the exact Castle context.

The site doesn't expose window.Castle — does the solver still work?

Yes. Modern sites bundle Castle as an ES module and call Castle.configure(...).createRequestToken() in module scope, so there is no window.Castle global. The solver detects this and loads the Castle browser SDK itself, configuring it with your config_json (pk plus any wUrl/swUrl), and also captures the x-castle-request-token the page mints on its own requests as a fallback. If a specific bundled site needs a particular SDK build, pass config_json.sdkUrl with its URL.

Do I really need to send the __cuid cookie?

Yes, unless the site set avoidCookies: true in its Castle config. Castle's server-side validation checks that the __cuid cookie in the request matches the one embedded in the token. Sending the token without the matching cookie causes InvalidRequestTokenError on Castle's API, which the site treats as a suspected bot.

How do I use the token on my follow-up request?

Set three things on the same HTTP request that submits the form or calls the API: (1) the header x-castle-request-token: <token>, (2) Cookie: __cuid=<cuid>, (3) User-Agent: <userAgent>. Using a matching TLS stack (curl_cffi or a real browser) helps keep the full fingerprint coherent.

Can I reuse the token?

No. Castle tokens are single-use and expire after 120 seconds. Call us fresh for each protected request.

Do I need a proxy for Castle?

The default fast engine can use ip to align its context with the IP that will submit the token. If you supply a proxy, keep its exit for submission. Leave backend unset for the default engine; use browser only when your integration needs that override.

Integration checks for Castle
  • Send all three values together: token as x-castle-request-token, __cuid as a cookie, and match the returned User-Agent. Sending the token without the cuid cookie triggers InvalidRequestTokenError server-side.
  • Tokens expire in 120 seconds and are single-use. Generate a fresh one for each protected request — do not cache or reuse.

Connect Castle to your workflow.

Get your Capzy API key and use this guide's integration.

$1.00Per 1,000 solves
4.2sAverage solve time

CastleTask · Live configuration