OpenAI Agents SDK · agent runner


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.
How CAPTCHA solving works
When a supported CAPTCHA appears, the agent calls CapSolver and receives the result needed to continue.
CAPTCHA appears
Challenge appears
Collect
Page URL, site key, and CAPTCHA type
Solve
Send a request to CapSolver
Return
Result sent back to the agent
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.
# 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)
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.
Authorized QA testing
Approved RPA
Public data workflows
User-authorized agent tasks
Compliance-reviewed automation
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.

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.
