Reference

Using Cookies for Better CAPTCHA Solve Rates

Passing browser cookies to CaptchaAI can significantly improve solve rates and token validity. Sites use cookies to track sessions, and mismatched cookies trigger harder CAPTCHAs.

Why Cookies Matter

When CaptchaAI solves a CAPTCHA, the solved token must match the session context. If the site has set cookies during your browsing session, those cookies define the context. Sending old or missing cookies can result in:

  • Lower solve accuracy
  • Tokens rejected by the target site
  • CAPTCHA difficulty escalation

Passing Cookies to CaptchaAI

Include cookies in your submit request using the cookies parameter:

Python

import requests

API_KEY = "YOUR_API_KEY"

# First, get cookies from the target site
session = requests.Session()
page = session.get("https://example.com/login")
site_cookies = session.cookies.get_dict()

# Format cookies for CaptchaAI
cookie_string = "; ".join(f"{k}={v}" for k, v in site_cookies.items())

# Submit with cookies
resp = requests.get("https://ocr.captchaai.com/in.php", params={
    "key": API_KEY,
    "method": "userrecaptcha",
    "googlekey": "6Le-wvkS...",
    "pageurl": "https://example.com/login",
    "cookies": cookie_string,
})

task_id = resp.text.split("|")[1]

Node.js

const axios = require("axios");

// Get cookies from target site
const pageResp = await axios.get("https://example.com/login", {
  withCredentials: true,
});

// Extract Set-Cookie headers
const cookies = pageResp.headers["set-cookie"]
  .map((c) => c.split(";")[0])
  .join("; ");

// Submit with cookies
const resp = await axios.get("https://ocr.captchaai.com/in.php", {
  params: {
    key: API_KEY,
    method: "userrecaptcha",
    googlekey: "6Le-wvkS...",
    pageurl: "https://example.com/login",
    cookies: cookies,
  },
});

From Selenium

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://example.com")

# Extract cookies
selenium_cookies = driver.get_cookies()
cookie_string = "; ".join(
    f"{c['name']}={c['value']}" for c in selenium_cookies
)

# Use with CaptchaAI
resp = requests.get("https://ocr.captchaai.com/in.php", params={
    "key": API_KEY,
    "method": "userrecaptcha",
    "googlekey": site_key,
    "pageurl": "https://example.com",
    "cookies": cookie_string,
})

From Puppeteer

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://example.com");

// Extract cookies
const cookies = await page.cookies();
const cookieString = cookies.map((c) => `${c.name}=${c.value}`).join("; ");

// Use with CaptchaAI
const resp = await axios.get("https://ocr.captchaai.com/in.php", {
  params: {
    key: API_KEY,
    method: "userrecaptcha",
    googlekey: siteKey,
    pageurl: "https://example.com",
    cookies: cookieString,
  },
});

From Playwright

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")

    cookies = page.context.cookies()
    cookie_string = "; ".join(
        f"{c['name']}={c['value']}" for c in cookies
    )

    # Use cookie_string with CaptchaAI

Important Cookies to Include

Cookie Purpose Sites
__cf_bm Cloudflare bot management Cloudflare-protected
cf_clearance Cloudflare challenge clearance Cloudflare-protected
_ga, _gid Google Analytics Many sites
NID, SID Google session Google properties
Session cookies Server session tracking Most sites

Best Practices

  1. Capture cookies right before solving — Cookies expire. Don't cache them too long.
  2. Include all cookies — Don't filter. Let CaptchaAI use what it needs.
  3. Match User-Agent — Use the same User-Agent in your requests and in the CaptchaAI userAgent parameter.
  4. Use session continuity — After solving, use the same cookies for subsequent requests.

Workflow: Full Session with Cookies

import requests
import time

API_KEY = "YOUR_API_KEY"

def solve_with_session(target_url):
    session = requests.Session()
    session.headers["User-Agent"] = (
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
        "AppleWebKit/537.36 (KHTML, like Gecko) "
        "Chrome/120.0.0.0 Safari/537.36"
    )

    # Step 1: Visit page to get cookies
    page = session.get(target_url)
    cookies = "; ".join(
        f"{k}={v}" for k, v in session.cookies.get_dict().items()
    )

    # Step 2: Solve CAPTCHA with cookies
    resp = requests.get("https://ocr.captchaai.com/in.php", params={
        "key": API_KEY,
        "method": "userrecaptcha",
        "googlekey": "6Le-wvkS...",
        "pageurl": target_url,
        "cookies": cookies,
    })
    task_id = resp.text.split("|")[1]

    while True:
        time.sleep(5)
        result = requests.get("https://ocr.captchaai.com/res.php", params={
            "key": API_KEY, "action": "get", "id": task_id,
        })
        if result.text.startswith("OK|"):
            token = result.text.split("|", 1)[1]
            break

    # Step 3: Submit with token using the SAME session
    resp = session.post(target_url, data={
        "g-recaptcha-response": token,
    })

    return resp

