CaptchaAI · API reference
reCAPTCHA v2
Google's classic challenge that may include checkbox, image, or audio prompts.
- API Documentation
- Code Examples
Code Examples
Below are code examples demonstrating how to solve reCAPTCHA v2 using CaptchaAI's API in various programming languages.
- Python
- JavaScript/Node.js
- PHP
- cURL
solve_recaptcha_v2.py
import requests
import time
API_KEY = "YOUR_API_KEY_HERE"
SITE_KEY = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
PAGE_URL = "https://www.google.com/recaptcha/api2/demo"
# Submit captcha
response = requests.post("https://ocr.captchaai.com/in.php", data={
'key': API_KEY,
'method': 'userrecaptcha',
'googlekey': SITE_KEY,
'pageurl': PAGE_URL,
'json': 1
})
task_id = response.json()['request']
print(f"Task ID: {task_id}")
# Wait and get result
time.sleep(20)
while True:
result = requests.get("https://ocr.captchaai.com/res.php", params={
'key': API_KEY,
'action': 'get',
'id': task_id,
'json': 1
}).json()
if result['status'] == 1:
print(f"Token: {result['request']}")
break
time.sleep(5)
solve_recaptcha_v2.js
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY_HERE';
const SITE_KEY = '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-';
const PAGE_URL = 'https://www.google.com/recaptcha/api2/demo';
async function solveCaptcha() {
// Submit captcha
const formData = new URLSearchParams({
key: API_KEY,
method: 'userrecaptcha',
googlekey: SITE_KEY,
pageurl: PAGE_URL,
json: 1
});
const submitRes = await axios.post('https://ocr.captchaai.com/in.php', formData);
const taskId = submitRes.data.request;
console.log(`Task ID: ${taskId}`);
// Wait and get result
await new Promise(resolve => setTimeout(resolve, 20000));
while (true) {
const result = await axios.get('https://ocr.captchaai.com/res.php', {
params: { key: API_KEY, action: 'get', id: taskId, json: 1 }
});
if (result.data.status === 1) {
console.log(`Token: ${result.data.request}`);
break;
}
await new Promise(resolve => setTimeout(resolve, 5000));
}
}
solveCaptcha();
solve_recaptcha_v2.php
<?php
$API_KEY = 'YOUR_API_KEY_HERE';
$SITE_KEY = '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-';
$PAGE_URL = 'https://www.google.com/recaptcha/api2/demo';
// Submit captcha
$ch = curl_init('https://ocr.captchaai.com/in.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'key' => $API_KEY,
'method' => 'userrecaptcha',
'googlekey' => $SITE_KEY,
'pageurl' => $PAGE_URL,
'json' => 1
]));
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
$taskId = $response['request'];
echo "Task ID: $taskId\n";
// Wait and get result
sleep(20);
while (true) {
$ch = curl_init('https://ocr.captchaai.com/res.php?' . http_build_query([
'key' => $API_KEY,
'action' => 'get',
'id' => $taskId,
'json' => 1
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($result['status'] == 1) {
echo "Token: " . $result['request'] . "\n";
break;
}
sleep(5);
}
?>
solve_recaptcha_v2.sh
#!/bin/bash
API_KEY="YOUR_API_KEY_HERE"
SITE_KEY="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
PAGE_URL="https://www.google.com/recaptcha/api2/demo"
# Submit captcha
TASK_ID=$(curl -s -X POST "https://ocr.captchaai.com/in.php" \
-d "key=$API_KEY" \
-d "method=userrecaptcha" \
-d "googlekey=$SITE_KEY" \
-d "pageurl=$PAGE_URL" \
-d "json=1" | jq -r '.request')
echo "Task ID: $TASK_ID"
# Wait and get result
sleep 20
while true; do
RESULT=$(curl -s "https://ocr.captchaai.com/res.php?key=$API_KEY&action=get&id=$TASK_ID&json=1")
STATUS=$(echo $RESULT | jq -r '.status')
if [ "$STATUS" == "1" ]; then
TOKEN=$(echo $RESULT | jq -r '.request')
echo "Token: $TOKEN"
break
fi
sleep 5
done