
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
rapidcaptcha
Advanced tools
Official JavaScript SDK for RapidCaptcha API - Solve Turnstile and reCAPTCHA with high success rates
Official JavaScript SDK for the RapidCaptcha API - Solve Turnstile and reCAPTCHA with high success rates.
npm install rapidcaptcha
yarn add rapidcaptcha
<script src="https://unpkg.com/rapidcaptcha@latest/dist/browser.js"></script>
import { RapidCaptchaClient } from "rapidcaptcha";
const client = new RapidCaptchaClient("Rapidcaptcha-your-api-key");
// Solve Turnstile
const result = await client.solveTurnstile("https://example.com", {
autoDetect: true,
});
if (result.isSuccess) {
console.log("Token:", result.turnstileValue);
} else {
console.log("Failed:", result.reason);
}
<script src="https://unpkg.com/rapidcaptcha@latest/dist/browser.js"></script>
<script>
const client = new RapidCaptcha.RapidCaptchaClient(
"Rapidcaptcha-your-api-key"
);
client.solveTurnstile("https://example.com").then((result) => {
if (result.isSuccess) {
console.log("Token:", result.turnstileValue);
}
});
</script>
import { RapidCaptchaClient, CaptchaResult } from "rapidcaptcha";
const client = new RapidCaptchaClient("Rapidcaptcha-your-api-key");
const result: CaptchaResult = await client.solveTurnstile(
"https://example.com",
{
autoDetect: true,
pollInterval: 2000,
}
);
const client = new RapidCaptchaClient(apiKey, options);
Options:
baseUrl
(string): API base URL (default: "https://rapidcaptcha.xyz")timeout
(number): Request timeout in milliseconds (default: 300000)maxRetries
(number): Maximum retry attempts (default: 3)retryDelay
(number): Delay between retries in milliseconds (default: 2000)// Basic usage with auto-detection
const result = await client.solveTurnstile("https://example.com");
// With manual sitekey
const result = await client.solveTurnstile("https://example.com", {
sitekey: "0x4AAAAAAABkMYinukE8nzKd",
action: "submit",
autoDetect: false,
});
// Basic usage
const result = await client.solveRecaptcha("https://example.com");
// With manual sitekey
const result = await client.solveRecaptcha("https://example.com", {
sitekey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
});
// Submit task
const taskId = await client.submitTurnstile("https://example.com", {
autoDetect: true,
});
// Get result
const result = await client.getResult(taskId);
// Wait for completion
const result = await client.waitForResult(taskId, 2000); // Poll every 2 seconds
import { solveTurnstile, solveRecaptcha } from "rapidcaptcha";
// One-liner solutions
const turnstileResult = await solveTurnstile(
"Rapidcaptcha-your-key",
"https://example.com"
);
const recaptchaResult = await solveRecaptcha(
"Rapidcaptcha-your-key",
"https://example.com"
);
const urls = ["https://site1.com", "https://site2.com", "https://site3.com"];
const promises = urls.map((url) =>
client.solveTurnstile(url, { autoDetect: true })
);
const results = await Promise.allSettled(promises);
results.forEach((result, index) => {
if (result.status === "fulfilled" && result.value.isSuccess) {
console.log(`Site ${index + 1}: Success`);
} else {
console.log(`Site ${index + 1}: Failed`);
}
});
import {
APIKeyError,
ValidationError,
RateLimitError,
TimeoutError,
} from "rapidcaptcha";
try {
const result = await client.solveTurnstile("https://example.com");
if (result.isSuccess) {
console.log("Token:", result.turnstileValue);
} else {
console.log("Solve failed:", result.reason);
}
} catch (error) {
if (error instanceof APIKeyError) {
console.error("Invalid API key");
} else if (error instanceof RateLimitError) {
console.error("Rate limit exceeded");
} else if (error instanceof TimeoutError) {
console.error("Operation timed out");
} else {
console.error("Unexpected error:", error.message);
}
}
async function solveWithRetry(url, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const result = await client.solveTurnstile(url);
if (result.isSuccess) {
return result;
}
if (attempt === maxRetries) {
throw new Error(
`Failed after ${maxRetries} attempts: ${result.reason}`
);
}
console.log(`Attempt ${attempt} failed, retrying...`);
await new Promise((resolve) => setTimeout(resolve, 2000));
} catch (error) {
if (error instanceof RateLimitError && attempt < maxRetries) {
console.log("Rate limited, waiting before retry...");
await new Promise((resolve) => setTimeout(resolve, 5000));
continue;
}
throw error;
}
}
}
// Custom configuration
const client = new RapidCaptchaClient("Rapidcaptcha-your-key", {
timeout: 120000, // 2 minutes
maxRetries: 5, // More retries
retryDelay: 3000, // 3 second delay
baseUrl: "https://rapidcaptcha.xyz",
});
// Health check
const health = await client.healthCheck();
console.log("API Status:", health.status);
The CaptchaResult
object contains comprehensive information about the solving attempt:
{
taskId: "task-123", // Task identifier
status: "success", // "pending", "success", or "error"
token: "abc123...", // reCAPTCHA token (if applicable)
turnstileValue: "0.abc...", // Turnstile token (if applicable)
elapsedTimeSeconds: 15.2, // Time taken to solve
sitekeyUsed: "0x4AAAA...", // Sitekey that was used
sitekeysTried: ["0x4A..."], // All sitekeys attempted
reason: "Solved successfully", // Error reason (if failed)
errors: [], // Detailed errors (if any)
completedAt: "2024-01-01T..." // Completion timestamp
}
// Helper methods
result.isSuccess // true if solved successfully
result.isError // true if solving failed
result.isPending // true if still in progress
The SDK provides specific error types for different scenarios:
APIKeyError
- Invalid or missing API keyValidationError
- Invalid request parametersTaskNotFoundError
- Task ID not found or expiredRateLimitError
- Rate limit exceededTimeoutError
- Operation timed outRapidCaptchaError
- Base error classThe SDK includes complete TypeScript definitions:
import type {
CaptchaResult,
ClientOptions,
TurnstileOptions,
RecaptchaOptions,
} from "rapidcaptcha";
The RapidCaptcha API has rate limits. The SDK automatically handles rate limit errors and provides appropriate error types. For high-volume usage:
Check out the /examples
directory for more comprehensive examples:
/examples/nodejs/
/examples/browser/
/examples/typescript/
# Install dependencies
npm install
# Run tests
npm test
# Run browser tests
npm run test:browser
# Run with coverage
npm run test:coverage
export RAPIDCAPTCHA_API_KEY="Rapidcaptcha-your-key"
npm run example
open tests/browser.test.html
# Clone repository
git clone https://github.com/RapidCaptcha-SDK/RapidCaptcha-JavaScript.git
cd RapidCaptcha-JavaScript
# Install dependencies
npm install
# Build all formats
npm run build
# Build specific format
npm run build:es # ES modules
npm run build:cjs # CommonJS
npm run build:umd # Browser UMD
git checkout -b feature-name
npm test
git commit -am 'Add feature'
git push origin feature-name
For complete API documentation, visit: https://rapidcaptcha.xyz/docs
This project is licensed under the MIT License - see the LICENSE file for details.
A: Sign up at rapidcaptcha.xyz to get your API key.
A: Auto-detection automatically finds the sitekey from the page, while manual mode requires you to specify the sitekey. Auto-detection is more convenient but may be slower.
A: Yes! The SDK supports concurrent solving. Use Promise.all()
or Promise.allSettled()
with multiple solve calls.
A: Typical solve times range from 10-30 seconds, depending on the CAPTCHA complexity and server load.
A: Yes, rate limits depend on your subscription plan. The SDK automatically handles rate limit errors.
A: Absolutely! The SDK is production-ready with comprehensive error handling, TypeScript support, and extensive testing.
A: All modern browsers are supported. See the Browser Support section for specific versions.
Made with ❤️ by the RapidCaptcha team
FAQs
Official JavaScript SDK for RapidCaptcha API - Solve Turnstile and reCAPTCHA with high success rates
The npm package rapidcaptcha receives a total of 2 weekly downloads. As such, rapidcaptcha popularity was classified as not popular.
We found that rapidcaptcha demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.