FAQ

Do all CAPTCHA types benefit from cookies?

Token-based CAPTCHAs (reCAPTCHA, Turnstile) benefit the most. Image CAPTCHAs rarely use session context.

Will passing cookies guarantee a solve?

No, but it significantly improves accuracy and reduces the chance of token rejection.

How long are cookies valid?

It depends on the site. Session cookies expire when the browser closes. cf_clearance typically lasts 30 minutes.

Discussions (0)

No comments yet.

Related Posts

Reference CAPTCHA Token Injection Methods Reference
Complete reference for injecting solved CAPTCHA tokens into web pages.

Complete reference for injecting solved CAPTCHA tokens into web pages. Covers re CAPTCHA, Turnstile, and Cloud...

Automation Python reCAPTCHA v2
Apr 08, 2026
Tutorials Pytest Fixtures for CaptchaAI API Testing
Build reusable pytest fixtures to test CAPTCHA-solving workflows with Captcha AI.

Build reusable pytest fixtures to test CAPTCHA-solving workflows with Captcha AI. Covers mocking, live integra...

Automation Python reCAPTCHA v2
Apr 08, 2026
Reference Browser Session Persistence for CAPTCHA Workflows
Manage browser sessions, cookies, and storage across CAPTCHA-solving runs to reduce repeat challenges and maintain authenticated state.

Manage browser sessions, cookies, and storage across CAPTCHA-solving runs to reduce repeat challenges and main...

Automation Python reCAPTCHA v2
Feb 24, 2026
Integrations Browser Profile Isolation + CaptchaAI Integration
Browser profile isolation tools create distinct browser environments with unique fingerprints per session.

Browser profile isolation tools create distinct browser environments with unique fingerprints per session. Com...

Automation Python reCAPTCHA v2
Feb 21, 2026
Comparisons WebDriver vs Chrome DevTools Protocol for CAPTCHA Automation
Compare Web Driver and Chrome Dev Tools Protocol (CDP) for CAPTCHA automation — detection, performance, capabilities, and when to use each with Captcha AI.

Compare Web Driver and Chrome Dev Tools Protocol (CDP) for CAPTCHA automation — detection, performance, capabi...

Automation Python reCAPTCHA v2
Mar 27, 2026
Tutorials CAPTCHA Handling in Flask Applications with CaptchaAI
Integrate Captcha AI into Flask applications for automated CAPTCHA solving.

Integrate Captcha AI into Flask applications for automated CAPTCHA solving. Includes service class, API endpoi...

Automation Cloudflare Turnstile
Mar 17, 2026
Use Cases Event Ticket Monitoring with CAPTCHA Handling
Build an event ticket availability monitor that handles CAPTCHAs using Captcha AI.

Build an event ticket availability monitor that handles CAPTCHAs using Captcha AI. Python workflow for checkin...

Automation Python reCAPTCHA v2
Jan 17, 2026
Use Cases CAPTCHA Solving in Ticket Purchase Automation
How to handle CAPTCHAs on ticketing platforms Ticketmaster, AXS, and event sites using Captcha AI for automated purchasing workflows.

How to handle CAPTCHAs on ticketing platforms Ticketmaster, AXS, and event sites using Captcha AI for automate...

Automation Python reCAPTCHA v2
Feb 25, 2026
Tutorials Caching CAPTCHA Tokens for Reuse
Cache and reuse CAPTCHA tokens with Captcha AI to reduce API calls and costs.

Cache and reuse CAPTCHA tokens with Captcha AI to reduce API calls and costs. Covers token lifetimes, cache st...

Automation Python reCAPTCHA v2
Feb 15, 2026
Reference API Endpoint Mapping: CaptchaAI vs Competitors
Side-by-side API endpoint comparison between Captcha AI, 2 Captcha, Anti-Captcha, and Cap Monster — endpoints, parameters, and response formats.

Side-by-side API endpoint comparison between Captcha AI, 2 Captcha, Anti-Captcha, and Cap Monster — endpoints,...

All CAPTCHA Types Migration
Feb 05, 2026
Reference CaptchaAI CLI Tool: Command-Line CAPTCHA Solving and Testing
A reference for building and using a Captcha AI command-line tool — solve CAPTCHAs, check balance, test parameters, and integrate with shell scripts and CI/CD p...

A reference for building and using a Captcha AI command-line tool — solve CAPTCHAs, check balance, test parame...

Automation Python All CAPTCHA Types
Feb 26, 2026
Reference CAPTCHA Solving Performance by Region: Latency Analysis
Analyze how geographic region affects Captcha AI solve times — network latency, proxy location, and optimization strategies for global deployments.

Analyze how geographic region affects Captcha AI solve times — network latency, proxy location, and optimizati...

Automation Python All CAPTCHA Types
Apr 05, 2026