AI4CAP.COM

Code Examples

Ready-to-use integration examples in popular programming languages

Quick Start Guide

1

Get your API key

Navigate to the API Keys section to create a new key

2

Install dependencies

Install the required HTTP client library for your language

3

Initialize the client

Create a client instance with your API key

4

Solve CAPTCHA

Call the solve method and wait for the result

Integration Examples

Installation

pip install requests

swiftsolver_example.py

import requests
import time
import base64

class AI4CAPClient:
    def __init__(self, api_key: str, base_url: str = "https://api.ai4cap.com"):
        self.api_key = api_key
        self.base_url = base_url
        self.headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json"
        }
    
    def solve_recaptcha_v2(self, site_key: str, page_url: str) -> dict:
        """Solve reCAPTCHA v2"""
        response = requests.post(
            f"{self.base_url}/api/captcha/solve",
            headers=self.headers,
            json={
                "type": "recaptcha_v2",
                "siteKey": site_key,
                "pageUrl": page_url
            }
        )
        response.raise_for_status()
        return response.json()
    
    def wait_for_solution(self, task_id: str, timeout: int = 120) -> dict:
        """Wait for CAPTCHA solution with polling"""
        start_time = time.time()
        
        while time.time() - start_time < timeout:
            result = self.get_task_result(task_id)
            
            if result["status"] == "completed":
                return result
            elif result["status"] == "failed":
                raise Exception(f"Task failed: {result.get('error', 'Unknown error')}")
            
            time.sleep(2)  # Poll every 2 seconds
        
        raise TimeoutError(f"Task {task_id} timed out after {timeout} seconds")

# Example usage
client = AI4CAPClient(api_key="your-api-key-here")
result = client.solve_recaptcha_v2(
    site_key="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
    page_url="https://example.com"
)
solution = client.wait_for_solution(result['taskId'])
print(f"Solution: {solution['solution']['gRecaptchaResponse']}")

API Documentation

Complete API reference with all endpoints and parameters

View Docs

GitHub Repository

Find more examples and contribute to our libraries

View on GitHub

Need Help?

Contact our support team for integration assistance

Contact Support