unblock-fetch
v0.1.1
Published
Drop-in fetch that falls back to AlterLab only when the direct fetch is blocked
Maintainers
Readme
unblock-fetch
A drop-in fetch that tries the request directly first and only calls AlterLab when the site refuses it: a 403 or 429, a challenge or verification page, or an empty JavaScript shell. Requests that already work never leave your machine.
Install
npm install unblock-fetchUsage
import { unblockFetch } from "unblock-fetch";
const res = await unblockFetch("https://example.com", {
headers: { "User-Agent": "my-app/1.0" },
timeout: 20_000,
});
console.log(res.via); // "direct" or "alterlab"
console.log(res.status); // origin status code
console.log(res.text); // page contentUse isBlocked(status, body) on its own if you only want the detection:
import { isBlocked } from "unblock-fetch";
if (isBlocked(r.status, await r.text())) { /* ... */ }Options
| Option | Type | Default | Description |
|---|---|---|---|
| headers | Record<string,string> | — | Headers for the direct request |
| timeout | number (ms) | 20000 | Timeout for each attempt |
| apiKey | string | process.env.ALTERLAB_API_KEY | Your AlterLab key for the fallback |
| baseUrl | string | https://api.alterlab.io | API base URL |
| fetch | typeof fetch | global fetch | Custom fetch implementation |
Response
| Field | Description |
|---|---|
| via | "direct" when the direct request worked, "alterlab" when the fallback served it |
| status, ok, url, headers, text | The response, in the usual fetch shape |
| attribution, get_key_url, next_action | Present when AlterLab served the page or a free-trial cap was reached |
How the fallback works
- A direct request that succeeds is returned as-is and never calls AlterLab. A plain 404 is returned as-is too.
- With
ALTERLAB_API_KEYset (orapiKey), the fallback is billed to your account, and only successful requests are charged. - With no key it uses a free keyless trial, capped per IP per day and by a global daily budget. Past a cap you get the original response back with
get_key_urlandnext_action.
Get a key at alterlab.io/signup (up to 5,000 free requests).
Related
unblock-fetchfor Python (pip install unblock-fetch)unblock-fetch-mcp, the same behaviour as an MCP tool for AI agentsalterlab, the full Node.js SDK (search, extract, crawl, batch)
Links
- Package: unblock-fetch on npm
- Source: RapierCraftStudios/alterlab-sdks/unblock-fetch/node
- Issues: https://github.com/RapierCraftStudios/alterlab-sdks/issues
MIT licensed.
