Node.js / TypeScript

Integrate reGOTCHA into your Node.js applications.

Installation

Use the built-in fetch API (Node.js 18+) or install node-fetch:

npm install node-fetch  # Only needed for Node.js < 18

Complete Example (TypeScript)

const API_KEY = process.env.REGOTCHA_API_KEY!;
const BASE_URL = "https://api.regotcha.com";

interface TaskResult {
  errorId: number;
  errorCode?: string;
  errorDescription?: string;
  status?: "processing" | "ready";
  solution?: {
    gRecaptchaResponse: string;
  };
}

async function solveRecaptcha(
  websiteUrl: string,
  websiteKey: string,
  action = "verify"
): Promise<string> {
  // Create task
  const createResponse = await fetch(`${BASE_URL}/createTask`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      clientKey: API_KEY,
      task: {
        type: "ReCaptchaV3TaskProxyless",
        websiteURL: websiteUrl,
        websiteKey: websiteKey,
        pageAction: action,
        minScore: 0.7,
      },
    }),
  });

  const createResult = await createResponse.json();

  if (createResult.errorId !== 0) {
    throw new Error(`Create task failed: ${createResult.errorDescription}`);
  }

  const taskId = createResult.taskId;

  // Poll for result
  for (let i = 0; i < 60; i++) {
    await new Promise((resolve) => setTimeout(resolve, 3000));

    const resultResponse = await fetch(`${BASE_URL}/getTaskResult`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        clientKey: API_KEY,
        taskId: taskId,
      }),
    });

    const result: TaskResult = await resultResponse.json();

    if (result.errorId !== 0) {
      throw new Error(`Get result failed: ${result.errorDescription}`);
    }

    if (result.status === "ready" && result.solution) {
      return result.solution.gRecaptchaResponse;
    }
  }

  throw new Error("Task timeout");
}

async function getBalance(): Promise<number> {
  const response = await fetch(`${BASE_URL}/getBalance`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ clientKey: API_KEY }),
  });

  const result = await response.json();
  return result.balance ?? 0;
}

// Usage
async function main() {
  console.log(`Balance: ${await getBalance()} credits`);

  const token = await solveRecaptcha(
    "https://example.com",
    "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_kl-",
    "login"
  );

  console.log(`Token: ${token.slice(0, 50)}...`);
}

main().catch(console.error);

With Axios

import axios from "axios";

const client = axios.create({
  baseURL: "https://api.regotcha.com",
  headers: { "Content-Type": "application/json" },
});

async function solveRecaptcha(websiteUrl: string, websiteKey: string) {
  const { data: createData } = await client.post("/createTask", {
    clientKey: API_KEY,
    task: {
      type: "ReCaptchaV3TaskProxyless",
      websiteURL: websiteUrl,
      websiteKey: websiteKey,
    },
  });

  const taskId = createData.taskId;

  while (true) {
    await new Promise((r) => setTimeout(r, 3000));

    const { data } = await client.post("/getTaskResult", {
      clientKey: API_KEY,
      taskId,
    });

    if (data.status === "ready") {
      return data.solution.gRecaptchaResponse;
    }
  }
}

ESM Module

// regotcha.mjs
export class ReGotcha {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = "https://api.regotcha.com";
  }

  async solve(websiteUrl, websiteKey, options = {}) {
    const taskId = await this.createTask(websiteUrl, websiteKey, options);
    return this.waitForResult(taskId);
  }

  async createTask(websiteUrl, websiteKey, options) {
    const res = await fetch(`${this.baseUrl}/createTask`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        clientKey: this.apiKey,
        task: {
          type: options.enterprise
            ? "ReCaptchaV3EnterpriseTaskProxyless"
            : "ReCaptchaV3TaskProxyless",
          websiteURL: websiteUrl,
          websiteKey: websiteKey,
          pageAction: options.action || "verify",
          minScore: options.minScore || 0.7,
        },
      }),
    });
    const data = await res.json();
    if (data.errorId !== 0) throw new Error(data.errorDescription);
    return data.taskId;
  }

  async waitForResult(taskId, timeout = 180000) {
    const start = Date.now();
    while (Date.now() - start < timeout) {
      await new Promise((r) => setTimeout(r, 3000));
      const res = await fetch(`${this.baseUrl}/getTaskResult`, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ clientKey: this.apiKey, taskId }),
      });
      const data = await res.json();
      if (data.status === "ready") return data.solution.gRecaptchaResponse;
    }
    throw new Error("Timeout");
  }
}

// Usage
const solver = new ReGotcha("YOUR_API_KEY");
const token = await solver.solve("https://example.com", "site_key");