### Complete Configuration Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/configuration.md A comprehensive example demonstrating various configuration options including AppId, verbosity, API URL, and polling delay. This snippet also shows how to use the configured solver to solve a ReCaptcha task. ```javascript const CapSolver = require('node-capsolver'); const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', { appId: 'my-app-id-123', verbose: true, verboseIdentifier: '[CapSolver]', apiUrl: 'https://api.capsolver.com', delay: 1500 }); // Use the configured solver const result = await solver.solve({ type: 'ReCaptchaV2TaskProxyLess', websiteURL: 'https://example.com', websiteKey: 'sitekey' }); ``` -------------------------------- ### Install node-capsolver using pnpm Source: https://github.com/novationa-z/node-capsolver/blob/main/readme.md Install the node-capsolver package using pnpm. ```bash pnpm add node-capsolver ``` -------------------------------- ### Install node-capsolver using yarn Source: https://github.com/novationa-z/node-capsolver/blob/main/readme.md Install the node-capsolver package using yarn. ```bash yarn add node-capsolver ``` -------------------------------- ### Install node-capsolver using npm Source: https://github.com/novationa-z/node-capsolver/blob/main/readme.md Install the node-capsolver package using npm. ```bash npm install node-capsolver ``` -------------------------------- ### POST /getToken Response Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md This is an example of a successful response from the /getToken endpoint, containing the ReCaptcha token. ```json { "errorId": 0, "errorCode": "string", "errorDescription": "string", "status": "ready", "solution": { "gRecaptchaResponse": "token_string" }, "taskId": "abc123def456" } ``` -------------------------------- ### Example of Pre-processing Image Buffers Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/architecture.md Demonstrates how to read an image file into a Buffer and how the PreProcessTask function converts it to a base64 string suitable for API submission. ```javascript const fs = require('fs'); // User passes Buffer const imageBuffer = fs.readFileSync('captcha.png'); const task = { type: 'ImageToTextTask', body: imageBuffer }; // PreProcessTask converts it task.body = imageBuffer.toString('base64'); // Now base64 string // Sent to API ``` -------------------------------- ### Runtime Configuration Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/configuration.md Illustrates that configuration is immutable after instance creation. To change settings, a new instance must be created with the desired configuration. ```javascript // Initial configuration const solver1 = new CapSolver(key, { delay: 1000 }); // ... use solver1 ... // Need different settings? Create a new instance const solver2 = new CapSolver(key, { delay: 5000 }); // ... use solver2 ... ``` -------------------------------- ### Buffer Conversion Usage Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Example showing how to convert image data to a buffer before sending it to the solver, useful when dealing with local image files. ```javascript const capsolver = require('@capsolver/node-capsolver'); const fs = require('fs'); const path = require('path'); async function solveWithBuffer() { const solver = new capsolver.Solver('YOUR_CLIENT_KEY'); const imagePath = path.join(__dirname, 'path/to/your/image.png'); // Replace with actual path try { const imageBuffer = fs.readFileSync(imagePath); const base64Image = imageBuffer.toString('base64'); const result = await solver.solve(capsolver.Task.ImageToTextTask, { body: base64Image, }); console.log('Captcha solved from buffer:', result.solution.text); } catch (error) { console.error('Error solving captcha from buffer:', error); } } // solveWithBuffer(); // Uncomment to run ``` -------------------------------- ### POST /getToken Request Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md This is an example of the JSON payload to send to the /getToken endpoint for ReCaptcha tasks. ```json { "clientKey": "CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "appId": "6B27D516-3A6F-4E13-9DED-F517295F5F89", "task": { "type": "ReCaptchaV2TaskProxyLess", "websiteURL": "https://example.com", "websiteKey": "sitekey" } } ``` -------------------------------- ### Create Task Request Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md The initial step in solving a captcha involves sending a POST request to the /createTask endpoint with clientKey, appId, and task details. ```http POST /createTask { clientKey, appId, task } → { errorId, taskId, status: null } ``` -------------------------------- ### Provide Feedback on Task Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md Optionally, you can provide feedback on a completed task by sending a POST request to the /feedbackTask endpoint with the taskId and result. ```http POST /feedbackTask { clientKey, appId, taskId, result } → { errorId, message } ``` -------------------------------- ### Handling Invalid API Key Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/errors.md This example shows how to initialize the Capsolver client with an API key and check for the 'ERROR_INVALID_API_KEY' error when fetching the balance. If the key is invalid, it logs an error message directing the user to the dashboard. ```javascript const apiKey = 'CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Valid format const solver = new CapSolver(apiKey); const balance = await solver.getBalance(); if (balance.errorCode === 'ERROR_INVALID_API_KEY') { console.error('API key is invalid. Check dashboard.capsolver.com'); } ``` -------------------------------- ### Solve ImageToTextTask with Node-Capsolver Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-reference-capsolver.md Use the `solve` method to resolve an ImageToTextTask. This example demonstrates reading an image file and sending it to the solver. Ensure you have a valid balance before proceeding. ```javascript const CapSolver = require('node-capsolver'); const fs = require('fs'); const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', { verbose: true, verboseIdentifier: '[Image Solve]' }); const balance = await solver.getBalance(); if (balance.balance > 0) { const result = await solver.solve({ type: 'ImageToTextTask', body: fs.readFileSync('captcha.png') // Buffer auto-converted to base64 }); if (result.errorId === 0) { console.log(`Captcha text: ${result.solution.text}`); } } ``` -------------------------------- ### Solve ReCaptchaV2TaskProxyLess with CapSolver Source: https://github.com/novationa-z/node-capsolver/blob/main/readme.md Solve a ReCaptchaV2 challenge using the CapSolver library without a proxy. This example first fetches the site key from a demo page before initiating the solve task. Check your balance before proceeding. ```javascript const CapSolver = require('node-capsolver') const axios = require("axios").default; const { JSDOM } = require('jsdom'); (async () => { let demoURL = "https://www.google.com/recaptcha/api2/demo"; let resp = await axios({ method: "GET", url: demoURL, }) const dom = new JSDOM(resp.data) const siteKey = dom.window.document.querySelector('#recaptcha-demo').getAttribute('data-sitekey'); const handler = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', { verbose: true // Optional }) let b = await handler.getBalance(); if (b.balance > 0) { let CapResponse = await handler.solve({ type: 'ReCaptchaV2TaskProxyLess', websiteURL: demoURL, websiteKey: `${siteKey}`, }) console.log(CapResponse) } else { console.log("Insufficient balance.") } })(); ``` -------------------------------- ### Poll Task Result Request Example (Complete) Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md Once the captcha is solved, the /getTaskResult endpoint will return a status of 'ready' along with the solution details. ```http POST /getTaskResult { clientKey, taskId } → { errorId, status: "ready", solution, taskId } ``` -------------------------------- ### Solving GeeTestTaskProxyLess Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Example for solving GeeTest captchas without needing a proxy. Requires website URL, challenge, and geetest_challenge parameters. ```javascript const capsolver = require('@capsolver/node-capsolver'); async function solveGeeTest() { const solver = new capsolver.Solver('YOUR_CLIENT_KEY'); try { const result = await solver.solve(capsolver.Task.GeeTestTaskProxyLess, { websiteURL: 'https://www.geetest.com/en/demo', challenge: 'YOUR_GEETEST_CHALLENGE', geetest_challenge: 'YOUR_GEETEST_CHALLENGE_VALUE', }); console.log('GeeTest solved:', result.solution.geetest_challenge, result.solution.geetest_validate, result.solution.seccode); } catch (error) { console.error('Error solving GeeTest:', error); } } // solveGeeTest(); // Uncomment to run ``` -------------------------------- ### Solve Image Captcha Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/quick-start.md Solve an image captcha by providing the image file. This example first checks the balance, then reads the captcha image from 'captcha.png' and prints the resulting text. Ensure you have sufficient balance before attempting to solve. ```javascript const CapSolver = require('node-capsolver'); const fs = require('fs'); const solver = new CapSolver('CAI-YOUR-API-KEY', { verbose: true }); (async () => { // Check balance first const balance = await solver.getBalance(); console.log(`Balance: $${balance.balance}`); if (balance.balance > 0) { // Solve image captcha const result = await solver.solve({ type: 'ImageToTextTask', body: fs.readFileSync('captcha.png') }); if (result.errorId === 0) { console.log(`Captcha text: ${result.solution.text}`); } else { console.error(`Failed: ${result.errorDescription}`); } } else { console.error('Insufficient balance'); } })(); ``` -------------------------------- ### Error Handling Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Illustrates how to catch and handle errors that may occur during the captcha solving process. It's recommended to implement retry logic for transient errors. ```javascript const capsolver = require('@capsolver/node-capsolver'); async function handleErrors() { const solver = new capsolver.Solver('YOUR_CLIENT_KEY'); try { // ... attempt to solve captcha ... const result = await solver.solve(capsolver.Task.ImageToTextTask, { body: 'INVALID_IMAGE_DATA', }); console.log('Captcha solved:', result.solution.text); } catch (error) { if (error.message.includes('ERROR_ZERO_BALANCE')) { console.error('Error: Insufficient balance. Please top up your account.'); } else { console.error('An unexpected error occurred:', error); } } } handleErrors(); ``` -------------------------------- ### Solving ReCAPTCHA v3 Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Example for solving ReCAPTCHA v3. Similar to v2, it requires the website URL and site key, but also accepts an optional action parameter. ```javascript const capsolver = require('@capsolver/node-capsolver'); async function solveRecaptchaV3() { const solver = new capsolver.Solver('YOUR_CLIENT_KEY'); try { const result = await solver.solve(capsolver.Task.ReCaptchaV3Task, { websiteURL: 'https://www.google.com/recaptcha/api2/demo', websiteKey: '6Le-wvkSAAAAAPBMRTsnOou2t0eL5_f8_f4_f4_f4', action: 'homepage', minScore: 0.3, }); console.log('ReCAPTCHA v3 solved:', result.solution.gRecaptchaResponse); } catch (error) { console.error('Error solving ReCAPTCHA v3:', error); } } solveRecaptchaV3(); ``` -------------------------------- ### Solving ReCAPTCHA v2 Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Example of solving a ReCAPTCHA v2 challenge. This requires the website URL and the site key provided by the target website. ```javascript const capsolver = require('@capsolver/node-capsolver'); async function solveRecaptchaV2() { const solver = new capsolver.Solver('YOUR_CLIENT_KEY'); try { const result = await solver.solve(capsolver.Task.ReCaptchaV2Task, { websiteURL: 'https://www.google.com/recaptcha/api2/demo', websiteKey: '6Le-wvkSAAAAAPBMRTsnOou2t0eL5_f8_f4_f4_f4', }); console.log('ReCAPTCHA v2 solved:', result.solution.gRecaptchaResponse); } catch (error) { console.error('Error solving ReCAPTCHA v2:', error); } } solveRecaptchaV2(); ``` -------------------------------- ### Catching Network and Timeout Errors Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/errors.md Use a try-catch block to handle network-related exceptions such as connection timeouts, DNS failures, or SSL errors. This example shows how to log the error message and optionally implement retry logic. ```javascript try { const result = await solver.solve(task); if (result.errorId === 0) { return result.solution; } else { console.error(`API Error: ${result.errorDescription}`); } } catch (error) { // Network or other exception console.error(`Network error: ${error.message}`); // Optionally retry with exponential backoff } ``` -------------------------------- ### Using Multiple Solver Instances Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Shows how to create and manage multiple solver instances, potentially for different configurations or concurrent tasks. ```javascript const capsolver = require('@capsolver/node-capsolver'); const solver1 = new capsolver.Solver('KEY_1', { verbose: true }); const solver2 = new capsolver.Solver('KEY_2', { proxy: { host: 'proxy.example.com', port: 8080 }, }); async function useMultipleSolvers() { try { const result1 = await solver1.solve(capsolver.Task.ImageToTextTask, { body: 'IMAGE_DATA_1', }); console.log('Solver 1 result:', result1.solution.text); const result2 = await solver2.solve(capsolver.Task.ReCaptchaV2Task, { websiteURL: 'https://example.com', websiteKey: 'SITE_KEY_2', }); console.log('Solver 2 result:', result2.solution.gRecaptchaResponse); } catch (error) { console.error('Error using multiple solvers:', error); } } ``` -------------------------------- ### Constructor Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/MANIFEST.md Initializes a new CapSolver client instance with your API key and optional configuration. ```APIDOC ## new CapSolver(clientKey, options) ### Description Initializes a new CapSolver client instance. ### Parameters - **clientKey** (string) - Required - Your Capsolver API key. - **options** (object) - Optional - Configuration options for the client. - **appId** (string) - Optional - Application ID for specific services. - **verbose** (boolean) - Optional - Enables verbose logging. - **verboseIdentifier** (string) - Optional - Identifier for verbose logs. - **apiUrl** (string) - Optional - Custom API endpoint URL. - **delay** (number) - Optional - Default delay between polling attempts in milliseconds. ``` -------------------------------- ### Constructor Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Initializes a new instance of the Capsolver client. ```APIDOC ## Constructor ### Description Initializes a new instance of the Capsolver client. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **clientKey** (string) - Required - Your Capsolver API key. - **appId** (string) - Optional - Your application ID. - **verbose** (boolean) - Optional - Enables verbose logging. - **verboseIdentifier** (string) - Optional - A custom identifier for verbose logs. - **apiUrl** (string) - Optional - The base URL for the Capsolver API. - **delay** (number) - Optional - Delay in milliseconds between polling for task results. ``` -------------------------------- ### Missing Required Field Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/errors.md The library does not validate required fields before sending. The API returns errors for missing fields, which vary by task type. For example, `websiteURL` and `websiteKey` are required for `ReCaptchaV2TaskProxyLess`. ```javascript const result = await solver.solve({ type: 'ReCaptchaV2TaskProxyLess' // Missing: websiteURL, websiteKey }); // API returns error ``` -------------------------------- ### Initialize CapSolver with Default Configuration Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/architecture.md Instantiate the CapSolver class with only your client key to use the default configuration settings for API URL, delay, and headers. ```javascript const solver = new CapSolver('KEY'); // Internally: // #options = {} // #delay = 2500 // #client baseURL = 'https://api.capsolver.com' // #client headers = { 'Content-Type': 'application/json' } ``` -------------------------------- ### Get Token (Fast) Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/README.md Obtains a fast ReCaptcha token without the need for polling. ```APIDOC ## POST /getToken ### Description Fast ReCaptcha token retrieval (no polling required). ### Method POST ### Endpoint /getToken ### Parameters #### Request Body - **clientKey** (string) - Required - Your CapSolver API key. - **task** (object) - Required - The task object defining the captcha to solve. - **type** (string) - Required - The type of captcha (e.g., 'ReCaptchaV2TaskProxyLess'). - **websiteURL** (string) - Required - The URL of the website where the captcha is located. - **websiteKey** (string) - Required - The sitekey of the captcha. ### Request Example ```json { "clientKey": "YOUR_API_KEY", "task": { "type": "ReCaptchaV2TaskProxyLess", "websiteURL": "https://www.google.com", "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq1bi0A83DR715" } } ``` ### Response #### Success Response (200) - **token** (string) - The ReCaptcha token. #### Response Example ```json { "token": "FAST_CAPTCHA_TOKEN" } ``` ``` -------------------------------- ### Get Task Result Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/README.md Polls the CapSolver service for the result of a previously created task. ```APIDOC ## POST /getTaskResult ### Description Poll task status and retrieve the result. ### Method POST ### Endpoint /getTaskResult ### Parameters #### Request Body - **clientKey** (string) - Required - Your CapSolver API key. - **taskId** (string) - Required - The ID of the task to poll. ### Request Example ```json { "clientKey": "YOUR_API_KEY", "taskId": "123456789" } ``` ### Response #### Success Response (200) - **status** (string) - The current status of the task (e.g., 'processing', 'ready'). - **solution** (object) - The solution to the captcha if the status is 'ready'. - **gRecaptchaResponse** (string) - The reCAPTCHA response token. #### Response Example ```json { "status": "ready", "solution": { "gRecaptchaResponse": "TOKEN_FROM_SOLVED_CAPTCHA" } } ``` ``` -------------------------------- ### Initialize CapSolver Instance Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-reference-capsolver.md Instantiate the CapSolver class with your API key. Basic initialization requires only the client key. For advanced configurations, provide an options object. ```javascript const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); ``` ```javascript const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', { verbose: true, verboseIdentifier: '[CaptchaSolver]', delay: 3000, apiUrl: 'https://api-stable.capsolver.com' }); ``` -------------------------------- ### Facade vs. Low-Level API Calls Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/architecture.md Illustrates the simplified interface provided by the Facade pattern compared to making direct low-level API calls for task creation and result retrieval. ```javascript const result = await solver.solve(task); // One call ``` ```javascript const create = await solver.createTask(task); const result = await solver.getTaskResult(create.taskId); // (in polling loop) ``` -------------------------------- ### getToken() Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt A fast-path method to get a token for specific captcha types without explicit task creation and polling. ```APIDOC ## getToken() ### Description A fast-path method to get a token for specific captcha types without explicit task creation and polling. ### Method POST ### Endpoint /getToken (internally) ### Parameters #### Request Body - **type** (string) - Required - The type of captcha task (e.g., 'ReCaptchaV2Classification'). - **params** (object) - Required - Parameters specific to the task type. ### Request Example ```javascript const token = await capsolver.getToken({ type: 'ReCaptchaV2Classification', params: { websiteURL: 'https://example.com', sitekey: 'your_site_key' } }); console.log(`ReCAPTCHA token: ${token.gRecaptchaResponse}`); ``` ### Response #### Success Response (200) - **gRecaptchaResponse** (string) - The response token for reCAPTCHA tasks. ``` -------------------------------- ### Initialize CapSolver with Configuration Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/configuration.md Instantiate the CapSolver class with a client key and an optional configuration object to customize its behavior. The options parameter allows setting application ID, verbosity, API URL, and polling delay. ```javascript const solver = new CapSolver(clientKey, options); ``` -------------------------------- ### Get Task Result Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md Polls for the result of a previously created captcha task. This method can be called repeatedly until the task is complete. ```APIDOC ## POST /getTaskResult ### Description Polls for the result of a captcha solving task. ### Method POST ### Endpoint /getTaskResult ### Parameters #### Request Body - **clientKey** (string) - Required - Your Capsolver API key. - **taskId** (string) - Required - The ID of the task to get the result for. ### Request Example ```json { "clientKey": "YOUR_API_KEY", "taskId": "TASK_ID" } ``` ### Response #### Success Response (200) - **errorId** (integer) - Non-zero indicates error. - **status** (string) - The current status of the task (e.g., "ready", null). - **solution** (object) - The solution to the captcha if the task is ready. - **taskId** (string) - The ID of the task. #### Response Example ```json { "errorId": 0, "status": "ready", "solution": { ... }, "taskId": "TASK_ID" } ``` ``` -------------------------------- ### CapSolverTask Union Type Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/types.md Represents all supported task types for creating, solving, or getting tokens. It's a union of RecognitionTask and TokenTask. ```typescript CapSolverTask = RecognitionTask | TokenTask ``` -------------------------------- ### Get CapSolver Account Balance Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-reference-capsolver.md Retrieves the current account balance in USD. Use this to check your remaining credits before initiating tasks. ```javascript const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); const balance = await solver.getBalance(); if (balance.errorId === 0) { console.log(`Current balance: $${balance.balance}`); } else { console.error(`Error: ${balance.errorDescription}`); } ``` -------------------------------- ### Initialize Multiple Solvers with Different Keys Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/quick-start.md Instantiate multiple CapSolver clients, each with a unique API key and custom verbose options. Useful for managing different accounts or services. ```javascript const CapSolver = require('node-capsolver'); const solvers = { account1: new CapSolver('CAI-KEY-1', { verbose: true, verboseIdentifier: '[Account1]' }), account2: new CapSolver('CAI-KEY-2', { verbose: true, verboseIdentifier: '[Account2]' }) }; // Use by key const result = await solvers.account1.solve(task); ``` -------------------------------- ### Import CapSolver Class Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-reference-capsolver.md Import the CapSolver class from the node-capsolver library. This is the first step before initializing an instance. ```javascript const CapSolver = require('node-capsolver'); ``` -------------------------------- ### Node.js Capsolver Configuration with Logging Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/configuration.md Enable verbose logging during client initialization to see task creation, waiting periods, and solving status. The output provides real-time feedback on the captcha solving process. ```javascript const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', { verbose: true }); ``` -------------------------------- ### Environment Variables Configuration Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/configuration.md Demonstrates how to read API credentials and configuration options from environment variables. This approach enhances security and flexibility by externalizing sensitive information. ```javascript const CapSolver = require('node-capsolver'); // Read API key from environment const apiKey = process.env.CAPSOLVER_API_KEY; const appId = process.env.CAPSOLVER_APP_ID; const solver = new CapSolver(apiKey, { appId: appId, verbose: process.env.CAPSOLVER_VERBOSE === 'true' }); ``` -------------------------------- ### ReCaptcha Fast Path Endpoint Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md Use the /getToken endpoint for ReCaptcha tasks to get the token directly without polling. The response is always 'ready'. ```http POST /getToken { clientKey, appId, task } → { errorId, status: "ready", solution, taskId } ``` -------------------------------- ### Enable Debugging and Configure Options Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/configuration.md Configure a CapSolver instance with verbose logging enabled for detailed troubleshooting. This includes setting a custom identifier for logs and adjusting the polling delay. ```javascript const solver = new CapSolver(key, { verbose: true, verboseIdentifier: '[DEBUG]', delay: 2500 // Monitor polling intervals }); // All task operations will now log detailed status ``` -------------------------------- ### Task Type Validation Example Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/errors.md The library does not validate task types at runtime; the API will reject invalid types. Ensure the `type` field is present and valid. ```javascript const result = await solver.solve({ type: 'InvalidTaskType', // API will reject this websiteURL: 'https://example.com' }); // Returns errorId: 1 with error code ``` -------------------------------- ### Task Object Construction (Builder Pattern) Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/architecture.md Demonstrates how task objects are constructed by users before being passed to API methods, showcasing the implicit Builder pattern. ```javascript const task = { type: 'ReCaptchaV2TaskProxyLess', websiteURL: 'https://example.com', websiteKey: 'sitekey' }; const result = await solver.solve(task); ``` -------------------------------- ### Configure Node-Capsolver with Environment Variables Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/quick-start.md Configure API key, verbosity, and polling delay using a .env file and the dotenv package. Ensure CAPSOLVER_API_KEY is set. ```javascript // Create .env file // CAPSOLVER_API_KEY=CAI-YOUR-API-KEY // CAPSOLVER_VERBOSE=true require('dotenv').config(); const CapSolver = require('node-capsolver'); const solver = new CapSolver(process.env.CAPSOLVER_API_KEY, { verbose: process.env.CAPSOLVER_VERBOSE === 'true', delay: parseInt(process.env.CAPSOLVER_POLL_DELAY || '2500') }); // Use solver... ``` -------------------------------- ### Solve ReCAPTCHA v2 with Proxy Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/quick-start.md Use this snippet to solve ReCAPTCHA v2 challenges when a proxy is required. Ensure you have the node-capsolver library installed and your API key is configured. ```javascript const CapSolver = require('node-capsolver'); const solver = new CapSolver('CAI-YOUR-API-KEY'); const result = await solver.solve({ type: 'ReCaptchaV2Task', websiteURL: 'https://example.com', websiteKey: 'sitekey', proxy: 'http://proxy-ip:proxy-port' // or socks5://... }); if (result.errorId === 0) { console.log('Success:', result.solution); } ``` -------------------------------- ### Minimal Node.js Capsolver Configuration Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/configuration.md Initialize the Capsolver client with only the required client key. This uses all default settings. ```javascript const CapSolver = require('node-capsolver'); const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); ``` -------------------------------- ### Manual Task Creation and Polling Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Demonstrates creating a task manually and then polling for its result. This provides more control over the task lifecycle. ```javascript const capsolver = require('@capsolver/node-capsolver'); async function manualTask() { const solver = new capsolver.Solver('YOUR_CLIENT_KEY'); try { const taskId = await solver.createTask(capsolver.Task.ImageToTextTask, { body: 'YOUR_IMAGE_URL_OR_BASE64', }); console.log('Task created with ID:', taskId); let result; while (!result) { await new Promise(resolve => setTimeout(resolve, 5000)); // Poll every 5 seconds result = await solver.getTaskResult(taskId); if (result && result.status === 'ready') { console.log('Task result:', result.solution.text); break; } } } catch (error) { console.error('Error with manual task:', error); } } manualTask(); ``` -------------------------------- ### Solve ReCAPTCHA v3 without Proxy Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/quick-start.md This example demonstrates solving ReCAPTCHA v3 challenges without using a proxy. It requires specifying the page action associated with the CAPTCHA. ```javascript const result = await solver.solve({ type: 'ReCaptchaV3TaskProxyLess', websiteURL: 'https://example.com', websiteKey: 'sitekey', pageAction: 'manage_account' // Page action from grecaptcha.execute() }); if (result.errorId === 0) { // Use token in form submission console.log(`Token: ${result.solution.gRecaptchaResponse}`); } ``` -------------------------------- ### Instantiate Multiple CapSolver Instances Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/architecture.md Demonstrates how to create and use multiple CapSolver instances concurrently for parallel captcha solving. Ensure you have the CapSolver class imported. ```javascript const solvers = [ new CapSolver('KEY-1'), new CapSolver('KEY-2'), new CapSolver('KEY-3') ]; // All can solve in parallel const results = await Promise.all( solvers.map(s => s.solve(task)) ); ``` -------------------------------- ### Solve ReCAPTCHA v2 Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/quick-start.md Solve a ReCAPTCHA v2 challenge. This example uses the 'ReCaptchaV2TaskProxyLess' type and requires the website URL and site key. The 'delay' option is set to 2000ms. ```javascript const CapSolver = require('node-capsolver'); const solver = new CapSolver('CAI-YOUR-API-KEY', { verbose: true, delay: 2000 }); (async () => { const result = await solver.solve({ type: 'ReCaptchaV2TaskProxyLess', websiteURL: 'https://www.google.com/recaptcha/api2/demo', websiteKey: '6Le-wvkSAAAAAPBMRTvw0Q75SqPaO30Xt7cKE9dA' }); if (result.errorId === 0) { console.log(`Token: ${result.solution.gRecaptchaResponse}`); } else { console.error(`Error: ${result.errorDescription}`); } })(); ``` -------------------------------- ### Diagnose Invalid Captcha Error in Node.js Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/errors.md This example shows how to detect an ERROR_INVALID_CAPTCHA by using an incorrect website key. It includes a conditional check to log a helpful message for debugging. ```javascript const result = await solver.solve({ type: 'ReCaptchaV2TaskProxyLess', websiteURL: 'https://example.com', websiteKey: 'INVALID_SITEKEY_12345' // Wrong key }); if (result.errorCode === 'ERROR_INVALID_CAPTCHA') { console.error('Check that websiteKey matches the target website'); } ``` -------------------------------- ### Get CapSolver Task Result Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-reference-capsolver.md Retrieves the current status and solution of a previously created task using its unique ID. Use this to poll for task completion and retrieve the captcha solution. ```javascript const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); const taskId = 'some-task-id'; const result = await solver.getTaskResult(taskId); if (result.status === 'ready') { console.log('Task completed:', result.solution); } else { console.log('Task still processing...'); } ``` -------------------------------- ### Proxy Configuration Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Configures the solver to use a proxy for solving tasks. Supports HTTP, HTTPS, SOCKS4, and SOCKS5 proxies. ```javascript const capsolver = require('@capsolver/node-capsolver'); async function solveWithProxy() { const solver = new capsolver.Solver('YOUR_CLIENT_KEY', { proxy: { type: 'http', host: 'YOUR_PROXY_HOST', port: 8080, username: 'YOUR_PROXY_USERNAME', password: 'YOUR_PROXY_PASSWORD', }, }); try { const result = await solver.solve(capsolver.Task.ImageToTextTask, { body: 'YOUR_IMAGE_URL_OR_BASE64', }); console.log('Captcha solved with proxy:', result.solution.text); } catch (error) { console.error('Error solving captcha with proxy:', error); } } solveWithProxy(); ``` -------------------------------- ### Solve ReCaptchaV2 (ProxyLess) Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/_START_HERE.md This snippet shows how to initialize the CapSolver client and solve a ReCaptchaV2 task without a proxy. Ensure you replace 'YOUR-API-KEY' with your actual API key. ```javascript const CapSolver = require('node-capsolver'); const solver = new CapSolver('YOUR-API-KEY'); const result = await solver.solve({ type: 'ReCaptchaV2TaskProxyLess', websiteURL: 'https://example.com', websiteKey: 'sitekey' }); if (result.errorId === 0) { console.log('Token:', result.solution.gRecaptchaResponse); } ``` -------------------------------- ### Poll Task Result Request Example (Pending) Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md After creating a task, poll the /getTaskResult endpoint periodically using the taskId to check its status. A status of null indicates the task is still processing. ```http POST /getTaskResult { clientKey, taskId } → { errorId, status: null } ``` -------------------------------- ### Buffer to Base64 Conversion for API Requests Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-reference-capsolver.md Demonstrates how to pass a Node.js Buffer object directly to the solver. The library automatically converts it to a base64 string before sending it to the CapSolver API. ```javascript const fs = require('fs'); // Read binary image file const imageBuffer = fs.readFileSync('captcha.png'); // Pass directly; library handles conversion to base64 const result = await solver.solve({ type: 'ImageToTextTask', body: imageBuffer // Automatically converted to base64 }); ``` -------------------------------- ### Environment Variable Integration Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Demonstrates how to use environment variables for sensitive information like API keys, improving security. ```javascript require('dotenv').config(); // Load environment variables from .env file const capsolver = require('@capsolver/node-capsolver'); async function solveWithEnvVar() { const clientKey = process.env.CAPSOLVER_API_KEY; if (!clientKey) { throw new Error('CAPSOLVER_API_KEY environment variable not set.'); } const solver = new capsolver.Solver(clientKey); try { const result = await solver.solve(capsolver.Task.ImageToTextTask, { body: 'YOUR_IMAGE_URL_OR_BASE64', }); console.log('Captcha solved using env var:', result.solution.text); } catch (error) { console.error('Error solving captcha with env var:', error); } } solveWithEnvVar(); ``` -------------------------------- ### Get Token for ReCaptchaV2TaskProxyLess with Node-Capsolver Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-reference-capsolver.md Use the `getToken` method for a faster way to obtain a ReCaptchaV2 token. This is suitable for ReCaptcha V2/V3 and Enterprise versions when a direct token is needed. It requires the website URL and key. ```javascript const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); const response = await solver.getToken({ type: 'ReCaptchaV2TaskProxyLess', websiteURL: 'https://www.example.com', websiteKey: 'sitekey123' }); if (response.errorId === 0) { console.log(`Token: ${response.solution.gRecaptchaResponse}`); } ``` -------------------------------- ### createTask Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/MANIFEST.md Submits a new task to be solved by the Capsolver service. ```APIDOC ## createTask(task) ### Description Creates a new task to be solved. ### Method POST ### Endpoint /createTask ### Parameters #### Request Body - **task** (object) - Required - The task object defining the type of captcha and its parameters. ### Request Example ```json { "task": { "type": "RecaptchaV2Task", "websiteURL": "https://www.google.com", "googleKey": "6Le-wvkSAAAAAPBMRTdwY4A5rHeZ_vOMs5OP7_Yd" } } ``` ### Response #### Success Response (200) - **taskId** (string) - The unique identifier for the created task. ``` -------------------------------- ### Account Info: getBalance() Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/architecture.md Retrieves the current account balance and information about available packages by making a POST request to the /getBalance endpoint. ```javascript async getBalance(): Promise ``` -------------------------------- ### Create Task Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/README.md Creates a new task for solving a captcha on the CapSolver service. ```APIDOC ## POST /createTask ### Description Create a new task to solve a captcha. ### Method POST ### Endpoint /createTask ### Parameters #### Request Body - **clientKey** (string) - Required - Your CapSolver API key. - **task** (object) - Required - The task object defining the captcha to solve. - **type** (string) - Required - The type of captcha (e.g., 'ReCaptchaV2TaskProxyLess'). - **websiteURL** (string) - Required - The URL of the website where the captcha is located. - **websiteKey** (string) - Required - The sitekey of the captcha. ### Request Example ```json { "clientKey": "YOUR_API_KEY", "task": { "type": "ReCaptchaV2TaskProxyLess", "websiteURL": "https://www.google.com", "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq1bi0A83DR715" } } ``` ### Response #### Success Response (200) - **taskId** (string) - The ID of the created task. #### Response Example ```json { "taskId": "123456789" } ``` ``` -------------------------------- ### Basic Usage: Solving an Image Captcha Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt Demonstrates the basic usage of the Capsolver client to solve an image-to-text captcha. Ensure you have your client key and the image URL. ```javascript const capsolver = require('@capsolver/node-capsolver'); async function solveImageCaptcha() { const solver = new capsolver.Solver('YOUR_CLIENT_KEY'); try { const result = await solver.solve(capsolver.Task.ImageToTextTask, { body: 'YOUR_IMAGE_URL_OR_BASE64', }); console.log('Captcha solved:', result.solution.text); } catch (error) { console.error('Error solving captcha:', error); } } solveImageCaptcha(); ``` -------------------------------- ### HTTP Client Configuration with Axios Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md This snippet shows the default configuration for the HTTP client used by the library, setting the base URL and content type for requests. ```javascript const client = new Axios({ baseURL: options.apiUrl || 'https://api.capsolver.com', headers: { 'Content-Type': 'application/json', } }); ``` -------------------------------- ### Authentication with Client Key Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md All requests must include the clientKey (API key) in the request body. This key is provided during library initialization and automatically appended to requests. ```javascript { "clientKey": "CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // ... endpoint-specific fields } ``` -------------------------------- ### POST /getBalance Request Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md Use this endpoint to retrieve your account balance in USD. The request body must contain your clientKey. ```javascript { "clientKey": "CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } ``` -------------------------------- ### Submit Feedback on a Task Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-reference-capsolver.md Use this method to report incorrect solutions or provide error details for a specific task. Ensure you have initialized the CapSolver with your API key. ```javascript const solver = new CapSolver('CAI-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); // Report that a solution didn't work const response = await solver.feedbackTask('task-id-123', { invalid: true, code: 1, message: 'Solution was rejected by the website' }); if (response.errorId === 0) { console.log('Feedback submitted'); } ``` -------------------------------- ### AntiCloudflareTask Configuration Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/types.md Configuration for Cloudflare challenge with a proxy. Requires website URL and proxy details. ```javascript { type: 'AntiCloudflareTask', websiteURL: string, proxy: string } ``` -------------------------------- ### Node-Capsolver API Documentation Overview Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/COMPLETION-SUMMARY.txt This snippet summarizes the key aspects of the Node-Capsolver technical documentation, focusing on the public API surface, HTTP endpoints, and types. ```APIDOC ## Node-Capsolver Technical Reference This documentation set covers the Node-Capsolver library, a Node.js client for the CapSolver.com API. ### Public API Surface - **1 main class**: `CapSolver` - **6 public methods** documented. - **2 private utility methods** documented. - **1 preprocessing function** documented. ### HTTP Endpoints - **5 REST endpoints** fully documented. - Includes request/response schemas for each endpoint. - Details error handling patterns, polling, and fast-path explanations. - Covers rate limiting and HTTP client details. ### Types and Interfaces - **25+ type definitions** documented. - Covers all task types (recognition and token-based). - Includes response types for all endpoints. - Documents helper types, type unions, field descriptions, and usage context. ### Configuration - All constructor options documented with defaults. - Includes configuration examples, environment variable patterns, and proxy configuration. - Details debugging and performance tuning. ### Error Handling - Explains the standard error response structure. - Provides an error code table with causes and fixes. - Details specific error scenarios, retry patterns, and best practices. ``` -------------------------------- ### VisionEngine Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/types.md Configuration for advanced vision-based captcha solving using various modules. This task requires a specific module, the main image, and optionally a background image, website URL, or question. ```APIDOC ## VisionEngine ### Description Configuration for advanced vision-based captcha solving. ### Fields - **type** (string) - Required - Task type identifier: 'VisionEngine' - **module** (string) - Required - Model to use: 'slider_1', 'rotate_1', 'rotate_2', 'shein', 'space_detection', 'slider_temu_plus', 'select_temu' - **websiteURL** (string) - Optional - Page source URL to improve accuracy - **image** (string) - Required - Base64-encoded main image (no newlines, no data URIs) - **imageBackground** (string) - Optional - Base64-encoded background image (no newlines, no data URIs) - **question** (string) - Optional - Required for space_detection module ### Related Methods `createTask()`, `solve()` ``` -------------------------------- ### getBalance() Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/README.md Checks the current account balance and package information associated with the API key. ```APIDOC ## getBalance() ### Description Retrieves the current account balance and details about available packages. ### Method Signature `getBalance()` ### Parameters None ### Returns - **Balance and package info**: An object containing the user's balance and related package information. ### Response Example ```json { "errorId": 0, "balance": 10.50, "packageInfo": { "packageName": "Standard", "daysLeft": 30 } } ``` ``` -------------------------------- ### HTTP Client Initialization Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/architecture.md Initializes the Axios HTTP client with a base API URL and sets the Content-Type header to application/json. The base URL can be customized via options. ```javascript constructor(clientKey, options) { this.#client = new Axios({ baseURL: this.#options.apiUrl || 'https://api.capsolver.com', headers: { 'Content-Type': 'application/json', }, }); } ``` -------------------------------- ### Instantiate CapSolver with Default AppId Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/configuration.md Create a CapSolver instance without specifying an appId to use the library's default value. This is suitable for general task creation, feedback, and token retrieval. ```javascript const solver = new CapSolver(key); // Uses default appId ``` -------------------------------- ### Low-Level API: createTask() Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/architecture.md Creates a CAPTCHA task on the server. It preprocesses task data, makes a POST request to the /createTask endpoint, and returns the server's response, which includes a taskId if successful. ```javascript async createTask(task: CapSolverTask): Promise ``` -------------------------------- ### solve Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/MANIFEST.md A high-level convenience method that creates a task and polls for its result. ```APIDOC ## solve(task) ### Description A convenience method that combines creating a task and polling for its result. ### Parameters #### Request Body - **task** (object) - Required - The task object defining the type of captcha and its parameters. ### Response #### Success Response (200) - **solution** (object) - The solution to the task. ``` -------------------------------- ### Create Task Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/api-endpoints.md Creates a new captcha solving task. This is the first step in the captcha solving process. ```APIDOC ## POST /createTask ### Description Creates a new captcha solving task. ### Method POST ### Endpoint /createTask ### Parameters #### Request Body - **clientKey** (string) - Required - Your Capsolver API key. - **appId** (string) - Required - The ID of the application. - **task** (object) - Required - The captcha task configuration. ### Request Example ```json { "clientKey": "YOUR_API_KEY", "appId": "YOUR_APP_ID", "task": { ... } } ``` ### Response #### Success Response (200) - **errorId** (integer) - Non-zero indicates error. - **taskId** (string) - The ID of the created task. - **status** (string) - The current status of the task (null if just created). #### Response Example ```json { "errorId": 0, "taskId": "TASK_ID", "status": null } ``` ``` -------------------------------- ### Checking Account Balance Before Task Source: https://github.com/novationa-z/node-capsolver/blob/main/_autodocs/errors.md Before submitting a task, check the account balance to prevent 'Insufficient Balance' errors. This snippet demonstrates how to fetch the balance and proceed only if sufficient funds are available. ```javascript const balance = await solver.getBalance(); if (balance.errorId === 0) { if (balance.balance > 0.001) { // Proceed with task const result = await solver.solve(task); } else { console.error('Insufficient balance'); } } else { console.error(`Balance check failed: ${balance.errorDescription}`); } ```