Skip to main content
hcaptchaarchitectureapi7 min readBy Catmouse Engineering

Synchronous hCaptcha API Design and Two-Phase Charge Leasing

Last reviewed
Short answer

Synchronous hCaptcha API design is a gateway pattern where one held HTTP POST to https://api.hcap.catmouse.ai/solve reserves a charge on admission, commits it only when a redeemable P1_ token arrives, and refunds it automatically on any failure. Below: why polling wastes token lifetime, how two-phase charge leasing works, and what fields the gateway accepts.

Who this is for

Backend and security engineers who design HTTP clients or evaluate challenge-solving gateways for authorized testing, and want to understand how synchronous connection holding and two-phase charge leasing prevent token staleness and billing leaks.

On this page
  1. Why do legacy task-polling queues waste hCaptcha token lifetime?
  2. How does two-phase charge leasing work (Reserve, Commit, Refund)?
  3. What are the request fields, idempotency rules, and status codes?
  4. Why do caller proxies, href, and rqdata matter?
  5. How does the unified API key and balance ledger work across services?
  6. Key takeaways
  7. Conclusion and scope
  8. Evidence and sources
  9. Frequently asked questions

Why do legacy task-polling queues waste hCaptcha token lifetime?

Legacy polling queues add idle wait time between token creation and retrieval, eating into the 120-second hCaptcha token expiry window.

Traditional captcha and anti-bot services expose an asynchronous two-step queue: your client sends a creation request to receive a task identifier, sleeps in a loop, and polls a status endpoint every few seconds until the state transitions from pending to ready. While simple to implement on an under-provisioned backend, polling introduces two architectural flaws for short-lived verification tokens.

First, per the hCaptcha developer documentation, an h-captcha-response token can only be used once and carries a default expiry window of 120 seconds (reported as expired-input-response at https://api.hcaptcha.com/siteverify). Every second a solved token sits in an output table waiting for your next poll tick is subtracted directly from the time you have to submit that token to the target application.

Polling loops versus a held HTTP connection

Holding a single HTTP POST socket eliminates polling round trips and delivers the token the instant the worker finishes.

On the Catmouse hCaptcha gateway, your client opens one HTTP POST to https://api.hcap.catmouse.ai/solve with a client timeout of at least 95 seconds, and the gateway writes the HTTP response onto that same socket as soon as the solve completes.

Table 1. Asynchronous polling queues vs synchronous single-POST gateway
DimensionLegacy task-polling APICatmouse synchronous gateway
HTTP round trips per solveOne creation call plus repeated polling callsOne held POST connection to https://api.hcap.catmouse.ai/solve
Token delivery delay after solveUp to one full polling interval of idle waitReturned immediately when the worker finishes
Client state machineQueue ID tracking, poll timers, and abandon rulesStandard synchronous HTTP call with a 95-second timeout
Duplicate retry protectionOften spawns a second billed task on retryBuilt-in task_id idempotency key caches the earlier result

How does two-phase charge leasing work (Reserve, Commit, Refund)?

Two-phase charge leasing is an atomic billing state machine that reserves one charge when a solve starts, commits it on HTTP 200, and refunds it on HTTP 500.

In a naive billing pipeline, deducting balance when a request enters the worker pool overcharges you whenever an upstream proxy drops or a worker times out; conversely, deducting balance only at the end of a long-running solve allows a caller with a nearly empty balance to launch dozens of concurrent requests and overrun it.

The four stages of a charge lease

Every request to the Catmouse hCaptcha gateway moves through four deterministic stages:

  1. Edge validation (zero cost): The gateway validates the JSON schema, authentication header (x-api-key), per-key concurrency cap, and required fields (site_key, host, and proxy). If the proxy is omitted or the payload is malformed, the gateway rejects the request immediately with HTTP 400 before queueing, so nothing is reserved or charged.
  2. Phase 1 — Reserve: When the request is accepted for execution, one hcap solve charge at the key's configured rates.hcap rate is atomically reserved against your key's balance. If your key has no available balance, the gateway returns HTTP 402 immediately.
  3. Phase 2a — Commit on 200 OK: If the worker produces a redeemable captcha_token (prefixed with P1_), the reserved lease is committed and the response is cached under the request's task_id.
  4. Phase 2b — Automatic refund on 500: If the solve fails, the upstream proxy disconnects, or the worker encounters an unrecoverable error, the gateway returns HTTP 500 and automatically releases the reserved charge back to your key's available balance.
Step 1: Client sends one synchronous POST request with site_key, host, and proxy to api.hcap.catmouse.ai/solve. Step 2: Edge validates inputs; invalid requests get 400 with zero reserve. Step 3: Valid requests reserve one charge atomically in the ledger. Step 4: Worker executes the challenge over the caller proxy. Step 5: On 200 OK with captcha_token, the charge is committed; on 500 failure or timeout, the reserved charge is refunded automatically.
Figure 1. Two-phase charge leasing and synchronous connection lifecycle on the Catmouse hCaptcha gateway. Diagram by Catmouse Engineering.

What are the request fields, idempotency rules, and status codes?

Send a JSON POST to https://api.hcap.catmouse.ai/solve with site_key, host, and proxy, authenticated via the x-api-key header.

The documented request contract on /hcaptcha.html uses a single synchronous call:

curl -X POST https://api.hcap.catmouse.ai/solve \
  -H 'Content-Type: application/json' \
  -H "x-api-key: $KEY" \
  --max-time 95 \
  -d '{
    "site_key": "<hcaptcha sitekey>",
    "host": "www.example.com",
    "proxy": "user:pass@host:port"
  }'

