CastleToken
Guide for solving Castle captchas with proxy support
Castle is a bot detection service commonly found on gaming and authentication platforms. This task type solves Castle challenges and returns session tokens.
For solving without proxy, see CastleTokenProxyLess.
Finding Castle Parameters
Paste this script into your browser console on the target page. It automatically detects all required Castle parameters:
(() => {
const r = { pk: null, wUrl: null, swUrl: null };
// Find pk
if (window._env?.pk) r.pk = window._env.pk;
if (!r.pk) {
const s = document.querySelector('script[data-config]');
if (s)
try {
r.pk = JSON.parse(s.dataset.config)?.castle?.publishableKey ?? null;
} catch {}
}
if (!r.pk) {
const m = document.documentElement.innerHTML.match(/publishableKey["']?\s*[:=]\s*["']([^"']+)["']/);
if (m) r.pk = m[1];
}
// Find wUrl (cw.js) and swUrl (csw.js)
document.querySelectorAll('script[src]').forEach((s) => {
if (s.src.endsWith('cw.js')) r.wUrl = s.src;
if (s.src.endsWith('csw.js')) r.swUrl = s.src;
});
if (!r.wUrl || !r.swUrl) {
performance.getEntriesByType('resource').forEach((e) => {
if (!r.wUrl && e.name.endsWith('cw.js')) r.wUrl = e.name;
if (!r.swUrl && e.name.endsWith('csw.js')) r.swUrl = e.name;
});
}
console.log('Castle params:', JSON.stringify(r, null, 2));
return r;
})();Manual Methods
If the automatic script doesn't find everything, use these manual approaches.
Publishable Key (websiteKey)
Elements tab — Open DevTools → Elements, press Ctrl + F, and search for pk or publishableKey.

window._env — Some sites expose the key on window._env. Run in console:
window._env?.pk ?? 'Not found';
data-config attribute — Extract from a script tag's config:
JSON.parse(document.querySelector('script[data-config]')?.dataset.config)?.castle?.publishableKey;
Script URLs (wUrl and swUrl)
Open DevTools → Network tab, trigger the Castle challenge, then filter for cw.js and csw.js. Copy the full URL of each request.

Token Count
The optional count parameter lets you request 1–49 tokens per request (default: 1). All tokens share the same __cuid session.
Supported Providers
| Provider | Price per 1,000 |
|---|---|
| $0.60 |
Request Schema
| Field | Type | Description |
|---|---|---|
clientKey* | string | Your API key from the AnySolver dashboard. Example: |
task* | object | |
provider | Specific provider to use. If omitted, automatic routing selects the best provider. Example: | |
selectionMode | Read more at the routing strategies docs. Example: | |
keyPoolMode | Example: |
Task Object Properties
The task field accepts an object with the following properties:
| Field | Type | Description |
|---|---|---|
websiteURL* | URL | Full URL of the page where the CAPTCHA is displayed. Example: |
websiteKey* | string | Castle Publishable Key. Example: |
wUrl* | URL | Link to the Castle cw.js script. Example: |
swUrl* | URL | Link to the Castle csw.js service worker script. Example: |
count | number | Number of tokens to generate with the same browser session (same __cuid identifier) (1-49, default 1). Example: |
userAgent | string | Browser User-Agent string. Must match the browser used on the target page. Not all providers properly support this parameter. Verify the compatibility with the provider you are using. |
proxy* | string | object |
Response Schema
| Field | Type | Description |
|---|---|---|
status* | Task status: "processing", "ready", or "failed". Example: | |
taskId | string | Unique identifier returned when the task was created. Example: |
errorId* | 0 = success, 1 = external error, 2 = internal error. Example: | |
errorCode | Machine-readable error code (e.g., "CAPTCHA_UNSOLVABLE"). Example: | |
errorDescription | string | Human-readable error message with resolution hints. Example: |
cost | number | Actual cost charged for this task in USD. Example: |
taskType | The type of CAPTCHA task to solve. Example: | |
provider | Specific provider to use. If omitted, automatic routing selects the best provider. Example: | |
solution | object |
Solution Object Properties
The solution field contains an object with the following properties:
| Field | Type | Description |
|---|---|---|
tokens* | string[] | Array of Castle tokens returned by the solver. Example: |
cuid | string | The __cuid cookie value extracted from the Castle response. |
raw* | Record<string, unknown> | Raw provider response data for advanced use cases. |