🎉NEWCapSolver for AI agents
Selenium CAPTCHA solver landing page hero section with code snippet and CTA buttons
Selenium CAPTCHA solver landing page hero section with code snippet and CTA buttons

Agent Automation · OpenAI Agents SDK

Solve CAPTCHAs in your OpenAI Agents SDK app

Add CapSolver as a function tool for browser-enabled agents. When a supported CAPTCHA appears, the agent can call CapSolver, receive the result, and continue the authorized workflow. Tool calls can also be reviewed through Agents SDK tracing.

OpenAI Agents SDK · agent runner

agent → browser.navigate("signup")
agent → form.fill(profile)
CAPTCHA detected
tool_call: solve_recaptcha()span: tools.solve_recaptcha · sitekey + page_url
token returned → agent.resume()
final_output: signup complete
CapSolver function tool

Solving captcha…

How CAPTCHA solving works

When a supported CAPTCHA appears, the agent calls CapSolver and receives the result needed to continue.

01

CAPTCHA appears

Challenge appears

02

Collect

Page URL, site key, and CAPTCHA type

03

Solve

Send a request to CapSolver

04

Return

Result sent back to the agent

05

Continue

Agent resumes the workflow

Integration

How CapSolver fits into an OpenAI agent workflow

OpenAI Agents SDK manages the agent loop and function-tool calls. A separate browser tool handles website interactions, while CapSolver processes supported CAPTCHA requests and returns the result to the agent.

Component

Primary role

When a CAPTCHA appears

OpenAI agent

Plans the task, selects tools, and manages state.

Decides when to call the CapSolver function tool.

Browser tool

Navigates, clicks, types, and reads the page.

Provides the page context and continues browser actions.

CapSolver

Processes supported CAPTCHA requests.

Returns the CAPTCHA result to the agent.

Agents SDK tracing

Records agent runs and tool calls.

Helps review tool activity and errors.

CAPTCHA coverage

Which CAPTCHA types does CapSolver support for OpenAI agents?

Current coverage includes reCAPTCHA v2 and v3, including Enterprise variants, and Cloudflare Turnstile.

reCAPTCHA v2

Standard, invisible, and Enterprise reCAPTCHA v2 challenges.

reCAPTCHA v3

Score-based and Enterprise reCAPTCHA v3 challenges with action support.

Cloudflare Turnstile

Managed, non-interactive, and invisible Turnstile widgets.

More CAPTCHA types

Explore additional CAPTCHA task types available through the CapSolver API.

Quick Start

Add CapSolver to an OpenAI agent as a function tool

Wrap CapSolver with@function_tool, add it to your agent's tools, and let the Agents SDK manage the tool-call loop.

openai_agent.py
# pip install capsolver-agent openai-agents
# export CAPSOLVER_API_KEY=CAP-XXXXXX
# export OPENAI_API_KEY=sk-XXXXXX

import json
import os
from agents import Agent, Runner, function_tool, set_default_openai_api, set_tracing_disabled
from capsolver_agent.schema import create_executor
from _env import load_example_env  # demo only: reads repo-root .env

load_example_env()
set_tracing_disabled(True)
if os.environ.get("OPENAI_BASE_URL"):  # OpenAI-compatible gateway (DeepSeek, ...)
    set_default_openai_api("chat_completions")

executor = create_executor()  # wraps a capsolver-core engine; key from CAPSOLVER_API_KEY

@function_tool
async def solve_captcha(
    captcha_type: str,
    website_url: str,
    website_key: str,
    proxy: str | None = None,   # pass a proxy for proxy-bound challenges
) -> str:
    """Solve a captcha (reCaptchaV2 / reCaptchaV3 / cloudflare) and return the result as JSON.

    Call this whenever a page blocks the task with a CAPTCHA. Provide the
    captcha type, the page URL, and the site key from the challenge widget.
    """
    args = {"captcha_type": captcha_type, "website_url": website_url, "website_key": website_key}
    if proxy:
        args["proxy"] = proxy
    result = await executor.execute("solve_captcha", args)
    return json.dumps(result, ensure_ascii=False)

agent = Agent(
    name="captcha-agent",
    model=os.environ.get("OPENAI_MODEL", "gpt-4o"),
    instructions=(
        "You complete web tasks. When a page shows a CAPTCHA, call solve_captcha "
        "with the captcha type, page URL and site key, then continue."
    ),
    tools=[solve_captcha],
)

result = Runner.run_sync(
    agent,
    "Solve the reCaptchaV2 at https://www.google.com/recaptcha/api2/demo with site key "
    "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ- and report the first 40 characters of the token.",
)
print(result.final_output)
This example uses token mode. See thedocumentationfor browser tools, CAPTCHA parameters, and proxy configuration.

Production best practices

Best practices for production OpenAI agents

Keep API keys secure, pass accurate CAPTCHA details, and track every request.

Area

Recommendation

Why it matters

API key security

Store CAPSOLVER_API_KEY in environment variables or a secret manager.

Prevents accidental key exposure in prompts, logs, and repositories.

Tool inputs

Use clear inputs for CAPTCHA type, page URL, and site key.

Helps the agent call the tool with the correct information.

CAPTCHA details

Pass verified CAPTCHA details from your application or browser tool.

Prevents the model from guessing page parameters.

Timeouts and retries

Use fixed-interval polling with an overall timeout. Retry HTTP errors separately.

Avoids long waits and unnecessary repeated requests.

Logging and tracing

Use Agents SDK tracing for tool calls, and record taskId, status, and errors.

Makes debugging and support easier.

Failure handling

Return a clear error and pause the workflow after repeated failures.

Prevents blind retries and unexpected agent loops.

Best-fit use cases

Built for B2B teams running OpenAI agents in production

Sales Automation

Support approved research and CRM workflows using public or user-provided business data.

HR Technology

Support authorized recruiting workflows across approved job and candidate systems.

QA and Testing Tools

Test signup, checkout, and form workflows that encounter supported CAPTCHAs.

RegTech and Compliance

Public registry checks and evidence collection workflows need reliability and audit logs.

Research Automation

Help research agents collect public web information when a supported CAPTCHA appears.

Internal RPA

Support user-authorized internal workflows that require CAPTCHA solving.

Responsible Use

Built for lawful and authorized automation

CapSolver is designed for responsible automation, including authorized QA testing, approved RPA, public-data workflows, and user-authorized agent tasks. Users must follow applicable laws, website terms, privacy requirements, and rate limits. CapSolver does not support unauthorized access or malicious automation.

01

Authorized QA testing

02

Approved RPA

03

Public data workflows

04

User-authorized agent tasks

05

Compliance-reviewed automation

06

Accessibility-focused automation

FAQ

Related Integrations

Explore more CapSolver integrations for your agent stack

Choose another integration to add CAPTCHA solving to your agent or browser workflow.

01

MCP Server

Connect CapSolver to other clients that support MCP tools.

View Integration
02

Playwright

Add CAPTCHA solving to custom browser automation.

View Integration
03

Browser Use

Add CapSolver as an action for browser-based AI agents.

View Integration
04

LangChain

Use CapSolver as a callable tool in LangChain agents.

View Integration

Add CAPTCHA solving to your OpenAI Agents SDK app

Start with a free trial, add CapSolver as a function tool, and follow the integration guide.