A passing solve returns HTTP 200 with the redeemable token, the idempotency identifier, and an instant_pass boolean:

{
  "captcha_token": "P1_...",
  "task_id": "...",
  "instant_pass": true
}
site_key (required)
The target site's hCaptcha sitekey UUID embedded in the challenge widget or page configuration.
host (required)
Bare hostname of the page without scheme or path (for example, www.example.com).
proxy (required)
Caller-supplied residential or mobile proxy formatted as user:pass@host:port. Requests without a proxy are refused at the edge with HTTP 400 at zero cost.
task_id (optional)
Idempotency key. When omitted, the gateway assigns one. Sending the same task_id again returns the cached earlier result; after a 500 response, generate a new task_id if you retry.
href and rqdata (optional)
Full page URL (href) and custom enterprise challenge data (rqdata) when supplied by the target page.

How should your client handle each HTTP status code?

Each standard HTTP status code (RFC 9110) maps to a specific client action and billing outcome:

  • 400 Bad Request: Malformed JSON or missing required field (such as proxy). Do not retry unchanged; fix the payload. Never charged.
  • 401 Unauthorized / 403 Forbidden: Missing, invalid, or disabled x-api-key. Check your key before sending further traffic.
  • 402 Payment Required: Key balance is exhausted and cannot reserve a charge. Top up your key via the dashboard.
  • 429 Too Many Requests: More solves are currently in flight than your key's concurrency cap allows. Back off and retry when in-flight calls complete.
  • 500 Internal Server Error: Solve failed during execution; the reserved charge is refunded automatically. Retry with a fresh task_id and verify that your proxy exit is healthy.

Why do caller proxies, href, and rqdata matter?

Residential or mobile proxies and matching page context ensure the issued token aligns with the session that redeems it at siteverify.

Unlike the Kasada solver endpoint (POST /Solver/solve in /openapi.json), which is purely offline and never contacts the target or accepts a proxy field, an hCaptcha solve interacts with hCaptcha challenge infrastructure on behalf of your session. As documented on /hcaptcha.html, hCaptcha rejects datacenter IP ranges, so every request must provide a working residential or mobile proxy.

When a target integration binds the widget to a specific page URL or injects an enterprise rqdata challenge nonce, passing the exact href and rqdata values into the solve request ensures the generated captcha_token matches the context the target server will verify at https://api.hcaptcha.com/siteverify.

How does the unified API key and balance ledger work across services?

A single ksk_... API key authenticates against both the Kasada API and the hCaptcha gateway, drawing from one shared USD balance.

Integrators who use both Catmouse gateways do not manage separate credentials or separate wallets. Your per-service rate is written on your key and returned by GET /v1/client/balance (under rates.hcap) and GET /key/status, as documented in the API reference and hCaptcha API page.

