Skip to content
easycaptcha.to
Documentation

Use native fetch with the easycaptcha JavaScript SDK

Integrate FetchClient in Node.js, supply an optional fetch implementation, and keep task status and transport errors separate.

Import the fetch-specific entry point

Use FetchClient from @easycaptcha-to/sdk/fetch when your runtime provides fetch. The SDK is ESM and asynchronous. You do not need axios or ky to import this backend, and choosing it preserves the same create, retrieve, feedback, and balance methods as the other clients.

Keep the API key in a server environment variable when building a public application. Native fetch being available in a browser does not make a private paid account key safe to embed in its JavaScript bundle.

Construct one client at the application boundary

import { FetchClient } from "@easycaptcha-to/sdk/fetch";

const client = new FetchClient({
  apiKey: process.env.EASYCAPTCHA_API_KEY,
});
const job = await client.createJob({
  type: "hcaptcha_token",
  sitekey: process.env.HCAPTCHA_SITEKEY,
  url: process.env.HCAPTCHA_PAGE_URL,
  hold: 30,
});
console.log(job.task_id, job.status);

Creation may return queued or running work. The JavaScript lifecycle guide supplies a bounded loop around getJob. Do not read result.token before establishing completion.

An injected fetch implementation can help an application adapt a runtime or create transport fixtures. Ensure it preserves response status, headers, and bytes. A test double that always returns valid JSON cannot exercise malformed responses or a transport failure before an ID arrives.

Treat abort and timeout as waiting decisions

A request option can carry an abort signal. Aborting stops local waiting; it does not cancel a job already accepted by the API. If the ID is known, save it and reconcile later. If creation fails without an ID, do not silently retry the POST as though it never reached the server.

Review middleware around fetch for credential logging and automatic retries. The client applies its own transport deadline, while your application should also define how long to keep observing a job. Those limits solve different problems.

The TypeScript guide explains narrowing job results after completion. The recovery guide describes persistence needed when a process exits while work is still pending.

Get started with easycaptcha

Build your next integration with easycaptcha.

Create an account, get your API key, and start submitting hCaptcha jobs. Use typed Python and JavaScript SDKs or integrate directly over HTTP.

Create an accountExplore the API

Prepaid credit. Check pricing before submitting paid tasks.