Python

Integrate reGOTCHA into your Python applications.

Installation

No SDK required - use the built-in requests library:

pip install requests

Complete Example

import requests
import time

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.regotcha.com"

def solve_recaptcha(website_url: str, website_key: str, action: str = "verify") -> str:
    """Solve a reCAPTCHA v3 challenge and return the token."""

    # Create task
    response = requests.post(f"{BASE_URL}/createTask", json={
        "clientKey": API_KEY,
        "task": {
            "type": "ReCaptchaV3TaskProxyless",
            "websiteURL": website_url,
            "websiteKey": website_key,
            "pageAction": action,
            "minScore": 0.7
        }
    })

    result = response.json()
    if result.get("errorId") != 0:
        raise Exception(f"Create task error: {result.get('errorDescription')}")

    task_id = result["taskId"]

    # Poll for result
    for _ in range(60):  # Max 60 attempts (3 minutes)
        time.sleep(3)

        response = requests.post(f"{BASE_URL}/getTaskResult", json={
            "clientKey": API_KEY,
            "taskId": task_id
        })

        result = response.json()

        if result.get("errorId") != 0:
            raise Exception(f"Get result error: {result.get('errorDescription')}")

        if result.get("status") == "ready":
            return result["solution"]["gRecaptchaResponse"]

    raise Exception("Task timeout")


def get_balance() -> int:
    """Get remaining credit balance."""
    response = requests.post(f"{BASE_URL}/getBalance", json={
        "clientKey": API_KEY
    })
    result = response.json()
    return result.get("balance", 0)


# Usage example
if __name__ == "__main__":
    print(f"Balance: {get_balance()} credits")

    token = solve_recaptcha(
        website_url="https://example.com",
        website_key="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_kl-",
        action="login"
    )
    print(f"Token: {token[:50]}...")

Async Version

For async/await support, use aiohttp:

import aiohttp
import asyncio

async def solve_recaptcha_async(website_url: str, website_key: str) -> str:
    async with aiohttp.ClientSession() as session:
        # Create task
        async with session.post(f"{BASE_URL}/createTask", json={
            "clientKey": API_KEY,
            "task": {
                "type": "ReCaptchaV3TaskProxyless",
                "websiteURL": website_url,
                "websiteKey": website_key,
            }
        }) as response:
            result = await response.json()
            task_id = result["taskId"]

        # Poll for result
        for _ in range(60):
            await asyncio.sleep(3)

            async with session.post(f"{BASE_URL}/getTaskResult", json={
                "clientKey": API_KEY,
                "taskId": task_id
            }) as response:
                result = await response.json()

                if result.get("status") == "ready":
                    return result["solution"]["gRecaptchaResponse"]

        raise Exception("Task timeout")

Error Handling

class ReGotchaError(Exception):
    def __init__(self, code: str, message: str):
        self.code = code
        self.message = message
        super().__init__(f"{code}: {message}")

def create_task(task: dict) -> str:
    response = requests.post(f"{BASE_URL}/createTask", json={
        "clientKey": API_KEY,
        "task": task
    })

    result = response.json()

    if result.get("errorId") != 0:
        raise ReGotchaError(
            result.get("errorCode", "UNKNOWN"),
            result.get("errorDescription", "Unknown error")
        )

    return result["taskId"]