Metadata-Version: 2.5
Name: crewai-turnstile
Version: 0.1.2
Summary: A CrewAI Tool that solves Cloudflare Turnstile via the Peak API, for agents that drive a browser and hit a challenge.
Project-URL: Homepage, https://peak.fo/?utm_source=github&utm_medium=readme&utm_campaign=packages&utm_content=crewai-turnstile
Project-URL: Documentation, https://peak.fo/docs/turnstile?utm_source=github&utm_medium=readme&utm_campaign=packages&utm_content=crewai-turnstile
Project-URL: Pricing, https://peak.fo/?utm_source=github&utm_medium=readme&utm_campaign=packages&utm_content=crewai-turnstile#pricing
Project-URL: Source, https://github.com/CircuitSavage/crewai-turnstile
Author: Peak
License: MIT
License-File: LICENSE
Keywords: agent,captcha,cloudflare,crewai,crewai-tool,llm-agent,solver,turnstile,web-scraping
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: crewai>=0.80
Requires-Dist: pydantic>=2
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Description-Content-Type: text/markdown

<div align="center">

# crewai-turnstile

**Give a CrewAI agent the ability to solve Cloudflare Turnstile.** A `BaseTool` that takes a page URL and a sitekey, calls [Peak](https://peak.fo/?utm_source=github&utm_medium=readme&utm_campaign=packages&utm_content=crewai-turnstile), and hands back a token. A crew that browses the web and hits a Turnstile challenge gets a move to make instead of getting stuck.

<p>
  <img src="https://img.shields.io/badge/python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python 3.10+">
  <img src="https://img.shields.io/badge/crewai-tool-FF5A1F?style=for-the-badge" alt="crewai tool">
  <img src="https://img.shields.io/badge/license-MIT-007EC7?style=for-the-badge" alt="MIT License">
</p>

</div>

---

A crew that browses the web runs into Cloudflare Turnstile sooner or later. The widget wants a token that Cloudflare mints after its own checks pass, and a retry loop or a fresh proxy won't produce one. This package gives the crew a `BaseTool` for that step: pass a URL and a sitekey, get a token back.

The tool never touches a browser. It sends one request to the Peak API and returns the answer, so it works in any crew, whether the agents drive Playwright, Selenium or a raw HTTP client. Pair it with whatever tool your agent already uses to read the DOM (to get the sitekey) and to run JS (to put the token back); see [Closing the loop](#closing-the-loop) below.

## Install

```bash
pip install crewai-turnstile
```

## Use it

```python
from crewai_turnstile import PeakTurnstileTool

tool = PeakTurnstileTool(api_key="pk_...")  # or set PEAK_API_KEY
token = tool.run(url="https://example.com/login", sitekey="0x4AAAAAAA...")
```

Hand it to an agent like any other tool:

```python
from crewai import Agent
from crewai_turnstile import PeakTurnstileTool

agent = Agent(
    role="Web researcher",
    goal="Fetch pages and clear any Turnstile challenge blocking them",
    backstory="You browse pages via tools and solve Turnstile when it blocks one.",
    tools=[*your_browser_tools, PeakTurnstileTool(api_key=api_key)],
)
```

The agent decides when to call it, most often after a browsing tool reports it's stuck on a Cloudflare challenge. The tool's `description` is written for that: an LLM reading the tool list will reach for `solve_cloudflare_turnstile` when it sees a Turnstile widget blocking a page.

## Closing the loop

Reading the sitekey and injecting the token both happen on a live page, which is specific to whatever browser your crew drives, so this package doesn't pick one for you. `inject.py` ships the JS every other Peak wrapper package uses, so you can call it from whichever `execute_script` / `page.evaluate` your stack exposes:

```python
from crewai_turnstile import build_injection_script

page.evaluate(build_injection_script(token))          # Playwright
driver.execute_script(build_injection_script(token))  # Selenium
```

It fills every `cf-turnstile-response` field and fires the widget's `data-callback` if the page registered one, the same two places a real form submit reads from.

## Matching the exit IP

Turnstile scores the IP that submits the token. If your agent's browser runs behind a proxy, pass the same one so the token and the request line up:

```python
tool.run(url=url, sitekey=sitekey, proxy="http://user:pass@host:port")
```

Leave `proxy` out and the tool solves through Peak's own IP pool instead. Fine for most sites, wrong for the ones that bind the token to the requesting IP.

## Errors come back as text, not exceptions

An agent copes better with a failure it can read than with a crash that kills the run. `PeakTurnstileTool` returns `"ERROR: <reason>"` (bad sitekey, no balance, no key configured) instead of raising, so the agent's next step can be "try a different sitekey" rather than "the whole crew run died." Call `PeakClient.solve()` directly from `crewai_turnstile.peak` if you want exceptions instead.

## Getting a key

The tool needs an API key for the solver it calls: [Peak](https://peak.fo/?utm_source=github&utm_medium=readme&utm_campaign=packages&utm_content=crewai-turnstile). You pay only for the solves that land, and the free trial (1,000 solves, no card) is enough to wire this up and test it. Peak also solves the Cloudflare 5-second challenge (`task_type: "cloudflare5stask"`); this package covers Turnstile.

<div align="center">

<a href="https://peak.fo/?utm_source=github&utm_medium=readme&utm_campaign=packages&utm_content=crewai-turnstile"><img src="https://img.shields.io/badge/Get_a_key-Peak-FF6B35?style=for-the-badge" alt="Peak"></a>
<br>
<sub><strong>$0.90 per 1,000 Turnstile solves</strong>, down to $0.35 at volume · pay only on success · 1,000 free solves · <a href="https://peak.fo/?utm_source=github&utm_medium=readme&utm_campaign=packages&utm_content=crewai-turnstile#pricing">peak.fo</a></sub>

</div>

## Troubleshooting

The tool returns failures as a string that starts with `ERROR:`. Print the tool output, or read the crew's verbose log, to see which one you have.

- **`ERROR: No Peak API key.`** Neither `api_key=` nor `PEAK_API_KEY` held a key. Keys start with `pk_`; the free one comes from the [dashboard](https://peak.fo/?utm_source=github&utm_medium=readme&utm_campaign=packages&utm_content=crewai-turnstile).
- **`ERROR: Peak request failed: ...`** The request never reached Peak. Check DNS, the firewall, and any `HTTPS_PROXY` variable in the environment, since `urllib` honours it.
- **`ERROR:` followed by Peak's own reason, or `Peak solve failed`.** Peak answered with `success: false`. Common causes: an empty balance, a sitekey that does not belong to the URL, or a `proxy` Peak could not connect through. Peak does not bill a failed solve. The [Cloudflare Turnstile error codes](https://blog.peak.fo/cloudflare-turnstile-error-codes/) post covers the widget-side codes (110200, 300030, 600010 and the rest).
- **The agent passes a sitekey that isn't on the page.** An LLM will invent a plausible `0x4AAAAAAA...` string if no tool gave it the real one. Have a browsing tool return the widget's `data-sitekey` attribute and tell the agent in its task to copy that value. [How to find a Cloudflare Turnstile sitekey](https://blog.peak.fo/how-to-find-a-cloudflare-turnstile-sitekey/) shows where sites hide it.
- **A second call returns the same token.** Versions before 0.1.2 left CrewAI's tool cache on, and CrewAI replays the stored result for a repeated `(url, sitekey)` pair. A Turnstile token works once, so the replayed one is dead. Upgrade to 0.1.2, which turns the cache off for this tool. Pass your own `cache_function=` if you want it back.
- **`build_injection_script` ran and the submit button stays disabled.** The script fills every `cf-turnstile-response` field and calls the function named in the widget's `data-callback` attribute. A site that passes a closure to `turnstile.render({callback: ...})` keeps that function out of reach. Submit the form from your browsing tool, or call the site's own handler with the token. [cf-turnstile-response is empty](https://blog.peak.fo/cf-turnstile-response-empty/) and [the cf-turnstile-response token explained](https://blog.peak.fo/the-cf-turnstile-response-token-explained/) cover the field.
- **The submit returns 403 or the form page again.** The site refused the token. A token is single-use and expires 300 seconds after Cloudflare issues it, so an agent that plans three more steps before it submits can run out the clock. Pass `proxy` with the browser's own egress so Peak mints the token from the address that submits it. [Cloudflare Turnstile 403](https://blog.peak.fo/cloudflare-turnstile-403-scraper-fix/) covers the refusal.
- **The page shows "Just a moment..." and has no widget.** That page is the managed 5-second challenge, a separate check from the Turnstile widget. It wants a `cf_clearance` cookie, and this tool returns widget tokens. [Turnstile token vs cookie](https://blog.peak.fo/cloudflare-turnstile-token-vs-cookie/) explains the difference, and [the Cloudflare 5-second challenge explained](https://blog.peak.fo/the-cloudflare-5-second-challenge-explained/) covers the interstitial.

A longer read: the [2026 Turnstile developer guide](https://blog.peak.fo/how-to-solve-cloudflare-turnstile-in-2026-dev-guide/).

## Related

Other agent wrappers for the same API: [langchain-turnstile](https://github.com/CircuitSavage/langchain-turnstile) · [browser-use-turnstile](https://github.com/CircuitSavage/browser-use-turnstile). Browser wrappers: [playwright-turnstile](https://github.com/CircuitSavage/playwright-turnstile) · [patchright-turnstile](https://github.com/CircuitSavage/patchright-turnstile) · [camoufox-turnstile](https://github.com/CircuitSavage/camoufox-turnstile) · [nodriver-turnstile](https://github.com/CircuitSavage/nodriver-turnstile) · [pydoll-turnstile](https://github.com/CircuitSavage/pydoll-turnstile) · [drissionpage-turnstile](https://github.com/CircuitSavage/drissionpage-turnstile) · [selenium-turnstile](https://github.com/CircuitSavage/selenium-turnstile) · [botasaurus-turnstile](https://github.com/CircuitSavage/botasaurus-turnstile) · [puppeteer-extra-plugin-turnstile](https://github.com/CircuitSavage/puppeteer-extra-plugin-turnstile) · [crawlee-turnstile](https://github.com/CircuitSavage/crawlee-turnstile). No browser: [cloudscraper-turnstile](https://github.com/CircuitSavage/cloudscraper-turnstile) · [turnstile-curl](https://github.com/CircuitSavage/turnstile-curl) · [scrapy-turnstile](https://github.com/CircuitSavage/scrapy-turnstile) · [scrapling-turnstile](https://github.com/CircuitSavage/scrapling-turnstile). Full list in [awesome-turnstile-solvers](https://github.com/CircuitSavage/awesome-turnstile-solvers).

[cloudflare-turnstile-reversed](https://github.com/CircuitSavage/cloudflare-turnstile-reversed) documents the challenge flow, the widget parameters and the fingerprinting the widget runs before it hands out a token.

## Notes

Use this on sites and accounts you're allowed to automate. Respect each target's Terms of Service and `robots.txt`. This is tooling for legitimate agents, testing, and public-data access. Nothing here helps with credential stuffing or abuse. Not affiliated with Cloudflare or CrewAI Inc.

## License

MIT
