NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

Glossary

Idempotency: making retries harmless

An operation is idempotent when performing it several times leaves the system in the same state as performing it once, which is what makes automatic retries safe.

Why it matters

Networks fail in an awkward way: a request can reach the server, be processed, and then the reply gets lost. From the client's side, a timeout looks identical whether the work happened or not. If the operation is idempotent, you simply send it again. If it is not, a blind retry may charge a card twice or create two records.

HTTP methods

MethodIdempotent by definition?Example
GET, HEAD, OPTIONSYes (and safe)Read a page or a status
PUTYesSet a record to this exact value
DELETEYesRemoving something twice leaves it removed
POSTNoCreate an order, submit a form
PATCHNot necessarily"Add 1 to quantity" is not idempotent

Note that idempotent describes the effect on the server, not the response. A second DELETE may return 404 instead of 204; the state is the same either way.

Idempotency keys

To make a POST safe to retry, many APIs accept an idempotency key: a unique value the client generates and sends in a header. The server remembers each key for a while; if the same key arrives again, it returns the stored result instead of repeating the action. Payment APIs popularized the pattern, and it pairs naturally with asynchronous APIs. Use a fresh random value (a UUID) per logical operation and reuse it only for retries of that operation.

Applying it to solving tasks

In the GateSolver API, the calls differ:

  • getTaskResult and getBalance only read state, so retry them freely after a network error.
  • createTask creates a new task each time. A retry after a lost reply may leave a second task running.

The consequences of a duplicate task are limited by the billing model: you pay only for tasks that are solved, so the worst case is one extra solve, such as $0.56 per 1,000 for reCAPTCHA v2 tasks. To avoid even that, keep a small record per page that needs a solve: the page key, the task ID once you have it, and the state. Before creating a task, check whether that page already has one in flight (the error handling guide shows a fuller version). If createTask timed out without a reply, it is usually cheaper to create one new task and use whichever answer arrives first than to stall the page.

// one solve per page: reuse an open task instead of creating a second
const open = new Map();   // pageKey -> Promise of a solution
function solveOnce(pageKey, task) {
  if (!open.has(pageKey)) {
    open.set(pageKey, runTask(task).finally(() => open.delete(pageKey)));
  }
  return open.get(pageKey);
}

Idempotency on the target site

The same thinking applies to the sites you automate. Submitting a contact form twice sends two messages; posting a search twice is harmless. Before retrying a form submission that timed out, check whether it succeeded (a confirmation page, a new item in a list). Each submission also needs its own fresh token, since CAPTCHA tokens are single use. See exponential backoff for spacing retries and POST request for encoding.

Common questions

Is POST ever idempotent?

Not by definition, but an API can make a POST idempotent by accepting an idempotency key and deduplicating on it.

Is getTaskResult safe to retry?

Yes. It only reads the task state, so repeating it changes nothing.

What happens if createTask is sent twice?

Two tasks are created. Only solved tasks are billed, so the cost is at most one extra solve.

What is an idempotency key?

A unique value sent with a request so the server can recognize retries and return the original result instead of acting again.

Can I reuse a CAPTCHA token when retrying a form?

No. Tokens are accepted once, so a new submission needs a freshly solved token.

Keep reading