Captcha solving for
OpenAI Agents SDK agents
An agent that meets a challenge has nothing in its toolset that can answer it, so it stalls or hallucinates its way around. Give it a solver as a tool and the block becomes one more call.
import time
import requests
CAPTCHANO_KEY = "cn-YOUR_API_KEY"
HEADERS = {"Authorization": f"Bearer {CAPTCHANO_KEY}"}
def solve(task: dict) -> dict:
"""Block until solved; returns e.g. {"token": "...", "userAgent": "..."}."""
r = requests.post(
"https://api.captchano.com/v1/solve",
params={"wait": 60},
json=task,
headers=HEADERS,
timeout=75,
)
data = r.json()
# A solve can outlast the 60 s wait: poll the task until it finishes.
while data.get("status") in ("queued", "solving"):
time.sleep(5)
data = requests.get(
f"https://api.captchano.com/v1/task/{data['id']}",
headers=HEADERS,
timeout=30,
).json()
if data.get("status") != "ready":
raise RuntimeError(data.get("error") or data)
return data["solution"]
from agents import Agent, function_tool
@function_tool
def solve_captcha(kind: str, sitekey: str, url: str) -> str:
"""Return a token for a captcha blocking the current page."""
return solve({"type": kind, "sitekey": sitekey, "url": url})["token"]
agent = Agent(name="browser", tools=[solve_captcha])Why agents need this specifically
A scraper that hits a challenge fails loudly and you fix it. An agent fails quietly: it reasons about the blocked page, invents a plausible next step, and reports progress it never made. The failure is worse because it is silent. A typed solver tool turns an ambiguous dead end into a deterministic result the agent can branch on.
What the tool returns
- A token or cookie — depending on the challenge type. Session-graded systems return a cookie plus the header set used to earn it.
- The user agent used, so the agent can replay it on submission.
- The cost of the solve, so an agent operating under a budget can account for it rather than spending blind.
Keeping the loop bounded
Give the agent a solve budget per run. Every response reports its cost, so a supervisor can cut the loop when spend passes a threshold rather than discovering it on the invoice. At $0.00598 per solve a typical agent run costs a few cents or less, but an unbounded retry loop is still an unbounded retry loop.
Keep the tool call blocking
The examples call ?wait=60, so the tool returns a finished token in a single step. That matters more for agents than for scripts: a tool that returns "still solving" forces the model to reason about polling, which it does badly. If you need a longer ceiling, raise wait up to 120 seconds. Request shapes for every challenge type are in the API reference.
How the solve fits into OpenAI Agents SDK
The OpenAI Agents SDK turns a typed Python function into a tool with function_tool. The solver becomes one of the agent's tools.
- 01Decorate a function
Wrap the API call with @function_tool and typed arguments.
- 02Add it to the agent
Pass it in the agent's tools list.
- 03Instruct the agent
Tell it to call the tool when a page shows a captcha, with the sitekey and URL.
- 04Trace it
The SDK's tracing shows each tool call and result, including the cost we return.
Getting the token into the page
The agent receives the token and passes it to its browser or HTTP tool.
Where integrations usually go wrong
Type every argument so the generated schema is precise and the model fills it correctly.
Set the HTTP timeout above the wait value so the tool does not fail while the solve is still running.
OpenAI Agents SDK captcha FAQ
Does it work with models other than OpenAI's?
The SDK supports other providers through its model interface, and the tool itself is plain HTTP, so yes.
Can I use it with handoffs?
Yes. Give the tool to whichever agent drives the browser; others can hand off to it.
Where should the API key live?
In an environment variable read inside the tool function, never in the agent instructions.
How do I cap spend?
Track the cost field from each result in the run context and refuse further solves past a budget.
Guides that help
Ready to build?
Start with a free 7-day trial of the Hobby plan, then pay per successful solve or keep the plan as your traffic grows. Cancel before the trial ends and you pay nothing.