Key takeaways

  • Single-POST gateway: Call POST https://api.hcap.catmouse.ai/solve with a 95-second timeout; no polling loop is required.
  • Two-phase charge lease: Charges are reserved on admission, committed only on HTTP 200, and refunded automatically on HTTP 500.
  • Edge validation: Requests rejected at the edge with HTTP 400 or 503 never reserve or spend a charge.
  • Idempotency: Reuse task_id to fetch a cached result safely; generate a new task_id when retrying after a 500 error.
  • Unified key: One x-api-key and balance ledger cover both Kasada and hCaptcha solves.

Conclusion and scope

Replacing two-step task polling with a held HTTP POST connection and a two-phase charge lease removes polling delay from the 120-second hCaptcha token lifetime and ensures that failed solves never deduct charges.

Scope and authorized use. This article explains the documented request contract, synchronous connection model, and two-phase charge leasing architecture of the Catmouse hCaptcha gateway as published on /hcaptcha.html on 2026-10-10. It publishes no solve-rate, throughput, or latency benchmarks, and a returned token is not a guarantee that a downstream application will accept a subsequent request. Use the Catmouse hCaptcha gateway only against applications and systems you own or have explicit written authorization to test.

Evidence and sources

Each statement in this article is backed by the primary documentation listed below:

  • Catmouse hCaptcha API documentation (/hcaptcha.html). Supports: the endpoint POST https://api.hcap.catmouse.ai/solve, the x-api-key header, the recommended 95-second client timeout (--max-time 95), the required fields (site_key, host, proxy) and optional fields (task_id, href, rqdata), the response shape (captcha_token, task_id, instant_pass), the status codes (200, 400, 401, 402, 403, 429, 500), and the charge reservation, commit, and refund rules. Reviewed 2026-10-10.
  • hCaptcha developer documentation. Supports: single-use verification tokens placed in h-captcha-response, verified via POST to https://api.hcaptcha.com/siteverify, and the 120-second default token expiration window (expired-input-response). Fetched 2026-10-09.
  • IETF RFC 9110 (HTTP Semantics) and MDN HTTP response status codes. Supports: standard definitions of HTTP status codes 200, 400, 401, 402, 403, 429, 500, and 503.
  • Catmouse OpenAPI 3.1 specification (/openapi.json) and API reference (/reference.html). Supports: GET /v1/client/balance, GET /key/status, and the distinction between POST /Solver/solve (offline Kasada ips.js solver with no proxy field) and the hCaptcha gateway. Reviewed 2026-10-10.

Methodology and limits. Documented: all API fields, status codes, charge lease transitions, and hCaptcha token expiry rules cited above. Not measured or claimed: pass rates, solve durations, or third-party vendor internals. Reviewed 2026-10-10.

Frequently asked questions

When is a charge spent on the Catmouse hCaptcha gateway?

Only when your client receives a redeemable captcha_token with HTTP 200. A charge is reserved when a valid request is accepted, committed when a token is returned, and refunded automatically on any worker failure. Requests rejected at the edge with 400 or 503 never reserve or spend a charge.

Why does the hCaptcha gateway hold the connection instead of using createTask and getTaskResult polling?

hCaptcha tokens are single-use and expire after 120 seconds by default. Polling intervals add idle delay between token issuance and delivery, and polling loops multiply HTTP overhead. Holding a single HTTP POST connection returns the token the instant the worker finishes.

What does the optional task_id field do?

task_id is an idempotency key. If you omit it, the gateway generates one and returns it in the response. Reusing the same task_id returns the cached earlier result without starting a second solve. On a 500 error, generate a new task_id when retrying.

Why is the proxy field mandatory on every hCaptcha solve request?

hCaptcha evaluates the network exit during challenge execution. Datacenter addresses are rejected by hCaptcha, so every request must supply a residential or mobile proxy in user:pass@host:port format. A request without a proxy is rejected at the edge with HTTP 400 at zero cost.

How does the hCaptcha gateway relate to POST /Solver/solve in openapi.json?

They are separate endpoints that share the same x-api-key authentication and unified key balance. POST /Solver/solve on kasadaapi.catmouse.ai takes a fetched Kasada ips.js body and never uses a proxy field, whereas POST https://api.hcap.catmouse.ai/solve handles hCaptcha challenges using the caller proxy.