AWS WAF and other CAPTCHAs
How to solve any CAPTCHA with cURL
Sometimes the quickest tool is the shell. This guide builds one Bash script that takes any task as a JSON file, works for all 14 supported types, and prints the answer for the next command in your pipeline.
Why a shell script
cURL is on nearly every server and CI image, and jq turns JSON into something the shell can use. Together they let you test a site key in seconds, run a nightly smoke test from cron, or feed a token into another command without writing a program. Because every task type uses the same two endpoints, one script covers reCAPTCHA, Turnstile, AWS WAF, image text and the rest; only the task file changes.
Check your tools
You need Bash, cURL and jq. Most Linux distributions ship cURL; install jq with your package manager (apt install jq, dnf install jq or brew install jq). The script uses --fail-with-body, which appeared in cURL 7.76, so check your version with curl --version. On older systems replace it with --fail.
Start with a single request
Before scripting, make one call by hand to confirm your key works. The balance endpoint is free and answers instantly.
export GS_KEY=YOUR_API_KEY
curl -sS https://gatesolver.com/getBalance \
--header 'content-type: application/json' --data "{\"clientKey\":\"$GS_KEY\"}"
# {"errorId":0,"balance":42.5}
An errorId of 0 means the key is valid. ERROR_KEY_DENIED_ACCESS means it is wrong or was replaced by a newer key in your account.
Write the task as a file
Keeping the task in its own JSON file avoids quoting trouble in the shell and lets you keep a folder of ready made tasks. Here are two examples; the field names are exactly the ones each type expects.
// turnstile.json
{ "type": "AntiTurnstileTaskProxyLess",
"websiteURL": "https://members.example.net/sign-in",
"websiteKey": "0x4AAAAAAAxxxxxxxxxxxxxx" }
// aws.json
{ "type": "AntiAwsWafTaskProxyLess", "websiteURL": "https://shop.example.net/catalog/all" }
JSON does not allow comments, so the first lines above are labels for this page only; leave them out of the real files.
The script
#!/usr/bin/env bash
# solve.sh: create a task from a JSON file and print its solution
set -euo pipefail
: "${GS_KEY:?set GS_KEY to your API key}"
api_root="https://gatesolver.com"
task_file="${1:?usage: solve.sh task.json [poll-seconds]}"
every="${2:-3}"
api() {
curl -sS --fail-with-body --max-time 30 -X POST "$api_root/$1" \
-H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary @-
}
created=$(jq -c --arg k "$GS_KEY" '{clientKey: $k, task: .}' "$task_file" | api createTask)
if [ "$(jq -r '.errorId' <<<"$created")" != "0" ]; then
jq -r '"create failed: \(.errorCode) \(.errorDescription // "")"' <<<"$created" >&2
exit 2
fi
tid=$(jq -r '.taskId' <<<"$created")
for _ in $(seq 1 $((125 / every))); do
sleep "$every"
state=$(jq -nc --arg k "$GS_KEY" --arg t "$tid" '{clientKey: $k, taskId: $t}' | api getTaskResult)
case "$(jq -r '.status // "error"' <<<"$state")" in
ready) jq -c '.solution' <<<"$state"; exit 0 ;;
processing) continue ;;
*) jq -r '"task \(.status // .errorCode)"' <<<"$state" >&2; exit 3 ;;
esac
done
echo "task $tid timed out" >&2
exit 4
How the script works
jq builds every request body, so the API key and task id are inserted safely even if they contain characters the shell would otherwise interpret. The first jq call wraps the task file into {"clientKey": ..., "task": ...} and pipes it into cURL through --data-binary @-, which reads the body from standard input. The second builds the polling body from scratch with -n.
The optional second argument sets the poll interval. Leave it at 3 for token tasks and pass 1 for image tasks such as ImageToTextTask, matching the intervals the API recommends. The loop stops a little after 120 seconds, when an unsolved task is marked failed and stays free.
Exit codes make the script easy to use from other tools: 0 for success with the solution printed on standard output, 2 for a create error, 3 for a failed task or polling error, 4 for a timeout. Messages go to standard error, so piping the output never mixes in diagnostics.
Using the output
The script prints the whole solution object on one line. Pick the field you need with jq:
chmod +x solve.sh
token=$(./solve.sh turnstile.json | jq -r '.token')
curl -sS -X POST https://members.example.net/sign-in \
--data-urlencode "cf-turnstile-response=$token" \
--data-urlencode "email=qa@example.com" -o /dev/null -w '%{http_code}\n'
waf=$(./solve.sh aws.json | jq -r '.cookie')
curl -sS -b "aws-waf-token=$waf" https://shop.example.net/catalog/all | head -c 300
Each type has its own solution field: gRecaptchaResponse for reCAPTCHA, token for Turnstile and MTCaptcha, cookie for AWS WAF and DataDome, text for image text, objects for classification. The type pages under all CAPTCHA types list them.
Image tasks from the shell
For an image, build the task file on the fly with base64. GNU base64 -w0 prints one line without wrapping; on macOS use base64 -i file instead.
jq -n --arg img "$(base64 -w0 code.png)" \
'{type: "ImageToTextTask", body: $img}' > image.json
./solve.sh image.json 1 | jq -r '.text'
Seeing what a task cost
The getTaskResult reply also carries a cost field with the amount charged for that task in US dollars. If you want a running record, print it to standard error just before the solution, for example with jq -r '"cost \(.cost)"' <<<"$state" >&2 inside the ready branch. Appending those lines to a log file gives you a simple spending history per job without opening the account page, and a sudden jump in the number of solves per day is often the first sign that a site changed something on its side. Pair it with a getBalance call at the start of a long job so the job can stop early, with a clear message, when the balance is lower than the run will need.
Common shell pitfalls
- Empty output and exit code 0 from jq: you read a field that does not exist for this type, for example
.tokenon an AWS WAF solution. Print the whole solution once to see its keys. - "parse error" from jq: the task file is not valid JSON. Run
jq . task.jsonto find the line. - Token rejected by the site: too much time passed between the solve and the request that uses it. Run the two commands back to back.
Running it from cron or CI
- Set
GS_KEYin the job's secret store, never in the script. - Use the exit code to fail the job, for example
./solve.sh task.json >/dev/null || exit 1as a nightly check that a form's CAPTCHA still loads with the expected site key. - Log the task id from standard error when something fails, so you can match it with your account history.
- Remember the 600 requests per minute per key limit if several jobs share a key; a few parallel scripts polling every three seconds stay well below it.
See the API docs for every field, and the guide on error handling for which codes are worth a retry.
Common questions
Does the script work for every CAPTCHA type?
Yes. Every type uses createTask and getTaskResult, so only the task JSON file changes between types.
Why use jq to build the request body?
It escapes values correctly, so API keys, task ids and base64 images never break the JSON or the shell quoting.
Which poll interval should I pass?
Three seconds for token tasks such as reCAPTCHA or AWS WAF, one second for image tasks.
Can I run this on macOS?
Yes. Install jq with Homebrew and use base64 -i instead of base64 -w0 when you encode images.
What if my curl does not support fail-with-body?
Replace it with --fail. You lose the error body on HTTP failures, but the API reports its own errors in JSON with status 200 anyway.
Keep reading
- API docscreateTask, getTaskResult, getBalance, error codes and the in.php format.
- All CAPTCHA typesThe 14 task families GateSolver solves, each with its own guide.
- Error handling for CAPTCHA APIsSort every CAPTCHA API error into retry, fix or stop, follow those rules in code, and know which outcomes cost nothing.
- API keyA secret string that authorizes your calls to a service, and the habits that keep it out of code and logs.