Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ zenrows extract <url> --output markdown
On a domain Extract hasn't prepared yet, `zenrows extract` fails with
`EXTRACT_DOMAIN_NOT_PREPARED` (API code REQS007) and prints the command to
prepare it. Preparing takes a few minutes and costs no credits; each new domain
uses one slot of the monthly allowance. `EXTRACT_PAGE_NOT_RECOGNISED` (also
uses one slot of the monthly allowance, and a preparation rejected by
verification gives its slot back. `EXTRACT_PAGE_NOT_RECOGNISED` (also
REQS007) is different: the domain is prepared, but this page is not one Extract
extracts. Try a product, article or listing page instead, retry it once in a
few minutes if it should work, or use `--css`; preparing again does not change
Expand All @@ -175,6 +176,14 @@ zenrows extract prepare status example.com # progress + monthly allowance
zenrows extract https://www.example.com/products/a # then extract again
```

`prepare` sends each request once and names the next step when it is refused:
`EXTRACT_PREPARE_OUT_OF_ALLOWANCE` means the account has no slots left this
month. `EXTRACT_PREPARE_DOMAIN_REJECTION_LIMIT` means this domain's
preparations were rejected by verification as many times as the monthly limit
per domain allows: do not retry this domain this month (other domains can still
be prepared, and nothing was spent); meanwhile use `--css` on it.
`EXTRACT_PREPARE_UNAVAILABLE` means retry in a few minutes, without a loop.

## 9. Batch

Zenrows **Batch** (`https://async.api.zenrows.com/v1`) fans a
Expand Down
4 changes: 4 additions & 0 deletions agent-plugin/skills/extract/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ extract({ url }) # 4. extract again
- Preparing takes a few minutes and costs no credits. Each new domain uses one
slot of the account's monthly allowance; `prepared_domain_status` returns it
(`used` / `limit` / `remaining`) and a `next` field with what to do now.
A preparation rejected by verification gives its slot back.
- `out_of_allowance`: no slots left this month; use `mode=css`.
`domain_rejection_limit`: this domain's preparations were rejected by
verification as often as the monthly limit allows. Do not retry this domain
this month; other domains can still be prepared. Use `mode=css` on it.
`overloaded` / `disabled`: retry in a few minutes; do not loop.
A `failed` status carries `failure.code` and `failure.slot_consumed`; follow `next`.
- A domain that is already prepared answers `ready` at once
Expand Down
5 changes: 4 additions & 1 deletion skills/extract/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ zenrows extract https://www.example.com/products/a # 3. extract again
separately, and a leading `www.` is dropped.
- Preparing takes a few minutes and costs no credits. Each new domain uses one
slot of the account's monthly allowance; `prepare status` shows `used` /
`limit` / `remaining`.
`limit` / `remaining`. A preparation rejected by verification gives its slot back.
- `EXTRACT_PREPARE_OUT_OF_ALLOWANCE`: no slots left this month; use `--css`.
`EXTRACT_PREPARE_DOMAIN_REJECTION_LIMIT`: this domain's preparations were
rejected by verification as often as the monthly limit allows. Do not retry
this domain this month; other domains can still be prepared. Use `--css` on it.
`EXTRACT_PREPARE_UNAVAILABLE`: retry in a few minutes; do not loop.
`prepare` sends each request once: `--retries` does not apply to it.
A `failed` status prints the next step for its failure code and says whether
Expand Down
1 change: 1 addition & 0 deletions src/core/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type ErrorCode =
| "EXTRACT_PREPARE_NOT_FOUND"
| "EXTRACT_PREPARE_IN_PROGRESS"
| "EXTRACT_PREPARE_OUT_OF_ALLOWANCE"
| "EXTRACT_PREPARE_DOMAIN_REJECTION_LIMIT"
| "EXTRACT_PREPARE_UNAVAILABLE"
| "EXTRACT_PREPARE_FAILED"
| "EXTRACT_PREPARE_TIMEOUT"
Expand Down
27 changes: 26 additions & 1 deletion src/core/prepared-domains-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,22 @@ export function prepareError(status: number, body: string, domain: string): Tool
server_code: code,
});
}
if (code === "out_of_allowance" || status === 429) {
if (code === "domain_rejection_limit") {
const counts =
p.rejected !== undefined && p.limit !== undefined
? ` (${String(p.rejected)} rejected this month, limit ${String(p.limit)} per domain)`
: "";
return new ToolkitError({
code: "EXTRACT_PREPARE_DOMAIN_REJECTION_LIMIT",
message: `${domain} has reached the monthly limit of preparations rejected by verification${counts}.`,
likely_cause: cause,
next_action:
"Do not retry this domain this month; new attempts reopen at the start of next month (UTC). This submission used no allowance slot, and other domains can still be prepared. Meanwhile extract this domain with --css and explicit selectors.",
suggested_commands: [`zenrows extract <url> --css '{"title":"h1"}'`],
server_code: code,
});
}
if (code === "out_of_allowance") {
const used = p.used !== undefined && p.limit !== undefined ? ` (${String(p.used)} of ${String(p.limit)} used)` : "";
return new ToolkitError({
code: "EXTRACT_PREPARE_OUT_OF_ALLOWANCE",
Expand All @@ -195,6 +210,16 @@ export function prepareError(status: number, body: string, domain: string): Tool
server_code: code,
});
}
if (status === 429) {
// A 429 this CLI does not know: the server's detail says what to do, not the allowance.
return new ToolkitError({
code: "EXTRACT_PREPARE_FAILED",
message: `Zenrows refused to prepare ${domain} (HTTP 429): ${detail}`,
likely_cause: cause,
next_action: "Follow the message above; do not retry in a loop. Meanwhile extract with --css and explicit selectors.",
server_code: code,
});
}
if (code === "overloaded" || code === "disabled" || status === 503) {
return new ToolkitError({
code: "EXTRACT_PREPARE_UNAVAILABLE",
Expand Down
51 changes: 51 additions & 0 deletions tests/extract-prepare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,57 @@ for (const [status, serverCode, code, pattern] of [
});
}

const REJECTION_DETAIL =
"example.com had 3 rejected preparation attempts this month (failed verification); the limit is 3 per domain per month. This submission was not accepted and not counted against your allowance. New attempts for this domain reopen at the start of next month (UTC).";

for (const [rejected, limit] of [
[3, 3],
[1, 0],
] as const) {
test(`prepare maps 429 domain_rejection_limit (limit ${limit}) to EXTRACT_PREPARE_DOMAIN_REJECTION_LIMIT, not the allowance`, async () => {
const { calls, fetchImpl } = stub({
[`POST ${BASE}`]: () =>
res(
{
code: "domain_rejection_limit",
title: "Domain rejection limit reached",
status: 429,
detail: REJECTION_DETAIL,
domain: "example.com",
rejected,
limit,
month: "2026-11",
},
429,
),
});
const { code: exit, out } = await run(["example.com", "--url", "https://example.com/p/1"], fetchImpl);
assert.equal(exit, 1);
assert.equal(out.error.code, "EXTRACT_PREPARE_DOMAIN_REJECTION_LIMIT");
assert.equal(out.error.server_code, "domain_rejection_limit");
assert.match(out.error.message, new RegExp(`${rejected} rejected this month, limit ${limit} per domain`));
assert.doesNotMatch(out.error.message, /allowance/);
assert.ok(out.error.likely_cause.includes(REJECTION_DETAIL));
assert.match(out.error.next_action, /Do not retry this domain this month/);
assert.match(out.error.next_action, /other domains can still be prepared/);
assert.match(out.error.next_action, /--css/);
assert.equal(calls.length, 1);
});
}

test("prepare reports an unknown 429 with the server's detail, not as the allowance", async () => {
const { fetchImpl } = stub({
[`POST ${BASE}`]: () => res({ code: "something_new", status: 429, detail: "Slow down for this domain." }, 429),
});
const { code: exit, out } = await run(["example.com", "--url", "https://example.com/p/1"], fetchImpl);
assert.equal(exit, 1);
assert.equal(out.error.code, "EXTRACT_PREPARE_FAILED");
assert.equal(out.error.server_code, "something_new");
assert.match(out.error.message, /Slow down for this domain\./);
assert.doesNotMatch(out.error.message, /allowance/);
assert.match(out.error.next_action, /do not retry in a loop/);
});

test("prepare rejects zero, six or non-URL --url values before any request", async () => {
const { calls, fetchImpl } = stub({});
for (const args of [
Expand Down
Loading