The ultimate API solution for generating valid Castle.io tokens for X (Twitter) automation. High throughput, low latency, and seamless integration for automated workflows.
| Parameter | Type | Required | Description |
|---|---|---|---|
cuid | string | No | UUID v4 format (32 hex chars without dashes). Auto-generated if not provided. ? Set as __cuid cookie. |
userAgent | string | Yes | Browser UA. Chrome 140+ recommended. |
country | string | No | ISO Country Code (e.g. US, GB). Default: US |
browser | string | No | Browser type: chrome, brave, edge, opera. Auto-detected from sec-ch-ua if not provided, or random if not available. |
version | string | No | Browser version (e.g. "131"). Auto-detected from sec-ch-ua or parsed from userAgent. |
sec-ch-ua | string | No | Client Hints header value. Can be passed in body or as HTTP header. Used to auto-detect browser and version. |
public_key | string | No | Castle public key. Default: pk_AvRa79bHyJSYSQHnRpcVtzyxetSvFerx (Twitter/X) |
domain | string | No | Target domain for token. Default: x.com. Change for other Castle-protected sites. |
const cuid = crypto.randomUUID().replace(/-/g, '');
curl -X POST https://castle.botwitter.com/generate-token \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "cuid": "550e8400e29b41d4a716446655440000", "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)...", "country": "US", "sec-ch-ua": "\"Chromium\";v=\"131\", \"Google Chrome\";v=\"131\"", "public_key": "pk_AvRa79bHyJSYSQHnRpcVtzyxetSvFerx", "domain": "x.com" }' // Response: { "success": true, "token": "eyJhbG...", "cuid": "550e8400e29b41d4a716446655440000", "cuidGenerated": false, "domain": "x.com", "headers": { "sec-ch-ua": "\"Chromium\";v=\"131\", \"Google Chrome\";v=\"131\"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "\"Windows\"" } }
The API returns Client Hints headers that you should use with Twitter/X requests:
| Header | Example Value | Description |
|---|---|---|
sec-ch-ua | "Chromium";v="131", "Google Chrome";v="131" | User-Agent Client Hints - Browser brands and versions |
sec-ch-ua-mobile | ?0 | Mobile device indicator (?0 = desktop, ?1 = mobile) |
sec-ch-ua-platform | "Windows" | Operating system platform |
Need a custom enterprise plan or have technical questions?