@hunt-labs/bytekit-mcp 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -3
- package/README.md +4 -4
- package/dist/client.d.ts +13 -7
- package/dist/client.js +17 -23
- package/dist/docs-bundle/docs-bundle.json +11 -11
- package/dist/lib/render-scrape.d.ts +1 -1
- package/dist/lib/render-scrape.js +2 -2
- package/dist/lib/scrape-formats.d.ts +13 -22
- package/dist/lib/scrape-formats.js +12 -26
- package/dist/scrape-contract.generated.d.ts +7 -4
- package/dist/tools/scrape-url.js +4 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,53 @@ today, see [README.md](./README.md), which remains the authoritative usage guide
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [0.3.4] - 2026-09-04
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Regenerated the bundled documentation corpus so the offline docs describe the proxy-tier
|
|
18
|
+
response headers as they now behave (#3926). `X-Scrape-Proxy-Tier-Label` reports the tier that
|
|
19
|
+
actually served a scrape — after any escalation, never the tier first attempted — and is
|
|
20
|
+
omitted on a cache hit, which replays stored bytes and runs no tier. No tool, argument or
|
|
21
|
+
output shape changed.
|
|
22
|
+
|
|
23
|
+
## [0.3.3] - 2026-09-03
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- **Breaking (API):** `scrape_url`'s `formats` enum is now `raw | markdown | links | images`
|
|
28
|
+
(#3775). The alias layer that accepted the two retired raw-HTML spellings from an agent and
|
|
29
|
+
translated them onto the wire is gone with the spellings themselves — there is one vocabulary
|
|
30
|
+
now, so the tool neither translates nor tolerates. A secondary `raw` format is still rendered
|
|
31
|
+
under its own `--- format: raw ---` delimiter; the cleaned-article-HTML format no longer
|
|
32
|
+
exists.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- A `402` now reaches the agent with the server's OWN error code and message (#3784). The client
|
|
37
|
+
carried a hardcoded `402` branch that rewrote every payment-required response to
|
|
38
|
+
`quota_exceeded` with client-authored bandwidth wording, so an impaired or expired subscription
|
|
39
|
+
— and an overage spending cap — all read as "Bandwidth quota exhausted". The branch is gone;
|
|
40
|
+
the generic envelope path reports what the gateway sent, so the four billing codes the API
|
|
41
|
+
documents are the four codes an agent sees.
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- Refreshed the bundled documentation snapshot for the two subscription-entitlement `402` codes
|
|
46
|
+
now documented in the errors guide (#3784).
|
|
47
|
+
|
|
48
|
+
- Refreshed the bundled documentation snapshot after the TypeScript and Python SDK changelog
|
|
49
|
+
entries for #3777, plus this entry itself. The `changelog` page's truncation notice reports the
|
|
50
|
+
full page size: `153564` becomes `155329` bytes (+1765, the combined length of the three new
|
|
51
|
+
entries). The TypeScript SDK's own changelog section alone already exceeds the page's
|
|
52
|
+
16,384-byte bundled cut (the Python SDK, CLI and MCP sections that follow it were never in the
|
|
53
|
+
bundle, before or after this change), so only the TypeScript SDK's new `0.9.2` entry is
|
|
54
|
+
actually visible — it lands near the top of that section, well inside the cut. Both the Python
|
|
55
|
+
SDK entry and this entry are further down the page than the cut has ever reached. Pushing
|
|
56
|
+
everything else in the page down by 1765 bytes moves the cut point 1765 bytes earlier within the
|
|
57
|
+
TypeScript SDK section's own older history, so slightly less of an older entry is visible than
|
|
58
|
+
before. The page count stays at 108 and no tool, argument, or response shape changes.
|
|
59
|
+
|
|
13
60
|
## [0.3.2] - 2026-08-31
|
|
14
61
|
|
|
15
62
|
### Changed
|
|
@@ -303,9 +350,11 @@ today, see [README.md](./README.md), which remains the authoritative usage guide
|
|
|
303
350
|
it can still be redeemed via `get_result`. Degrades gracefully when the header is
|
|
304
351
|
absent. (#2591)
|
|
305
352
|
- The 402 message on `/v1/screenshots` no longer says "Bandwidth quota exhausted"
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
353
|
+
and no longer points at `get_account`, which is rate-limit-fragile immediately
|
|
354
|
+
after a quota failure. Every other endpoint's 402 wording is unchanged. (#2591)
|
|
355
|
+
(Correction, #3785: this entry originally explained the change by saying screenshot
|
|
356
|
+
quotas are credit/count-based. They are not. Screenshots are billed on bandwidth —
|
|
357
|
+
Phase 1 wire bytes x 1.5 — and the credit figure they report is a legacy weight.)
|
|
309
358
|
- `get_result`'s invalid-id-prefix message no longer truncates the offending id to 3
|
|
310
359
|
characters. (#2591)
|
|
311
360
|
- `get_result` now gives the same "poll with get_result" guidance `screenshot_url`'s
|
package/README.md
CHANGED
|
@@ -174,7 +174,7 @@ The server also exposes **resources** (`bytekit://account`,
|
|
|
174
174
|
|
|
175
175
|
`scrape_url` (and `get_result` redeeming a scrape's `sc_` handle) render every
|
|
176
176
|
requested format present in the response: the first present format (default
|
|
177
|
-
`markdown`) is unlabeled, and each additional one (`
|
|
177
|
+
`markdown`) is unlabeled, and each additional one (`raw`) follows under
|
|
178
178
|
its own `--- format: <name> ---` delimiter, with `links`/`images` blocks appended
|
|
179
179
|
after. That rendered content (the requested formats plus any `links`/`images`
|
|
180
180
|
blocks) is capped at a single 100KB budget — on very large pages a requested format's
|
|
@@ -203,9 +203,9 @@ entries (never mid-URL) and the affected section is annotated with
|
|
|
203
203
|
`[Links truncated: N of M entries shown]`, so the count in the header stays
|
|
204
204
|
reconcilable with what you were actually handed.
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
Neither textual format is HTML-sanitized — `raw` and `markdown` both reflect the
|
|
207
|
+
page's own markup (`markdown` differs only in being content-extracted, not
|
|
208
|
+
sanitized). Treat all of their content as untrusted page data,
|
|
209
209
|
the same as fetching the page directly.
|
|
210
210
|
|
|
211
211
|
## Documentation
|
package/dist/client.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { Format, ScrapeEnvelope } from './scrape-contract.generated.js';
|
|
2
2
|
import type { PublicScrapeFormat } from './lib/scrape-formats.js';
|
|
3
3
|
/**
|
|
4
|
-
* The `formats` values this client puts ON THE WIRE
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The `formats` values this client puts ON THE WIRE.
|
|
5
|
+
*
|
|
6
|
+
* Since #3775 the public spelling and the gateway's internal `Format` are the same set, so
|
|
7
|
+
* this is `Format` itself. It was `Exclude<Format, …> | PublicScrapeFormat` while the two
|
|
8
|
+
* diverged (#2959); with the divergence gone that exclusion excluded nothing, which is a
|
|
9
|
+
* silently-widening shape rather than a narrowing one. Written as the intersection of the
|
|
10
|
+
* two vocabularies so the type still fails to compile if they ever diverge again.
|
|
8
11
|
*/
|
|
9
|
-
export type ScrapeFormat =
|
|
12
|
+
export type ScrapeFormat = Format & PublicScrapeFormat;
|
|
10
13
|
export interface ScrapeParams {
|
|
11
14
|
url: string;
|
|
12
15
|
formats?: ScrapeFormat[] | undefined;
|
|
@@ -233,8 +236,11 @@ export declare class BytekitClient {
|
|
|
233
236
|
* Map a non-2xx `response` to a {@link BytekitApiError}.
|
|
234
237
|
*
|
|
235
238
|
* `path` is the request path (the caller's second `request` argument). It is threaded in
|
|
236
|
-
* so status
|
|
237
|
-
*
|
|
239
|
+
* so a status mapping can be endpoint-aware. Only the 422 arm still is: it reads the
|
|
240
|
+
* `X-Screenshot-ID` header on `POST /v1/screenshots` alone (#2591). The 402 mapping that
|
|
241
|
+
* used to need it — different prose for bandwidth-billed capture vs credit-billed
|
|
242
|
+
* `/v1/search` (#2571) — is gone; #3784 deleted it so the server's own billing code and
|
|
243
|
+
* message reach the agent unrewritten.
|
|
238
244
|
*
|
|
239
245
|
* `signal` is the per-request timeout signal (#2568); it is forwarded into
|
|
240
246
|
* `parseErrorEnvelope` so an aborted error-body read surfaces as a timeout rather than a
|
package/dist/client.js
CHANGED
|
@@ -402,8 +402,11 @@ export class BytekitClient {
|
|
|
402
402
|
* Map a non-2xx `response` to a {@link BytekitApiError}.
|
|
403
403
|
*
|
|
404
404
|
* `path` is the request path (the caller's second `request` argument). It is threaded in
|
|
405
|
-
* so status
|
|
406
|
-
*
|
|
405
|
+
* so a status mapping can be endpoint-aware. Only the 422 arm still is: it reads the
|
|
406
|
+
* `X-Screenshot-ID` header on `POST /v1/screenshots` alone (#2591). The 402 mapping that
|
|
407
|
+
* used to need it — different prose for bandwidth-billed capture vs credit-billed
|
|
408
|
+
* `/v1/search` (#2571) — is gone; #3784 deleted it so the server's own billing code and
|
|
409
|
+
* message reach the agent unrewritten.
|
|
407
410
|
*
|
|
408
411
|
* `signal` is the per-request timeout signal (#2568); it is forwarded into
|
|
409
412
|
* `parseErrorEnvelope` so an aborted error-body read surfaces as a timeout rather than a
|
|
@@ -430,25 +433,15 @@ export class BytekitClient {
|
|
|
430
433
|
if (status === 401) {
|
|
431
434
|
throw new BytekitApiError('Invalid API key. Check your BYTEKIT_API_KEY.', 401, 'invalid_api_key');
|
|
432
435
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
// Screenshot quotas are credit/count-based, not bandwidth (issue #2591 item 3) --
|
|
443
|
-
// the bandwidth wording below is factually wrong for this endpoint. The
|
|
444
|
-
// get_account pointer is also dropped here: recommending an immediate follow-up
|
|
445
|
-
// call right after a quota failure is rate-limit-fragile on a 1-rps plan.
|
|
446
|
-
// Exact-match (not startsWith) so `/v1/screenshots/{id}` GET is unaffected.
|
|
447
|
-
if (path === '/v1/screenshots') {
|
|
448
|
-
throw new BytekitApiError('Screenshot quota exhausted. Add credits or upgrade your plan to capture more screenshots.', 402, 'quota_exceeded');
|
|
449
|
-
}
|
|
450
|
-
throw new BytekitApiError('Bandwidth quota exhausted. Check usage with get_account.', 402, 'quota_exceeded');
|
|
451
|
-
}
|
|
436
|
+
// NO 402 branch: every billing code `middleware/quota.ts` throws with 402 — the
|
|
437
|
+
// bandwidth/credit exhaustion code, the overage spending-cap code, and the two
|
|
438
|
+
// subscription-entitlement codes — reaches the agent through the generic envelope
|
|
439
|
+
// branch below, carrying the server's own code and message. Collapsing all four onto
|
|
440
|
+
// one hardcoded code plus endpoint-specific prose (#2571/#2591) told an agent whose
|
|
441
|
+
// subscription had expired to check its bandwidth usage: wrong action, wrong code, and
|
|
442
|
+
// unfixable server-side. `docs/api/openapi.yaml` is the contract, and a client never
|
|
443
|
+
// substitutes its own code for the server's (#3784). The codes themselves are
|
|
444
|
+
// deliberately not spelled here: this file must name none of them.
|
|
452
445
|
if (status === 422) {
|
|
453
446
|
// ── The RESOURCE-body 422 (issue #2679) ──
|
|
454
447
|
// POST /v1/screenshots answers a capture that FAILED inside its sync hold with 422
|
|
@@ -505,8 +498,9 @@ export class BytekitClient {
|
|
|
505
498
|
// docs/api/openapi.yaml §/v1/search 502). The string IS the error code, so
|
|
506
499
|
// surface it — but keep the status line in the text, because a bare code is
|
|
507
500
|
// not a sentence and callers key off the HTTP status (issue #2541).
|
|
508
|
-
// Position is load-bearing: strictly BELOW the 401/
|
|
509
|
-
// actionable guidance must keep winning (#2478
|
|
501
|
+
// Position is load-bearing: strictly BELOW the 401/422 mappings, whose
|
|
502
|
+
// actionable guidance must keep winning (#2478 — the 402 mapping that used to
|
|
503
|
+
// sit alongside them was deleted in #3784), and strictly ABOVE the
|
|
510
504
|
// generic envelope branch, which is unreachable for flat bodies anyway
|
|
511
505
|
// because the flat parse never populates both `code` and `message`. ──
|
|
512
506
|
if (envelope.shape === 'flat' && envelope.code !== undefined) {
|
|
@@ -252,12 +252,12 @@
|
|
|
252
252
|
"billing/balance": {
|
|
253
253
|
"title": "Balance and exhausted quota",
|
|
254
254
|
"section": "General",
|
|
255
|
-
"body": "# Balance and exhausted quota\n\nWhat happens when a ByteKit bandwidth or credit balance reaches zero.\n\nByteKit checks the relevant balance before admitting billable work. Capture endpoints use the bandwidth balance; search uses the credit balance; schema extraction requires both.\n\nWhen a request would exceed an enforced balance, ByteKit returns **HTTP 402** with the error code `quota_exceeded`. The request does not continue as unpriced usage.\n\nThere is no automatic overage: availability is an explicit plan setting, and no standard plan enables it. Starter, Growth and Scale carry `has_overage = false`, so a credit-metered request past the included allowance is refused with 402 `quota_exceeded` rather than admitted as billable overage. Only a custom plan arranged with ByteKit can enable overage; on such a plan a configured spending cap can permit or reject additional usage, returning 402 `spending_cap_reached` when the cap is crossed. Capture endpoints still enforce their bandwidth budget.\n\nTo continue after a hard balance stop, purchase a top-up or move to a plan with more included usage. Auto-top-up can purchase bandwidth before the configured threshold is crossed, but it must be enabled and configured in advance; reaching zero does not silently enable it.\n\nSee **Dashboard → Settings → Billing** for included usage, purchased and rollover balances, and auto-top-up status."
|
|
255
|
+
"body": "# Balance and exhausted quota\n\nWhat happens when a ByteKit bandwidth or credit balance reaches zero.\n\nByteKit checks the relevant balance before admitting billable work. Capture endpoints use the bandwidth balance; search uses the credit balance; schema extraction requires both.\n\nWhen a request would exceed an enforced balance, ByteKit returns **HTTP 402** with the error code `quota_exceeded`. The request does not continue as unpriced usage.\n\nThere is no automatic overage: availability is an explicit plan setting, and no standard plan enables it. Starter, Growth and Scale carry `has_overage = false`, so a credit-metered request past the included allowance is refused with 402 `quota_exceeded` rather than admitted as billable overage. Only a custom plan arranged with ByteKit can enable overage; on such a plan a configured spending cap can permit or reject additional usage, returning 402 `spending_cap_reached` when the cap is crossed. Capture endpoints still enforce their bandwidth budget.\n\n## Starter grant\n\nA new pay-as-you-go account receives a one-time starter grant when it is first created: **50 MB of bandwidth and 100 credits**. It is issued once per account, is not a purchase, and does not expire. Granted value is spent last — after your plan's included allowance and after any purchased top-up — so a top-up you paid for is never consumed while free grant remains.\n\n`GET /v1/billing/balance` reports the grant separately from purchases: `granted_topup_bytes` and `granted_topup_credits` hold the grant, `purchased_topup_bytes` and `purchased_topup_credits` hold what you bought, and `topup_bytes` / `topup_credits` are the two added together.\n\nTo continue after a hard balance stop, purchase a top-up or move to a plan with more included usage. Auto-top-up can purchase bandwidth before the configured threshold is crossed, but it must be enabled and configured in advance; reaching zero does not silently enable it.\n\nSee **Dashboard → Settings → Billing** for included usage, purchased and rollover balances, and auto-top-up status."
|
|
256
256
|
},
|
|
257
257
|
"billing/bandwidth": {
|
|
258
258
|
"title": "Bandwidth billing",
|
|
259
259
|
"section": "General",
|
|
260
|
-
"body": "# Bandwidth billing\n\nHow ByteKit measures billed bandwidth for capture and sitemap endpoints.\n\nByteKit bills most capture endpoints from bytes transferred over the upstream wire, not from the size of the final JSON, Markdown, image, or recording artifact. Sitemap jobs use the generated results artifact instead, as described below.\n\n## Upstream wire-byte endpoints\n\nFor scrape, fetch, crawl, and monitor requests, the amount taken from your balance is calculated once, at settlement, and rounded once:\n\n```\nbalance deduction = round(upstream wire bytes × cache factor × clean-Markdown factor)\n```\n\nA cache hit contributes a **0.5×** factor. Successful clean-Markdown processing contributes a separate **3×** factor. The
|
|
260
|
+
"body": "# Bandwidth billing\n\nHow ByteKit measures billed bandwidth for capture and sitemap endpoints.\n\nByteKit bills most capture endpoints from bytes transferred over the upstream wire, not from the size of the final JSON, Markdown, image, or recording artifact. Sitemap jobs use the generated results artifact instead, as described below.\n\n## Upstream wire-byte endpoints\n\nFor scrape, fetch, crawl, and monitor requests, the amount taken from your balance is calculated once, at settlement, and rounded once:\n\n```\nbalance deduction = round(upstream wire bytes × endpoint factor × cache factor × clean-Markdown factor)\n```\n\nA cache hit contributes a **0.5×** factor. Successful clean-Markdown processing contributes a separate **3×** factor. The endpoint factor is listed below. All three compose; they are not alternative rates.\n\n### Endpoint factors\n\nEach endpoint carries a factor reflecting the work it performs:\n\n| Endpoint | Factor |\n| --- | ---: |\n| Scrape | 1× |\n| Scrape with Markdown output | 1.5× |\n| Fetch | 1× |\n| Fetch with Markdown output | 1.5× |\n| Crawl | 1.5× |\n| Crawl links | 1× |\n| Monitor run | 1× |\n\nRequesting Markdown output raises a scrape **or a fetch** from 1× to 1.5×, so a Markdown scrape and a Markdown fetch each deduct one and a half times their upstream wire bytes. The surcharge is not scrape-only.\n\nThis factor is part of what you are charged. `GET /v1/usage/by-endpoint`, the per-endpoint table under **Dashboard → Usage**, the `billing` object on each response and the `X-Billable-Bytes` header all report the same amount your balance lost — there is no separate reporting weight to reconcile.\n\nScreenshot and recording captures bill on a different basis, described under [Other capture artifacts](#other-capture-artifacts).\n\n## Sitemap\n\nSitemap billing uses the byte length of the **gzip-compressed generated results CSV**. The worker builds the results CSV, compresses it, and uses that compressed length for the job's billed bytes and sitemap usage record.\n\nDiscovery fetch bytes are not accumulated into the sitemap charge. The charged byte count is the compressed results artifact, not the upstream bytes transferred while discovering URLs.\n\n## Other capture artifacts\n\nScreenshots and recordings use a separate capture basis: `phase1WireBytes × 1.5`, rounded to whole bytes. The 1.5× combines the upstream Phase 1 fetch with rendering overhead. If Phase 1 has no positive wire-byte measurement, that capture contributes zero billable bytes.\n\nYour current allowance, purchased bandwidth, rollover bandwidth, and remaining balance are shown under **Dashboard → Settings → Billing**."
|
|
261
261
|
},
|
|
262
262
|
"billing/credits": {
|
|
263
263
|
"title": "Credit billing",
|
|
@@ -267,17 +267,17 @@
|
|
|
267
267
|
"billing/spending": {
|
|
268
268
|
"title": "Spending controls",
|
|
269
269
|
"section": "General",
|
|
270
|
-
"body": "# Spending controls\n\nHow spending caps and automatic bandwidth top-ups behave.\n\nByteKit has two distinct spending controls: a credit-overage cap and automatic bandwidth top-ups.\n\n## Credit-overage spending cap\n\nNo standard plan is overage-enabled: Starter, Growth and Scale stop at the included credit allowance with 402 `quota_exceeded`, so this cap never applies to them. It applies only to a custom plan arranged with ByteKit that carries an overage agreement.\n\nFor a credit-metered request on such a plan, ByteKit compares the calculated overage cost with the account's `max_overage_spend_cents`. When the request would cross that limit, the API returns **HTTP 402** with `spending_cap_reached`.\n\nThe current billing page does not expose a self-service control for this account-level overage cap. Contact support if it must be changed.\n\n## Automatic bandwidth top-ups\n\nThe billing page lets an account administrator enable or disable auto-top-up and configure:\n\n- the remaining-bandwidth threshold that triggers a purchase;\n- the amount of bandwidth to purchase; and\n-
|
|
270
|
+
"body": "# Spending controls\n\nHow spending caps and automatic bandwidth top-ups behave.\n\nByteKit has two distinct spending controls: a credit-overage cap and automatic bandwidth top-ups.\n\n## Credit-overage spending cap\n\nNo standard plan is overage-enabled: Starter, Growth and Scale stop at the included credit allowance with 402 `quota_exceeded`, so this cap never applies to them. It applies only to a custom plan arranged with ByteKit that carries an overage agreement.\n\nFor a credit-metered request on such a plan, ByteKit compares the calculated overage cost with the account's `max_overage_spend_cents`. When the request would cross that limit, the API returns **HTTP 402** with `spending_cap_reached`.\n\nThe current billing page does not expose a self-service control for this account-level overage cap. Contact support if it must be changed.\n\n## Automatic bandwidth top-ups\n\nThe billing page lets an account administrator enable or disable auto-top-up and configure:\n\n- the remaining-bandwidth threshold that triggers a purchase;\n- the amount of bandwidth to purchase; and\n- a monthly cap on automatic top-up spending, from $1 to $1,000.\n\nAll three are required when auto-top-up is enabled, and the account must have a Stripe customer. When remaining included bandwidth falls below the configured threshold, ByteKit queues a top-up — unless that purchase would take this month's automatic top-up spending past the cap, in which case it is skipped until the next month. An account that has never stored a cap is uncapped, and the API reports its cap as `null`.\n\nThese controls do not configure purchased-balance expiration. See [Top-ups](https://bytekit.com/docs/billing/top-ups) for the expiry and rollover rules enforced by the billing ledger."
|
|
271
271
|
},
|
|
272
272
|
"billing/top-ups": {
|
|
273
273
|
"title": "Top-ups and rollover",
|
|
274
274
|
"section": "General",
|
|
275
|
-
"body": "# Top-ups and rollover\n\nHow purchased bandwidth and credits expire, carry across periods, and are consumed.\n\nTop-ups add bandwidth or credits without changing your plan's included allowance. The billing ledger records each purchase as its own lot
|
|
275
|
+
"body": "# Top-ups and rollover\n\nHow purchased bandwidth and credits expire, carry across periods, and are consumed.\n\nTop-ups add bandwidth or credits without changing your plan's included allowance. The billing ledger records each purchase as its own lot. Value is spent in one order: your plan's included allowance, including any rollover from earlier periods, then purchased top-ups, then the one-time starter grant.\n\n## Expiration\n\nPurchased top-up lots expire **180 days after the payment provider object was created**. A cancellation or downgrade freezes the lot and **resets that deadline to 90 days from the freeze**. The reset runs in both directions: a lot with five months left loses that time, and a lot that was about to expire gains a little. The window is set by the billing service; it is not configurable in the dashboard. Expired lots are removed from the active purchased balance and cannot fund new usage. If your subscription is cancelled or lapses, any purchased balance above the pay-as-you-go tier is held (not spent, not forfeited) until you resubscribe at the same tier or higher. Restoring the balance does not restore the original deadline — a released lot keeps the date the freeze assigned it. A second freeze restamps from that second freeze, because the rule is keyed to the event, not to the lot.\n\nThat source-backed rule supersedes older wording that described top-ups as never expiring or said their expiration could be configured.\n\n## Billing-period rollover\n\nUnused bandwidth from your monthly plan allowance rolls over to the next billing period with no cap, for as long as the subscription stays on its plan or moves to a higher one. A downgrade or cancellation freezes it: the frozen balance stops being spendable, and resubscribing at the same tier or higher within 90 days restores it in full — after that it is permanently lost. Purchased value is maintained separately in the billing ledger rather than being limited to the `account_usage_periods` row where the purchase first appeared; the current period's `topup_bytes` and `topup_credits` fields are projections of eligible, unexpired lot balances.\n\nCredits do not roll over — they reset every billing period. The `rollover_credits` field exists on the usage-period row and is read when computing the enforced credit budget, but it is never written non-zero today, so it has no effect in practice. This does not affect top-up expiry, which follows the rule above and is not configurable.\n\nYour current purchased and rollover balances appear under **Dashboard → Settings → Billing**."
|
|
276
276
|
},
|
|
277
277
|
"changelog": {
|
|
278
278
|
"title": "Changelog",
|
|
279
279
|
"section": "General",
|
|
280
|
-
"body": "# Changelog\n\nRelease history for the ByteKit SDKs, CLI, and MCP server\n\nEach section below is the `CHANGELOG.md` kept alongside that client’s source in the ByteKit\nrepository. Entries record what a release changed, including names and options it retired.\n\n## @hunt-labs/bytekit-sdk\n\nTypeScript SDK, published on npm.\n\n### [Unreleased]\n\n### [0.9.1] - 2026-08-25\n\n#### Fixed\n\n- The generated `paths` type for the `200` of `GET /v1/scrape/bulk/{id}` now declares `items`\n (#3632). The route builds one body and varies only the status code, so the terminal `200`\n has always carried the per-URL scrape envelopes — but only the `202` documented them, so\n `scrape.bulk.get()` typed the results away at exactly the poll that has them. Types only:\n the field was already on the wire, and server behavior is unchanged.\n\n- The generated `paths` types now describe the `202` that `GET /v1/scrape/bulk/{id}`,\n `GET /v1/fetch/bulk/{id}` and `GET /v1/bulk/{id}` already serve while a bulk job is\n non-terminal (#3533). Each of the three returns 202 with the job envelope until the job is\n terminal and 200 afterwards, but only the 200 was declared, so anything typed off the spec\n had no shape for the response the very first poll receives. Types only: `scrape.bulk.get()`,\n `fetch.bulk.get()` and `bulk.get()` already resolved the body on any 2xx, and server behavior\n is unchanged.\n\n#### Changed\n\n- The generated `topup_balance_bytes` description on `GET /v1/usage` now states that the value is\n the remaining purchased top-up bytes, already net of any overage consumed against them (#3459).\n Types only: the field's name, type and wire format are unchanged. The server previously\n subtracted the consumed overage a second time when computing this value, so the number a client\n reads is larger than before for accounts that ran past their included allowance.\n\n### [0.9.0] - 2026-08-20\n\n#### Removed\n\n- **BREAKING: the `cookies` and `headers` request-body fields are gone from every capture\n endpoint** (#3242) — `/v1/scrape`, `/v1/scrape/bulk`, `/v1/screenshots`, `/v1/recordings` and\n `/v1/schema`. A request that carries either field is rejected with `400 validation_error`; it\n is not ignored, and there is no deprecation window, feature flag, or compatibility header.\n `ScrapeOpts.cookies`, `ScrapeOpts.headers` and the exported `ScrapeCookie` type are removed\n from the SDK surface, so a call that still passes them no longer compiles.\n\n ```ts\n // before — compiled, and the values were forwarded to the target site\n await client.scrape.create({ url, cookies: [{ name: 'session', value: 'abc' }] });\n // after — does not compile; the same body over raw HTTP is a 400 validation_error\n await client.scrape.create({ url });\n ```\n\n ByteKit continues to manage its own cookie jar and request headers internally; what was removed\n is the caller's ability to inject or override them.\n\n#### Changed\n\n- **The generated types now declare the `503` response of `GET`/`POST /v1/fetch`** (#3372).\n `/v1/fetch` answers `503` on two conditions and both carry the ordinary `Error` envelope, so\n a typed consumer reading `operations['getFetch']['responses']` / `['postFetch']` can handle it\n instead of meeting an undeclared status at runtime. Read `error.code` to tell the two apart,\n because they disagree about `error.http_status`:\n - `upstream_error` — the target returned HTTP `502`, relayed at `503` because Cloudflare\n replaces a clean origin 502 with its own error page. `error.http_status` stays `502`, the\n **true upstream status**, and is the only surviving record of what the target answered.\n - `internal_error` (`Fetch service unavailable.`) — the fetch service was unreachable. There\n is no upstream, so `error.http_status` reports `503`, matching what was served.\n\n No runtime behaviour changes, and every other documented `/v1/fetch` status is unaffected.\n\n### [0.8.0] - 2026-08-19\n\n#### Removed\n\n- **BREAKING: `billing_multiplier` and `billed_bytes` are gone from the scrape success\n envelope** (#3143). Read `billing` instead — a `BillingNode` that names every factor\n applied to the charge, the multiplier they compose to, and the resulting billed bytes:\n\n ```ts\n // before\n const spend = res.billed_bytes; // flat, base-endpoint only\n // after\n const spend = res.billing?.billed_bytes;\n const why = res.billing?.factors; // [{ name: 'endpoint', value: 1.5, reason: 'scrape_md' }, …]\n ```\n\n This is a correction, not a rename: the two surfaces reported **different numbers for the\n same charge**. The flat pair carried the BASE-endpoint composition, so a markdown cache hit\n read `0.5` / `400` while the real charge — and the `X-Billing-Multiplier` header — was\n `0.75` / `600`; an html-only miss read the per-format credits estimate `1.5` / `150` against\n an endpoint factor of `1.0` / `100`. The flat pair also never carried the `clean_markdown`\n ×3 surcharge, so on a successful clean it under-reported the amount billed by two thirds.\n `billing.multiplier` composes every applied factor behind exactly one rounding, so it is the\n number that predicts your invoice.\n\n `billing` is optional and is **absent** on resources that completed before the billing node\n existed. A pre-node row omits the field rather than reporting a zero node, because a zero\n node would assert that a real past charge was zero. Test the node for presence\n (`res.billing !== undefined`, or equivalently a plain truthiness check — `billing` is an\n object or `undefined`, and an object is always truthy, so the two are the same test here).\n The hazard is a condition that reaches _into_ the node: `if (res.billing?.billed_bytes)`\n silently skips a genuine zero-byte charge, because `0` is falsy. Check that the node is\n present, then read `billed_bytes` from it.\n\n ```ts\n // wrong — a real 0-byte charge is falsy and disappears\n if (res.billing?.billed_bytes) record(res.billing.billed_bytes);\n // right — presence first, value second\n if (res.billing) record(res.billing.billed_bytes); // 0 is a charge, not an absence\n ```\n\n Two endpoints deliberately carry no node: `/v1/search` is billed per credit and reports\n `credits_used`, and a single `/v1/fetch` reports its charge through response headers only.\n The `/v1/logs` row field named `billing_multiplier` is a **different field** and is not the\n envelope field this release removed. It carries the BASE settled `credits_charged` factor,\n not the composed real-endpoint value the `X-Billing-Multiplier` header reports — a markdown\n cache hit reads `0.5` on the logs row and `0.75` on the header.\n\n#### Changed\n\n- Generated `ScrapeErrorEnvelope` types now describe terminal asynchronous `scrape.failed`\n webhook delivery (#1856). No runtime SDK behavior or API shape changed.\n\n#### Fixed\n\n- **`GET /v1/logs` entries now carry `billing_multiplier`, as a JSON number** (#3022). The\n gateway had been serializing that value under an undeclared key `credits`, and as the raw\n Postgres `NUMERIC(10,2)` string (`\"1.50\"`), while the OpenAPI spec — and therefore the\n generated types in `src/generated/api.d.ts` — declared `billing_multiplier?: number | null`.\n Anything typed against this package read `undefined` for the field.\n\n **Breaking at the wire level:** the undeclared `credits` key is gone from every `/v1/logs`\n entry. Code that reached past the generated types to read `credits` must read\n `billing_multiplier`. No SDK method exposes this endpoint, so the only change inside this\n package is the regenerated type description.\n\n- **`change_threshold` (on `monitors.create`/`monitors.list`/`monitors.get`/\n `monitors.update` responses) and `change_pct` (on `monitors.captures.list` entries)\n now serialize as JSON numbers, not strings** (#3021). Both are Postgres `NUMERIC(5,2)`\n columns; the gateway passed the raw driver string through unconverted (`\"5.00\"` /\n `\"7.25\"`) while the OpenAPI spec's _request_ schemas already declared `number` — only\n the _response_ schemas had been (incorrectly) edited to match the buggy string output.\n This release fixes the gateway serializer and corrects the two response schemas to\n `number` / `number | null`, so spec and runtime now agree.\n\n **Breaking at the wire level:** `client.monitors.create()`, `client.monitors.list()`,\n `client.monitors.get()`, and `client.monitors.update()` now return a JS number for\n `change_threshold` instead of a string (screenshot-type monitors only); the create\n response's `MonitorCreateResponse` and every other monitor route serialize through the\n same `MonitorResponse` schema, so all four are affected identically.\n `client.monitors.captures.list()` now returns a JS number for `change_pct` instead of a\n string. Code doing `parseFloat(monitor.change_threshold)` or template-literal\n interpolation keeps working; strict `typeof x === 'string'` checks or string methods\n (`.trim()`, `.padStart()`) will now throw. `change_pct` is `null` (not `0`) when there is\n no prior capture to diff against, unchanged from before. No SDK method-level shape\n changed otherwise — the only change inside this package is the regenerated type\n description.\n\n### [0.7.4] - 2026-08-19\n\n#### Changed\n\n- **`gen:version` no longer runs as part of `build`** (#3144). `scripts/gen-version.ts` writes\n `src/version.ts`, a _tracked_ source file, and it was chained into the `build` script. That made\n a build silently rewrite committed source whenever the file disagreed with the manifest: local\n runs went green on a tree CI could fail, the resulting ` M src/version.ts` was indistinguishable\n from routine build noise, and in CI the outcome depended on whether Turbo's build cache hit\n (restoring `dist/**` without re-running the generator) or missed. `build` now starts at\n `rm -rf dist ...`, so building this package touches nothing tracked. This changes `prepack` /\n `prepublishOnly` behavior too: both call `build`, so the publish path now reads the committed\n `src/version.ts` rather than regenerating it, and the committed value is what ships.\n- **New `gen:version-check` script**, `pnpm gen:version && git diff --exit-code src/version.ts`,\n mirroring the existing `gen:types-check` in the same manifest. It runs in `.woodpecker/ci.yaml`'s\n `types-drift` step, so a manifest bump without the matching `src/version.ts` regeneration now\n fails a named PR check instead of reaching `staging`. `src/__tests__/version-parity.test.ts`\n stays in place as the in-suite assertion; the gate is what makes its failure reachable before\n merge rather than after.\n\nNo runtime or type changes. `SDK_VERSION` and the `X-ByteKit-Client: sdk_ts/<version>` affix\nbehave exactly as before.\n\n### [0.7.3] - 2026-08-18\n\n#### Changed\n\n- **`XFetchContentLength`'s description no longer calls the header a wire-byte count** (#3133).\n `X-Fetch-Content-Length` is the byte length of the response body actually served: on a\n passthrough `/v1/fetch` (no `format`) that is the relayed upstream payload, so it does equal\n the upstream wire bytes — but with `format=html` or `format=markdown` the gateway overwrites\n it with the transformed document's length, which is typically far smaller than what is billed.\n The old description therefore read as a billing discrepancy on every transform request. Billing\n is unchanged and has always used the upstream compressed wire bytes reported by `X-Raw-Bytes` /\n `X-Billable-Bytes`. Generated-type comments only; no type or runtime behavior changes.\n\n### [0.7.2] - 2026-08-17\n\n#### Changed\n\n- **`ScrapeResponses.202`'s headers no longer advertise `X-Raw-Bytes`, `X-Billable-Bytes`, or\n `X-Billing-Multiplier`** (#3068). The gateway's async `/v1/scrape` path only ever emitted\n `X-Scrape-ID` and `X-Scrape-Status: queued` on a 202 — a queued scrape has no finalized byte\n charge yet — but `docs/api/openapi.yaml` documented the billing-transparency trio there too,\n so `src/generated/api.d.ts` typed three response headers the runtime never sends. This corrects\n the generated type to match the gateway's actual behavior; it does not change any runtime\n behavior. The synchronous `200` response, and `/v1/screenshots`' `202` (which does finalize a\n charge before responding), are unaffected.\n\n### [0.7.1] - 2026-08-11\n\n#### Changed\n\n- **Generated types follow the spec's corrected error and format vocabularies** (#2959). Two\n vocabulary corrections in `docs/api/openapi.yaml` flow through `src/generated/api.d.ts`:\n - `ScrapeErrorEnvelope.error.code` no longer lists `quota_exhausted`. The API has emitted\n `quota_exceeded` since #1539 and there is no throw site for `quota_exhausted` anywhere in\n the gateway, so this removes a code that has never been sent — not one that stops being\n sent. A consumer switching on it was matching a branch that could not be reached; the\n live code for an exceeded quota is `quota_exceeded`. `invalid_url`, which the API does\n emit, is unchanged and still listed.\n - `createBulk`'s `formats` now spells the raw-HTML value `raw_html`, matching `ScrapeRequest`\n and `createScrapeBulk`. `/v1/bulk` previously accepted only the internal `rawHtml`\n spelling and the spec documented that; it now accepts both, so the one endpoint that\n disagreed with the rest of the surface no longer does. `rawHtml` keeps working.\n\n#### Added\n\n- **`ByteKitError.headers` — the failing response's headers, so you can write your own backoff**\n (#2957). This SDK performs exactly one `fetch` per call and never retries, deliberately, so that\n retry policy stays the caller's. But the policy was unwritable: `ByteKitError` carried no\n headers and `requestWithResponse` returns headers only on 2xx — which a rate-limited request\n never reaches — so `Retry-After` and the `X-RateLimit-*` family were unreachable through the SDK\n at every entry point. `err.headers` closes that:\n\n ```ts\n if (err instanceof ByteKitError && err.status === 429) {\n const waitMs = Number(err.headers?.get('Retry-After') ?? 1) * 1000;\n }\n ```\n\n It is the runtime's own `Headers` object rather than a snapshot, so `get()` stays\n case-insensitive whatever casing the wire used. **Strictly additive**: it is optional and last\n on the constructor, follows the same `declare` discipline `details` uses, and an error\n constructed without one carries no `headers` key at all — `'headers' in err`, spreads and\n `JSON.stringify` are unchanged for every pre-existing construction, as are `status`, `code`,\n `message`, `details` and both 2xx return shapes. Only **response** headers are exposed;\n `Authorization` rides on the request and is never reachable through it.\n `ByteKitConnectionError` is unchanged — no response, no headers to carry.\n\n#### Fixed\n\n- **`screenshots.getWithResponse`'s docstring no longer promises headers that endpoint never\n emits** (#2957). The JSDoc — the one an IDE surfaces on hover, and the one the published SDK\n reference is generated from — claimed the documented `X-Screenshot-*` / `X-Raw-Bytes` /\n `X-Billable-Bytes` / `X-Billing-Multiplier` headers \"are on `headers`\". They are not:\n `GET /v1/screenshots/{id}` is declared with **no** `X-*` response headers, which is what\n `ByteKit.requestWithResponse`'s own doc comment and the README have said all along, and what a\n live GET confirms. Documentation only — no signature, return type or runtime behavior changed.\n `screenshots.createWithResponse` (`POST /v1/screenshots`) really does emit that family, and its\n docstring still says so.\n\n- **README documents the `signal`-vs-`timeoutMs` precedence and the `requestTimeoutMs` escape\n hatch** (#2957). Passing your own `AbortSignal` silently disables the constructor's `timeoutMs`\n — the signal becomes the request's only abort source, so a client built with `timeoutMs: 200`\n waits indefinitely if the signal never fires. That precedence was documented on\n `RequestOptions.signal` in the types, where only a reader already inspecting the option would\n meet it, and nowhere in the README. A new \"Timeouts and cancellation\" section states it with the\n full four-row precedence ta\n\n---\n[Truncated to the 16384-byte per-page limit — this page is 151210 bytes in full. The text cut here is not searchable either: search_docs matches only the part kept above. Read all of it at https://bytekit.com/docs/changelog]"
|
|
280
|
+
"body": "# Changelog\n\nRelease history for the ByteKit SDKs, CLI, and MCP server\n\nEach section below is the `CHANGELOG.md` kept alongside that client’s source in the ByteKit\nrepository. Entries record what a release changed, including names and options it retired.\n\n## @hunt-labs/bytekit-sdk\n\nTypeScript SDK, published on npm.\n\n### [Unreleased]\n\n### [0.9.3] - 2026-09-04\n\n#### Changed\n\n- Regenerated `src/generated/api.d.ts` against the corrected queued-scrape `status_url`\n documentation (#3925). `status_url` is a root-relative path, never an absolute URI: join it\n onto the API base URL you called (`https://api.bytekit.com`, no trailing slash) to get the URL\n to poll. The spec had declared it `format: uri` with an absolute example, which no server has\n ever emitted; the emitted value is unchanged, so no client behaviour moves.\n- Regenerated `src/generated/api.d.ts` against the documented proxy-tier response headers\n (#3926). `X-Scrape-Proxy-Tier-Label` now documents that it reports the tier that ACTUALLY\n served a scrape — after any escalation, never the tier first attempted — that it is\n diagnostic only, and that it is omitted on a cache hit, which replayed stored bytes and ran\n no tier. The deprecated numeric `X-Scrape-Proxy-Tier` documents the legacy `1` datacenter /\n `2` residential / `3` mobile vocabulary and its omission for the lean-browser tier. Types are\n unchanged; only the documentation on them moved.\n\n### [0.9.2] - 2026-09-03\n\n#### Changed\n\n- **Breaking (API):** the scrape `formats` vocabulary is now `raw | markdown | links | images`\n (#3775). The unprocessed-source format is called `raw` — it has returned JSON, XML and plain\n text alongside HTML since #1853, so the old raw-HTML name misdescribed it — and the\n cleaned-article-HTML format is gone. The server accepts no alias for either retired value, so\n a request naming one now comes back `422` with the new set in the message. Update `formats`\n and read the content back from `formats.raw`:\n\n ```ts\n const result = await client.scrape.create({ url, formats: ['raw', 'markdown'] });\n console.log(result.formats.raw);\n ```\n\n- Regenerated `src/generated/api.d.ts` against the documented `402` contract (#3784). Every\n quota-enforced operation now declares `402` through one shared `PaymentRequired` response, and\n the `X-Quota-*` headers are referenced by the operations that actually emit them. Types only —\n no runtime behavior changed.\n\n- The generated `events` field description on the scrape request type now documents the\n widened server default (`queued`, `completed`, `failed`) and that a caller may send an\n explicit subset to receive fewer deliveries (#3777). Types/docs only — this regeneration\n followed a server-side default change; the SDK carried no logic tied to the old default.\n\n### [0.9.1] - 2026-08-25\n\n#### Fixed\n\n- The generated `paths` type for the `200` of `GET /v1/scrape/bulk/{id}` now declares `items`\n (#3632). The route builds one body and varies only the status code, so the terminal `200`\n has always carried the per-URL scrape envelopes — but only the `202` documented them, so\n `scrape.bulk.get()` typed the results away at exactly the poll that has them. Types only:\n the field was already on the wire, and server behavior is unchanged.\n\n- The generated `paths` types now describe the `202` that `GET /v1/scrape/bulk/{id}`,\n `GET /v1/fetch/bulk/{id}` and `GET /v1/bulk/{id}` already serve while a bulk job is\n non-terminal (#3533). Each of the three returns 202 with the job envelope until the job is\n terminal and 200 afterwards, but only the 200 was declared, so anything typed off the spec\n had no shape for the response the very first poll receives. Types only: `scrape.bulk.get()`,\n `fetch.bulk.get()` and `bulk.get()` already resolved the body on any 2xx, and server behavior\n is unchanged.\n\n#### Changed\n\n- The generated `topup_balance_bytes` description on `GET /v1/usage` now states that the value is\n the remaining purchased top-up bytes, already net of any overage consumed against them (#3459).\n Types only: the field's name, type and wire format are unchanged. The server previously\n subtracted the consumed overage a second time when computing this value, so the number a client\n reads is larger than before for accounts that ran past their included allowance.\n\n### [0.9.0] - 2026-08-20\n\n#### Removed\n\n- **BREAKING: the `cookies` and `headers` request-body fields are gone from every capture\n endpoint** (#3242) — `/v1/scrape`, `/v1/scrape/bulk`, `/v1/screenshots`, `/v1/recordings` and\n `/v1/schema`. A request that carries either field is rejected with `400 validation_error`; it\n is not ignored, and there is no deprecation window, feature flag, or compatibility header.\n `ScrapeOpts.cookies`, `ScrapeOpts.headers` and the exported `ScrapeCookie` type are removed\n from the SDK surface, so a call that still passes them no longer compiles.\n\n ```ts\n // before — compiled, and the values were forwarded to the target site\n await client.scrape.create({ url, cookies: [{ name: 'session', value: 'abc' }] });\n // after — does not compile; the same body over raw HTTP is a 400 validation_error\n await client.scrape.create({ url });\n ```\n\n ByteKit continues to manage its own cookie jar and request headers internally; what was removed\n is the caller's ability to inject or override them.\n\n#### Changed\n\n- **The generated types now declare the `503` response of `GET`/`POST /v1/fetch`** (#3372).\n `/v1/fetch` answers `503` on two conditions and both carry the ordinary `Error` envelope, so\n a typed consumer reading `operations['getFetch']['responses']` / `['postFetch']` can handle it\n instead of meeting an undeclared status at runtime. Read `error.code` to tell the two apart,\n because they disagree about `error.http_status`:\n - `upstream_error` — the target returned HTTP `502`, relayed at `503` because Cloudflare\n replaces a clean origin 502 with its own error page. `error.http_status` stays `502`, the\n **true upstream status**, and is the only surviving record of what the target answered.\n - `internal_error` (`Fetch service unavailable.`) — the fetch service was unreachable. There\n is no upstream, so `error.http_status` reports `503`, matching what was served.\n\n No runtime behaviour changes, and every other documented `/v1/fetch` status is unaffected.\n\n### [0.8.0] - 2026-08-19\n\n#### Removed\n\n- **BREAKING: `billing_multiplier` and `billed_bytes` are gone from the scrape success\n envelope** (#3143). Read `billing` instead — a `BillingNode` that names every factor\n applied to the charge, the multiplier they compose to, and the resulting billed bytes:\n\n ```ts\n // before\n const spend = res.billed_bytes; // flat, base-endpoint only\n // after\n const spend = res.billing?.billed_bytes;\n const why = res.billing?.factors; // [{ name: 'endpoint', value: 1.5, reason: 'scrape_md' }, …]\n ```\n\n This is a correction, not a rename: the two surfaces reported **different numbers for the\n same charge**. The flat pair carried the BASE-endpoint composition, so a markdown cache hit\n read `0.5` / `400` while the real charge — and the `X-Billing-Multiplier` header — was\n `0.75` / `600`; an html-only miss read the per-format credits estimate `1.5` / `150` against\n an endpoint factor of `1.0` / `100`. The flat pair also never carried the `clean_markdown`\n ×3 surcharge, so on a successful clean it under-reported the amount billed by two thirds.\n `billing.multiplier` composes every applied factor behind exactly one rounding, so it is the\n number that predicts your invoice.\n\n `billing` is optional and is **absent** on resources that completed before the billing node\n existed. A pre-node row omits the field rather than reporting a zero node, because a zero\n node would assert that a real past charge was zero. Test the node for presence\n (`res.billing !== undefined`, or equivalently a plain truthiness check — `billing` is an\n object or `undefined`, and an object is always truthy, so the two are the same test here).\n The hazard is a condition that reaches _into_ the node: `if (res.billing?.billed_bytes)`\n silently skips a genuine zero-byte charge, because `0` is falsy. Check that the node is\n present, then read `billed_bytes` from it.\n\n ```ts\n // wrong — a real 0-byte charge is falsy and disappears\n if (res.billing?.billed_bytes) record(res.billing.billed_bytes);\n // right — presence first, value second\n if (res.billing) record(res.billing.billed_bytes); // 0 is a charge, not an absence\n ```\n\n Two endpoints deliberately carry no node: `/v1/search` is billed per credit and reports\n `credits_used`, and a single `/v1/fetch` reports its charge through response headers only.\n The `/v1/logs` row field named `billing_multiplier` is a **different field** and is not the\n envelope field this release removed. It carries the BASE settled `credits_charged` factor,\n not the composed real-endpoint value the `X-Billing-Multiplier` header reports — a markdown\n cache hit reads `0.5` on the logs row and `0.75` on the header.\n\n#### Changed\n\n- Generated `ScrapeErrorEnvelope` types now describe terminal asynchronous `scrape.failed`\n webhook delivery (#1856). No runtime SDK behavior or API shape changed.\n\n#### Fixed\n\n- **`GET /v1/logs` entries now carry `billing_multiplier`, as a JSON number** (#3022). The\n gateway had been serializing that value under an undeclared key `credits`, and as the raw\n Postgres `NUMERIC(10,2)` string (`\"1.50\"`), while the OpenAPI spec — and therefore the\n generated types in `src/generated/api.d.ts` — declared `billing_multiplier?: number | null`.\n Anything typed against this package read `undefined` for the field.\n\n **Breaking at the wire level:** the undeclared `credits` key is gone from every `/v1/logs`\n entry. Code that reached past the generated types to read `credits` must read\n `billing_multiplier`. No SDK method exposes this endpoint, so the only change inside this\n package is the regenerated type description.\n\n- **`change_threshold` (on `monitors.create`/`monitors.list`/`monitors.get`/\n `monitors.update` responses) and `change_pct` (on `monitors.captures.list` entries)\n now serialize as JSON numbers, not strings** (#3021). Both are Postgres `NUMERIC(5,2)`\n columns; the gateway passed the raw driver string through unconverted (`\"5.00\"` /\n `\"7.25\"`) while the OpenAPI spec's _request_ schemas already declared `number` — only\n the _response_ schemas had been (incorrectly) edited to match the buggy string output.\n This release fixes the gateway serializer and corrects the two response schemas to\n `number` / `number | null`, so spec and runtime now agree.\n\n **Breaking at the wire level:** `client.monitors.create()`, `client.monitors.list()`,\n `client.monitors.get()`, and `client.monitors.update()` now return a JS number for\n `change_threshold` instead of a string (screenshot-type monitors only); the create\n response's `MonitorCreateResponse` and every other monitor route serialize through the\n same `MonitorResponse` schema, so all four are affected identically.\n `client.monitors.captures.list()` now returns a JS number for `change_pct` instead of a\n string. Code doing `parseFloat(monitor.change_threshold)` or template-literal\n interpolation keeps working; strict `typeof x === 'string'` checks or string methods\n (`.trim()`, `.padStart()`) will now throw. `change_pct` is `null` (not `0`) when there is\n no prior capture to diff against, unchanged from before. No SDK method-level shape\n changed otherwise — the only change inside this package is the regenerated type\n description.\n\n### [0.7.4] - 2026-08-19\n\n#### Changed\n\n- **`gen:version` no longer runs as part of `build`** (#3144). `scripts/gen-version.ts` writes\n `src/version.ts`, a _tracked_ source file, and it was chained into the `build` script. That made\n a build silently rewrite committed source whenever the file disagreed with the manifest: local\n runs went green on a tree CI could fail, the resulting ` M src/version.ts` was indistinguishable\n from routine build noise, and in CI the outcome depended on whether Turbo's build cache hit\n (restoring `dist/**` without re-running the generator) or missed. `build` now starts at\n `rm -rf dist ...`, so building this package touches nothing tracked. This changes `prepack` /\n `prepublishOnly` behavior too: both call `build`, so the publish path now reads the committed\n `src/version.ts` rather than regenerating it, and the committed value is what ships.\n- **New `gen:version-check` script**, `pnpm gen:version && git diff --exit-code src/version.ts`,\n mirroring the existing `gen:types-check` in the same manifest. It runs in `.woodpecker/ci.yaml`'s\n `types-drift` step, so a manifest bump without the matching `src/version.ts` regeneration now\n fails a named PR check instead of reaching `staging`. `src/__tests__/version-parity.test.ts`\n stays in place as the in-suite assertion; the gate is what makes its failure reachable before\n merge rather than after.\n\nNo runtime or type changes. `SDK_VERSION` and the `X-ByteKit-Client: sdk_ts/<version>` affix\nbehave exactly as before.\n\n### [0.7.3] - 2026-08-18\n\n#### Changed\n\n- **`XFetchContentLength`'s description no longer calls the header a wire-byte count** (#3133).\n `X-Fetch-Content-Length` is the byte length of the response body actually served: on a\n passthrough `/v1/fetch` (no `format`) that is the relayed upstream payload, so it does equal\n the upstream wire bytes — but with `format=html` or `format=markdown` the gateway overwrites\n it with the transformed document's length, which is typically far smaller than what is billed.\n The old description therefore read as a billing discrepancy on every transform request. Billing\n is unchanged and has always used the upstream compressed wire bytes reported by `X-Raw-Bytes` /\n `X-Billable-Bytes`. Generated-type comments only; no type or runtime behavior changes.\n\n### [0.7.2] - 2026-08-17\n\n#### Changed\n\n- **`ScrapeResponses.202`'s headers no longer advertise `X-Raw-Bytes`, `X-Billable-Bytes`, or\n `X-Billing-Multiplier`** (#3068). The gateway's async `/v1/scrape` path only ever emitted\n `X-Scrape-ID` and `X-Scrape-Status: queued` on a 202 — a queued scrape has no finalized byte\n charge yet — but `docs/api/openapi.yaml` documented the billing-transparency trio there too,\n so `src/generated/api.d.ts` typed three response headers the runtime never sends. This corrects\n the generated type to match the gateway's actual behavior; it does not change any runtime\n behavior. The synchronous `200` response, and `/v1/screenshots`' `202` (which does finalize a\n charge before responding), are unaffected.\n\n### [0.7.1] - 2026-08-11\n\n#### Changed\n\n- **Generated types follow the spec's corrected error and format vocabularies** (#2959). Two\n vocabulary corrections in `docs/api/openapi.yaml` flow through `src/generated/api.d.ts`:\n - `ScrapeErrorEnvelope.error.code` no longer lists `quota_exhausted`. The API has emitted\n `quota_exceeded` since #1539 and there is no throw site for `quota_exhausted` anywhere in\n the gateway, so this removes a code that has never been sent — not one that stops being\n sent. A consumer switching on it was matching a branch that could not be reached; the\n live code for an exceeded quota is `quota_exceeded`. `invalid_url`, which the API does\n emit, is unchanged and still listed.\n - `createBulk`'s `formats` now spells the raw-HTML value `raw_html`, matching `ScrapeRequest`\n and `createScrapeBulk`. `/v1/bulk` previously accepted only the internal `rawHtml`\n spelling and the spec documented that; it now accepts both, so the one endpoint that\n disagreed with the rest of the surface no longer does. `rawHtml` keeps working.\n\n#### Added\n\n- **`ByteKitError.headers` — the failing response's headers, so you can write your own backoff**\n (#2957). This SDK performs exactly one `fetch` per call and never retries, deliberately, so that\n retry policy stays the caller's. But the policy was unwritable: `ByteKitError` carried no\n headers and `re\n\n---\n[Truncated to the 16384-byte per-page limit — this page is 159714 bytes in full. The text cut here is not searchable either: search_docs matches only the part kept above. Read all of it at https://bytekit.com/docs/changelog]"
|
|
281
281
|
},
|
|
282
282
|
"cli": {
|
|
283
283
|
"title": "Install & Authenticate",
|
|
@@ -307,7 +307,7 @@
|
|
|
307
307
|
"cli/scrape": {
|
|
308
308
|
"title": "Scrape",
|
|
309
309
|
"section": "CLI Reference",
|
|
310
|
-
"body": "# Scrape\n\nScrape URL content\n\nScrape URL content\n\n### scrape › bulk\n\nBulk scrape operations\n\n| Option | Description |\n| --- | --- |\n| `-h, --help` | display help for command |\n\n#### scrape › bulk › create\n\nCreate a bulk scrape job\n\n| Option | Description |\n| --- | --- |\n| `--file <path>` | Path to a newline-delimited file. Each line is a plain URL, or a JSON object carrying \"url\" plus per-item config. A line whose only key is \"url\" behaves exactly as before (sent as a bare URL string); any line with additional keys switches the payload to the per-item shape. |\n| `--webhook-url <url>` | HTTPS webhook URL notified when the job completes |\n| `--webhook-secret <secret>` | HMAC secret used to sign the completion webhook (omitted → unsigned) |\n| `--defaults <json>` | Defaults applied to every entry, as a JSON object (omitted → none). Unknown keys are rejected by /v1/bulk (422) and ignored by scrape bulk / fetch bulk; fetch bulk additionally rejects browser-only keys (wait_until, wait_for_selector, delay_ms) with a 400. `cookies` and `headers` are no longer accepted by any capture endpoint and 400 (#3242). |\n| `--metadata <json>` | Arbitrary metadata echoed on the job envelope, as a JSON object, e.g. '\\{\"run\":\"7\"\\}' (omitted → none) |\n| `--custom <json>` | User payload echoed on every scrape entry, as a JSON object, e.g. '\\{\"job\":\"1\"\\}' (omitted → none; a per-entry value in --file wins) |\n| `-h, --help` | display help for command |\n\n```bash\n$ bytekit scrape bulk create --file <path> --webhook-url <url> --webhook-secret <secret> --defaults <json> --metadata <json> --custom <json>\n```\n\n#### scrape › bulk › get\n\nGet a bulk scrape job\n\n| Option | Description |\n| --- | --- |\n| `-h, --help` | display help for command |\n\n```bash\n$ bytekit scrape bulk get <id>\n```\n\n### scrape › create\n\nCreate a scrape job\n\n| Option | Description |\n| --- | --- |\n| `--url <url>` | URL to scrape |\n| `--format <format>` | Output format; repeat or comma-separate for multiple (e.g. --format
|
|
310
|
+
"body": "# Scrape\n\nScrape URL content\n\nScrape URL content\n\n### scrape › bulk\n\nBulk scrape operations\n\n| Option | Description |\n| --- | --- |\n| `-h, --help` | display help for command |\n\n#### scrape › bulk › create\n\nCreate a bulk scrape job\n\n| Option | Description |\n| --- | --- |\n| `--file <path>` | Path to a newline-delimited file. Each line is a plain URL, or a JSON object carrying \"url\" plus per-item config. A line whose only key is \"url\" behaves exactly as before (sent as a bare URL string); any line with additional keys switches the payload to the per-item shape. |\n| `--webhook-url <url>` | HTTPS webhook URL notified when the job completes |\n| `--webhook-secret <secret>` | HMAC secret used to sign the completion webhook (omitted → unsigned) |\n| `--defaults <json>` | Defaults applied to every entry, as a JSON object (omitted → none). Unknown keys are rejected by /v1/bulk (422) and ignored by scrape bulk / fetch bulk; fetch bulk additionally rejects browser-only keys (wait_until, wait_for_selector, delay_ms) with a 400. `cookies` and `headers` are no longer accepted by any capture endpoint and 400 (#3242). |\n| `--metadata <json>` | Arbitrary metadata echoed on the job envelope, as a JSON object, e.g. '\\{\"run\":\"7\"\\}' (omitted → none) |\n| `--custom <json>` | User payload echoed on every scrape entry, as a JSON object, e.g. '\\{\"job\":\"1\"\\}' (omitted → none; a per-entry value in --file wins) |\n| `-h, --help` | display help for command |\n\n```bash\n$ bytekit scrape bulk create --file <path> --webhook-url <url> --webhook-secret <secret> --defaults <json> --metadata <json> --custom <json>\n```\n\n#### scrape › bulk › get\n\nGet a bulk scrape job\n\n| Option | Description |\n| --- | --- |\n| `-h, --help` | display help for command |\n\n```bash\n$ bytekit scrape bulk get <id>\n```\n\n### scrape › create\n\nCreate a scrape job\n\n| Option | Description |\n| --- | --- |\n| `--url <url>` | URL to scrape |\n| `--format <format>` | Output format; repeat or comma-separate for multiple (e.g. --format raw --format markdown, or --format raw,markdown). Sent as the formats array; omitted → server default. |\n| `--country <cc>` | Two-letter country code to route the request through (e.g. us, de) |\n| `--timeout-ms <n>` | Per-request timeout in milliseconds |\n| `--markdown-mode <mode>` | Markdown extraction mode: article, raw, llm |\n| `--markdown-query <q>` | BM25 query string for relevance-ranked markdown filtering (omitted → disabled) |\n| `--cache-ttl <ttl>` | Cache freshness: 0, Nh (hours), or Nd (days), e.g. 48h, 2d, 0 (omitted → server default) |\n| `--delay-ms <n>` | Post-load delay in milliseconds before capture |\n| `--events <csv>` | Webhook events (comma-separated): queued, completed, failed (omitted → server default) |\n| `--token-encoding <enc>` | Tokenizer for --token-budget: cl100k_base, o200k_base (omitted → server default) |\n| `--custom <json>` | User payload echoed on the envelope as a JSON object, e.g. '\\{\"job\":\"1\"\\}' (omitted → none) |\n| `--remove-base64-images` | Strip base64 data: images before conversion (server default) |\n| `--no-remove-base64-images` | Preserve base64 data: images in the pipeline output |\n| `--markdown-links <mode>` | Link rendering: inline, references, none, text |\n| `--markdown-images <mode>` | Image retention: inline, references, none, text |\n| `--with-links-summary` | Append a Links footer to the markdown output |\n| `--with-images-summary` | Append an Images footer to the markdown output |\n| `--markdown-compact` | Collapse excessive whitespace in the markdown output |\n| `--markdown-filter-images` | Filter low-signal images from the markdown output |\n| `--markdown-include-media` | Return rich link/image objects and a tables array |\n| `--markdown-include-warnings` | Include markdown-pipeline and tag-filter warnings |\n| `--markdown-include-stats` | Include a top-level stats object (chars, tokens, blocks) |\n| `--async` | Queue the scrape and return a job envelope immediately (no wait) |\n| `--webhook-url <url>` | HTTPS webhook URL notified when an async scrape completes |\n| `--token-budget <n>` | Maximum tokens of markdown to return |\n| `--clean-markdown` | Post-process markdown with the LLM cleaner (billed 3x) |\n| `--include-tags <csv>` | Comma-separated HTML tags to keep (e.g. article,main) |\n| `--exclude-tags <csv>` | Comma-separated HTML tags to drop (e.g. nav,footer) |\n| `--mobile` | Render with a mobile viewport/user-agent |\n| `--raw` | Print the requested format body raw, with no JSON wrapper |\n| `-o, --output <file>` | Write the output to the given file path (implies --raw unless --json is set) |\n| `-h, --help` | display help for command |\n\n```bash\n$ bytekit scrape create --url <url> --format <format> --country <cc> --timeout-ms <n> --markdown-mode <mode> --markdown-query <q> --cache-ttl <ttl> --delay-ms <n> --events <csv> --token-encoding <enc> --custom <json> --remove-base64-images --no-remove-base64-images --markdown-links <mode> --markdown-images <mode> --with-links-summary --with-images-summary --markdown-compact --markdown-filter-images --markdown-include-media --markdown-include-warnings --markdown-include-stats --async --webhook-url <url> --token-budget <n> --clean-markdown --include-tags <csv> --exclude-tags <csv> --mobile --raw\n```\n\n### scrape › get\n\nGet a scrape job by ID (use --raw/-o/--format to retrieve a completed body)\n\n| Option | Description |\n| --- | --- |\n| `--raw` | Print the requested format body raw, with no JSON wrapper |\n| `-o, --output <file>` | Write the output to the given file path (implies --raw unless --json is set) |\n| `--format <format>` | Which persisted format to emit — only takes effect with --raw/-o; ignored otherwise |\n| `-h, --help` | display help for command |\n\n```bash\n$ bytekit scrape get <id> --raw --format <format>\n```"
|
|
311
311
|
},
|
|
312
312
|
"cli/screenshots": {
|
|
313
313
|
"title": "Screenshots",
|
|
@@ -347,7 +347,7 @@
|
|
|
347
347
|
"guides/errors": {
|
|
348
348
|
"title": "Errors",
|
|
349
349
|
"section": "Guides",
|
|
350
|
-
"body": "# Errors\n\nByteKit error response shape, common error codes, and retry guidance.\n\nAll errors from the ByteKit API follow a consistent envelope shape so you can handle them\nprogrammatically.\n\n## Error response shape\n\nEvery `4xx`/`5xx` response across the API uses one unified envelope. `status` is\nalways the literal string `\"failed\"`, so you can branch on the response body alone.\n\n```json\n{\n \"status\": \"failed\",\n \"error\": {\n \"code\": \"rate_limited\",\n \"message\": \"Rate limit exceeded. Allowed 5 requests per second.\",\n \"http_status\": 429,\n \"failed_at\": \"2026-08-27T12:17:46.234Z\"\n }\n}\n```\n\nThe number in a `rate_limited` message is your own plan's per-second limit — the same value the `X-RateLimit-Limit` response header carries.\n\n| Field | Description |\n|-------|-------------|\n| `status` | Always `\"failed\"` on an error response — the top-level discriminator |\n| `error.code` | Machine-readable string identifier |\n| `error.message` | Human-readable explanation |\n| `error.http_status` | Mirrors the HTTP response status (useful for logged or replayed bodies) |\n| `error.failed_at` | ISO-8601 UTC timestamp of when the error was produced |\n| `error.details` | Optional object with additional context (e.g. which field failed validation). Absent — not `{}` — when the error carries no context |\n\n## Common error codes\n\n| HTTP status | Code | Meaning |\n|-------------|------|---------|\n| `400` | `invalid_url` | A supplied URL (including `webhook_url`) is malformed or uses an unsupported scheme |\n| `401` | `unauthorized` | Missing or malformed `Authorization` header |\n| `401` | `invalid_api_key` | API key is present but not valid |\n| `402` | `quota_exceeded` | Account has exceeded its plan quota |\n| `402` | `spending_cap_reached` | A credit-metered request would push overage spend past the account's cap. Only reachable on a custom plan with an overage agreement — standard plans have no automatic overage and stop at `quota_exceeded` |\n| `403` | `forbidden` | Key is valid but lacks permission for this action |\n| `422` | `validation_error` | Malformed JSON or a request field failed validation |\n| `429` | `rate_limited` | Too many requests per second; back off and retry |\n| `429` | `concurrency_limit` | Too many simultaneous in-flight requests; back off and retry |\n| `500` | `internal_error` | The upstream fetch or browser render failed |\n\n## Webhook URLs Must Use HTTPS\n\nAll webhook URLs submitted to the ByteKit API must use HTTPS. Plain HTTP URLs (e.g. `http://example.com/webhook`) are rejected with a `400` `invalid_url` error.\n\n**Why HTTPS only?** Webhook payloads may contain sensitive data (API keys, session tokens, scrape results). HTTPS encryption protects this data in transit.\n\n**Request with an invalid webhook URL:**\n\n```json\n{\n \"webhook_url\": \"http://example.com/webhook\"\n}\n```\n\n**Response (HTTP 400)** — the same unified envelope as every other error; `error.details` names the offending field and reason:\n\n```json\n{\n \"status\": \"failed\",\n \"error\": {\n \"code\": \"invalid_url\",\n \"message\": \"url is not a valid HTTP(S) URL: scheme_unsupported\",\n \"http_status\": 400,\n \"failed_at\": \"2026-08-27T12:16:29.033Z\",\n \"details\": {\n \"url\": \"http://example.com/webhook\",\n \"field\": \"webhook_url\",\n \"reason\": \"scheme_unsupported\"\n }\n }\n}\n```\n\n**Working example:**\n\n```json\n{\n \"webhook_url\": \"https://example.com/webhook\"\n}\n```\n\nThis applies to all endpoints that accept a `webhook_url` parameter: `/v1/scrape` (async), `/v1/scrape/bulk`, `/v1/fetch/bulk`, `/v1/bulk`, `/v1/monitors`, and `/v1/sitemap`.\n\n## Retry guidance\n\nNot all errors are retryable. Use this table to decide:\n\n| Code | Retry? | Guidance |\n|------|--------|---------|\n| `invalid_url` | No | Fix the URL before retrying |\n| `validation_error` | No | Fix the request body before retrying |\n| `unauthorized` / `invalid_api_key` | No | Check your API key |\n| `quota_exceeded` | No | Upgrade your plan or wait for quota reset |\n| `spending_cap_reached` | No | The overage cap is account-level and has no self-service control — [contact support](https://bytekit.com/docs/billing/spending) to raise it, or upgrade the plan |\n| `forbidden` | No | You do not have access to this resource |\n| `rate_limited` | Yes | Exponential backoff; honour the `Retry-After` header |\n| `concurrency_limit` | Yes | Honour the `Retry-After` header (a short fixed back-off — a slot frees on job completion, not a fixed window) |\n| `internal_error` | Yes | Exponential backoff; most resolve on retry |\n\nFor retriable errors, start with a 1-second delay and double on each subsequent failure, up to\na maximum of 60 seconds. Respect the `Retry-After` header value when it is present on `429`\nresponses.\n\n## Example: handling errors in curl\n\n```bash\nresponse=$(curl -s -w \"\\n%{http_code}\" -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\": \"https://example.com\"}')\n\nhttp_code=$(echo \"$response\" | tail -1)\n# Body is everything except the trailing status-code line — drop only the last\n# line so multi-line JSON responses survive intact.\nbody=$(echo \"$response\" | sed '$d')\n\nif [ \"$http_code\" -ge 400 ]; then\n echo \"Error $http_code: $body\"\nfi\n```\n\n## Next steps\n\n- [Rate Limits](https://bytekit.com/docs/guides/rate-limits) — quota model, concurrency slots, rate limit headers\n- [Scraping](https://bytekit.com/docs/guides/scraping) — when `500 internal_error` occurs and how fallback works\n- [API Reference](https://bytekit.com/docs/api) — per-endpoint error codes"
|
|
350
|
+
"body": "# Errors\n\nByteKit error response shape, common error codes, and retry guidance.\n\nAll errors from the ByteKit API follow a consistent envelope shape so you can handle them\nprogrammatically.\n\n## Error response shape\n\nEvery `4xx`/`5xx` response across the API uses one unified envelope. `status` is\nalways the literal string `\"failed\"`, so you can branch on the response body alone.\n\n```json\n{\n \"status\": \"failed\",\n \"error\": {\n \"code\": \"rate_limited\",\n \"message\": \"Rate limit exceeded. Allowed 5 requests per second.\",\n \"http_status\": 429,\n \"failed_at\": \"2026-08-27T12:17:46.234Z\"\n }\n}\n```\n\nThe number in a `rate_limited` message is your own plan's per-second limit — the same value the `X-RateLimit-Limit` response header carries.\n\n| Field | Description |\n|-------|-------------|\n| `status` | Always `\"failed\"` on an error response — the top-level discriminator |\n| `error.code` | Machine-readable string identifier |\n| `error.message` | Human-readable explanation |\n| `error.http_status` | Mirrors the HTTP response status (useful for logged or replayed bodies) |\n| `error.failed_at` | ISO-8601 UTC timestamp of when the error was produced |\n| `error.details` | Optional object with additional context (e.g. which field failed validation). Absent — not `{}` — when the error carries no context |\n\n## Common error codes\n\n| HTTP status | Code | Meaning |\n|-------------|------|---------|\n| `400` | `invalid_url` | A supplied URL (including `webhook_url`) is malformed or uses an unsupported scheme |\n| `400` | `validation_error` | Field errors on `/v1/search`, `POST /v1/billing/checkout` and `PUT`/`DELETE /v1/billing/payment-methods/{id}`, plus rejections that run before schema validation on any endpoint: a removed field such as `cookies` or `headers` on a capture endpoint, or a `/v1/fetch` or `/v1/fetch/bulk` request asking for an option only `/v1/scrape` or `/v1/bulk` serves |\n| `401` | `unauthorized` | Missing or malformed `Authorization` header |\n| `401` | `invalid_api_key` | API key is present but not valid |\n| `402` | `quota_exceeded` | Account has exceeded its plan quota |\n| `402` | `spending_cap_reached` | A credit-metered request would push overage spend past the account's cap. Only reachable on a custom plan with an overage agreement — standard plans have no automatic overage and stop at `quota_exceeded` |\n| `402` | `billing_entitlement_impaired` | The paid subscription is in a payment impairment (e.g. `past_due`); `error.message` names the reason |\n| `402` | `billing_entitlement_expired` | The paid subscription's entitlement period has ended, or its dunning grace period has run out |\n| `403` | `forbidden` | Key is valid but lacks permission for this action |\n| `422` | `validation_error` | Malformed JSON, or a request field failed validation, everywhere the `400` row above does not name |\n| `429` | `rate_limited` | Too many requests per second; back off and retry |\n| `429` | `concurrency_limit` | Too many simultaneous in-flight requests; back off and retry |\n| `500` | `internal_error` | The upstream fetch or browser render failed |\n\n## Webhook URLs Must Use HTTPS\n\nAll webhook URLs submitted to the ByteKit API must use HTTPS. Plain HTTP URLs (e.g. `http://example.com/webhook`) are rejected with a `400` `invalid_url` error.\n\n**Why HTTPS only?** Webhook payloads may contain sensitive data (API keys, session tokens, scrape results). HTTPS encryption protects this data in transit.\n\n**Request with an invalid webhook URL:**\n\n```json\n{\n \"webhook_url\": \"http://example.com/webhook\"\n}\n```\n\n**Response (HTTP 400)** — the same unified envelope as every other error; `error.details` names the offending field and reason:\n\n```json\n{\n \"status\": \"failed\",\n \"error\": {\n \"code\": \"invalid_url\",\n \"message\": \"url is not a valid HTTP(S) URL: scheme_unsupported\",\n \"http_status\": 400,\n \"failed_at\": \"2026-08-27T12:16:29.033Z\",\n \"details\": {\n \"url\": \"http://example.com/webhook\",\n \"field\": \"webhook_url\",\n \"reason\": \"scheme_unsupported\"\n }\n }\n}\n```\n\n**Working example:**\n\n```json\n{\n \"webhook_url\": \"https://example.com/webhook\"\n}\n```\n\nThis applies to all endpoints that accept a `webhook_url` parameter: `/v1/scrape` (async), `/v1/scrape/bulk`, `/v1/fetch/bulk`, `/v1/bulk`, `/v1/monitors`, and `/v1/sitemap`.\n\n## Retry guidance\n\nNot all errors are retryable. Use this table to decide:\n\n| Code | Retry? | Guidance |\n|------|--------|---------|\n| `invalid_url` | No | Fix the URL before retrying |\n| `validation_error` | No | Fix the request body before retrying |\n| `unauthorized` / `invalid_api_key` | No | Check your API key |\n| `quota_exceeded` | No | Upgrade your plan or wait for quota reset |\n| `spending_cap_reached` | No | The overage cap is account-level and has no self-service control — [contact support](https://bytekit.com/docs/billing/spending) to raise it, or upgrade the plan |\n| `billing_entitlement_impaired` | No | Settle the outstanding invoice — retrying cannot succeed while the subscription is impaired |\n| `billing_entitlement_expired` | No | Restore or renew the subscription; the entitlement period has ended |\n| `forbidden` | No | You do not have access to this resource |\n| `rate_limited` | Yes | Exponential backoff; honour the `Retry-After` header |\n| `concurrency_limit` | Yes | Honour the `Retry-After` header (a short fixed back-off — a slot frees on job completion, not a fixed window) |\n| `internal_error` | Yes | Exponential backoff; most resolve on retry |\n\nFor retriable errors, start with a 1-second delay and double on each subsequent failure, up to\na maximum of 60 seconds. Respect the `Retry-After` header value when it is present on `429`\nresponses.\n\n## Example: handling errors in curl\n\n```bash\nresponse=$(curl -s -w \"\\n%{http_code}\" -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\": \"https://example.com\"}')\n\nhttp_code=$(echo \"$response\" | tail -1)\n# Body is everything except the trailing status-code line — drop only the last\n# line so multi-line JSON responses survive intact.\nbody=$(echo \"$response\" | sed '$d')\n\nif [ \"$http_code\" -ge 400 ]; then\n echo \"Error $http_code: $body\"\nfi\n```\n\n## Next steps\n\n- [Rate Limits](https://bytekit.com/docs/guides/rate-limits) — quota model, concurrency slots, rate limit headers\n- [Scraping](https://bytekit.com/docs/guides/scraping) — when `500 internal_error` occurs and how fallback works\n- [API Reference](https://bytekit.com/docs/api) — per-endpoint error codes"
|
|
351
351
|
},
|
|
352
352
|
"guides/monitors": {
|
|
353
353
|
"title": "Monitors",
|
|
@@ -357,12 +357,12 @@
|
|
|
357
357
|
"guides/rate-limits": {
|
|
358
358
|
"title": "Rate Limits",
|
|
359
359
|
"section": "Guides",
|
|
360
|
-
"body": "# Rate Limits\n\nHow ByteKit enforces quotas, concurrency slots, and rate limits.\n\nByteKit enforces three independent limits: **rate limits** (requests per second),\n**concurrency slots** (simultaneous in-flight requests), and **quota** (monthly usage caps).\nAll three are enforced before any capture work begins.\n\n## Quota model\n\nQuota is pre-incremented on every request and corrected after the request completes:\n\n1. **Pre-increment** — your usage counter is incremented by an estimate before the capture\n starts. This prevents over-committing capacity even for concurrent requests.\n2. **Adjust** — once the response returns, the actual `content_length` (compressed wire bytes)\n replaces the estimate for bandwidth accounting.\n3. **Compensating decrement** — if the request fails with a terminal error, the pre-incremented\n amount is rolled back so
|
|
360
|
+
"body": "# Rate Limits\n\nHow ByteKit enforces quotas, concurrency slots, and rate limits.\n\nByteKit enforces three independent limits: **rate limits** (requests per second),\n**concurrency slots** (simultaneous in-flight requests), and **quota** (monthly usage caps).\nAll three are enforced before any capture work begins.\n\n## Quota model\n\nQuota is pre-incremented on every request and corrected after the request completes:\n\n1. **Pre-increment** — your usage counter is incremented by an estimate before the capture\n starts. This prevents over-committing capacity even for concurrent requests.\n2. **Adjust** — once the response returns, the actual `content_length` (compressed wire bytes)\n replaces the estimate for bandwidth accounting.\n3. **Compensating decrement** — if the request fails with a terminal error, the pre-incremented\n amount is rolled back, so a capture that returns no bytes costs nothing.\n\nTwo charges survive a failure. A `/v1/fetch` request answered from the cache with a non-2xx\nupstream status is served from the cached body and billed at the cache-hit rate, and a failed\nschema extraction refunds the credits it pre-charged but keeps the source page's bandwidth.\n\nThis means your dashboard usage counter may briefly read higher than actual consumption during\na burst of requests, then settle to the true value.\n\n## Concurrency slots\n\nEach account has a concurrency limit — the maximum number of in-flight requests at one time.\nSlots are released automatically a few minutes after a client disconnects, so a crashed client\ncannot permanently hold them.\n\nWhen you exceed your concurrency limit, you receive `429 concurrency_limit` (not\n`rate_limited` — a distinct error code) with a `Retry-After` header indicating how long to\nwait before retrying.\n\n## Rate limit headers\n\nEvery response includes headers that show your current position:\n\n| Header | Description |\n|--------|-------------|\n| `X-RateLimit-Limit` | Your account's request-per-second limit |\n| `X-RateLimit-Remaining` | Requests remaining in the current window |\n| `X-RateLimit-Reset` | Unix timestamp when the window resets |\n| `Retry-After` | Seconds to wait before retrying (present on `429` only) |\n\n## Bandwidth metering\n\nBandwidth usage is measured as `content_length` — the compressed wire bytes returned by the\norigin server. If the origin sends gzip or Brotli-encoded content, the compressed size is what\ncounts, not the decompressed size. This matches what your client actually receives over the\nnetwork.\n\nThat measurement is the basis, not the charge. Your balance is deducted by the wire bytes times\nthe endpoint factor, so a Markdown scrape deducts 1.5× its `content_length` — and so does a\nMarkdown fetch. See [Bandwidth billing](https://bytekit.com/docs/billing/bandwidth) for the full composition.\n\n## Handling 429 responses\n\nWhen you receive `429 rate_limited` or `429 concurrency_limit`:\n\n1. Read the `Retry-After` header value (in seconds).\n2. Wait at least that long before retrying.\n3. If no `Retry-After` is present, use exponential backoff starting at 1 second.\n\n```bash\n# Check rate limit headers\ncurl -I -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\": \"https://example.com\"}'\n```\n\n## Next steps\n\n- [Errors](https://bytekit.com/docs/guides/errors) — full error code reference and retry guidance\n- [Scraping](https://bytekit.com/docs/guides/scraping) — formats, options, latency, and async polling"
|
|
361
361
|
},
|
|
362
362
|
"guides/scraping": {
|
|
363
363
|
"title": "Scraping",
|
|
364
364
|
"section": "Guides",
|
|
365
|
-
"body": "# Scraping\n\nScrape any URL as HTML, markdown, or structured content — formats, options, latency, and async polling.\n\n`POST /v1/scrape` fetches a URL and returns its content in the format you ask for. The same\nrequest shape works for every site; the options you pass determine the output and how long the\ncall takes.\n\n## Rendering & latency\n\nMost scrapes return in well under a second. Some options require ByteKit to fully render the page\nbefore it can return content, which takes longer — typically a few seconds. Pass these only when\nyou need them:\n\n| Option | When it adds latency |\n|--------|----------------------|\n| `delay_ms` | Greater than `0` |\n| `async` | `true` (request is queued and processed off the fast path) |\n\nThe `country` option routes the request through a geo-located proxy. On its own it does not add\nrendering latency; it only does so when combined with one of the options above.\n\nLooking for `wait_for_selector` or `wait_until`? Those are not `ScrapeRequest` options — they\nbelong to the [Screenshot](https://bytekit.com/docs/api/screenshots/createscreenshot) endpoint. Sending them to\n`/v1/scrape` returns `422`.\n\n`cookies` and `headers` are no longer request options on any capture endpoint. Sending either\nreturns `400 validation_error`.\n\n```bash\n# A simple, low-latency scrape\ncurl -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\": \"https://example.com\"}'\n```\n\n```bash\n# Slower: delay_ms forces a full render and waits before returning\ncurl -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"url\": \"https://example.com\",\n \"delay_ms\": 2000\n }'\n```\n\n## Response fields\n\nThe default format is `
|
|
365
|
+
"body": "# Scraping\n\nScrape any URL as HTML, markdown, or structured content — formats, options, latency, and async polling.\n\n`POST /v1/scrape` fetches a URL and returns its content in the format you ask for. The same\nrequest shape works for every site; the options you pass determine the output and how long the\ncall takes.\n\n## Rendering & latency\n\nMost scrapes return in well under a second. Some options require ByteKit to fully render the page\nbefore it can return content, which takes longer — typically a few seconds. Pass these only when\nyou need them:\n\n| Option | When it adds latency |\n|--------|----------------------|\n| `delay_ms` | Greater than `0` |\n| `async` | `true` (request is queued and processed off the fast path) |\n\nThe `country` option routes the request through a geo-located proxy. On its own it does not add\nrendering latency; it only does so when combined with one of the options above.\n\nLooking for `wait_for_selector` or `wait_until`? Those are not `ScrapeRequest` options — they\nbelong to the [Screenshot](https://bytekit.com/docs/api/screenshots/createscreenshot) endpoint. Sending them to\n`/v1/scrape` returns `422`.\n\n`cookies` and `headers` are no longer request options on any capture endpoint. Sending either\nreturns `400 validation_error`.\n\n```bash\n# A simple, low-latency scrape\ncurl -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\": \"https://example.com\"}'\n```\n\n```bash\n# Slower: delay_ms forces a full render and waits before returning\ncurl -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"url\": \"https://example.com\",\n \"delay_ms\": 2000\n }'\n```\n\n## Response fields\n\nThe default format is `raw` — pass `formats` to request others (`markdown`, `links`,\n`images`). The `formats` object in the response is keyed by the format you requested.\n\nEnvelope fields are `snake_case`; the keys inside `metadata` are the page's own metadata and\nstay `camelCase`.\n\n| Field | Description |\n|-------|-------------|\n| `schema_version` | Response envelope version (currently `1`) |\n| `formats.raw` | Page content in the requested format (`raw` is the default when `formats` is omitted) |\n| `final_url` | URL the fetch landed on after redirects |\n| `content_type` | `Content-Type` reported by the origin |\n| `content_length` | Compressed wire bytes — the *basis* for bandwidth billing, before the endpoint factor (see `billing`) |\n| `status_code` | HTTP status code of the origin page |\n| `retrieved_at` | ISO-8601 UTC timestamp of the fetch |\n| `cache` | `\"hit\"` or `\"miss\"` |\n| `cache_age_s` | Age of the cached entry in seconds — present only on a hit |\n| `billing` | What the request cost: `raw_bytes`, the `factors` applied, the resulting `multiplier`, and `billed_bytes` |\n| `metadata.title` | Page `<title>` element |\n\nThe `X-Scrape-*` response headers describe how each request was handled (cache status, timing,\nand the final URL) — useful for debugging.\n\n## Async scrapes\n\nFor long-running pages, pass `\"async\": true` to get a `202 Accepted` response with a scrape\n`id` prefixed `sc_`. Poll the result with `GET /v1/scrape/{id}`.\n\n```bash\n# Start async scrape\ncurl -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\": \"https://example.com\", \"async\": true}'\n\n# Poll for result\ncurl https://api.bytekit.com/v1/scrape/sc_... \\\n -H \"Authorization: Bearer sk_live_YOUR_KEY_HERE\"\n```\n\n## Webhook event header\n\nEvery outbound webhook POST includes an `X-ByteKit-Event` header with the event type:\n\n| Event type | Trigger |\n|---|---|\n| `bulk.completed` | A bulk job finishes (all items processed) |\n| `scrape.completed` | An async scrape succeeds |\n| `scrape.failed` | An async scrape fails terminally |\n| `monitor.change_detected` | A monitor fires and detects a change (screenshot or content) |\n| `monitor.captured` | A monitor fires with no change detected (notify_on: every) |\n| `sitemap.completed` | A sitemap job finishes |\n| `sitemap.failed` | A sitemap job fails terminally |\n\nUse this header to dispatch events without inspecting the body shape:\n\n```python\nfrom flask import Flask, request\n\napp = Flask(__name__)\n\n@app.route(\"/webhooks/bytekit\", methods=[\"POST\"])\ndef handle():\n event = request.headers.get(\"X-ByteKit-Event\")\n if event == \"bulk.completed\":\n handle_bulk(request.json)\n elif event == \"scrape.completed\":\n handle_scrape(request.json)\n return \"\", 200\n```\n\n`X-ByteKit-Event` is a reserved header — you cannot supply it via `webhook_headers` in\nmonitor or bulk configuration. Attempts to do so will be rejected with a `422` at request\ntime.\n\n## Next steps\n\n- [Rate Limits](https://bytekit.com/docs/guides/rate-limits) — quota model and concurrency slots\n- [Errors](https://bytekit.com/docs/guides/errors) — how to interpret and retry error responses\n- [API Reference: Scrape](https://bytekit.com/docs/api/scrape/createscrape) — full request/response schema"
|
|
366
366
|
},
|
|
367
367
|
"guides/webhooks": {
|
|
368
368
|
"title": "Webhooks",
|
|
@@ -402,7 +402,7 @@
|
|
|
402
402
|
"quickstart": {
|
|
403
403
|
"title": "Quickstart",
|
|
404
404
|
"section": "General",
|
|
405
|
-
"body": "# Quickstart\n\nMake your first ByteKit API call in under 5 minutes — no SDK required.\n\nNothing to install. You only need `curl` and an API key.\n\n## Get an API key\n\nSign up at [app.bytekit.com](https://app.bytekit.com) and create an API key from the\ndashboard. Keys are prefixed `sk_live_`.\n\nSee [Authentication](https://bytekit.com/docs/guides/authentication) for details on key formats and management.\n\n## Make your first scrape\n\nSet your API key and run this — no file to save, no `chmod`:\n\n```bash\ncurl -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer $BYTEKIT_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\":\"https://example.com\"}'\n```\n\nWant a full-featured script with error handling and `jq` formatting? Use this instead:\n\n<!-- example omitted: curl/scrape.sh (source unavailable) -->\n\nA successful response looks like this — every envelope field is `snake_case`:\n\n```json\n{\n \"schema_version\": 1,\n \"status\": \"success\",\n \"id\": \"sc_84c14b1058184045b97ae360ad74888b\",\n \"url\": \"https://example.com\",\n \"final_url\": \"https://example.com\",\n \"content_type\": \"text/html\",\n \"content_length\": 318,\n \"status_code\": 200,\n \"retrieved_at\": \"2026-08-27T12:16:01.872Z\",\n \"formats\": {\n \"
|
|
405
|
+
"body": "# Quickstart\n\nMake your first ByteKit API call in under 5 minutes — no SDK required.\n\nNothing to install. You only need `curl` and an API key.\n\n## Get an API key\n\nSign up at [app.bytekit.com](https://app.bytekit.com) and create an API key from the\ndashboard. Keys are prefixed `sk_live_`.\n\nSee [Authentication](https://bytekit.com/docs/guides/authentication) for details on key formats and management.\n\n## Make your first scrape\n\nSet your API key and run this — no file to save, no `chmod`:\n\n```bash\ncurl -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer $BYTEKIT_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\":\"https://example.com\"}'\n```\n\nWant a full-featured script with error handling and `jq` formatting? Use this instead:\n\n<!-- example omitted: curl/scrape.sh (source unavailable) -->\n\nA successful response looks like this — every envelope field is `snake_case`:\n\n```json\n{\n \"schema_version\": 1,\n \"status\": \"success\",\n \"id\": \"sc_84c14b1058184045b97ae360ad74888b\",\n \"url\": \"https://example.com\",\n \"final_url\": \"https://example.com\",\n \"content_type\": \"text/html\",\n \"content_length\": 318,\n \"status_code\": 200,\n \"retrieved_at\": \"2026-08-27T12:16:01.872Z\",\n \"formats\": {\n \"raw\": \"<!doctype html><html lang=\\\"en\\\"><head><title>Example Domain</title>…</html>\\n\"\n },\n \"metadata\": {\n \"title\": \"Example Domain\",\n \"description\": null,\n \"language\": \"en\",\n \"canonicalUrl\": null,\n \"ogTitle\": null,\n \"ogDescription\": null,\n \"ogImage\": null,\n \"ogUrl\": null,\n \"ogSiteName\": null,\n \"robots\": null,\n \"byline\": null,\n \"publishedAt\": null\n },\n \"cache\": \"miss\",\n \"billing\": {\n \"raw_bytes\": 318,\n \"factors\": [{ \"name\": \"endpoint\", \"value\": 1, \"reason\": \"scrape\" }],\n \"multiplier\": 1,\n \"billed_bytes\": 318\n }\n}\n```\n\n`content_length` is the compressed wire size in bytes (used for bandwidth billing), and\n`billing` breaks down what the request actually cost. `cache` is `\"miss\"` or `\"hit\"`, and a\nhit adds a `cache_age_s` field. The `id` field uses the `sc_` prefix — you can poll\n`GET /v1/scrape/{id}` if the scrape was queued asynchronously.\n\nThe keys inside `metadata` stay `camelCase` (`canonicalUrl`, `ogTitle`, …): they are the\npage's own metadata, not envelope fields.\n\n## Ask for markdown\n\nThe default format is `raw` — that is why the response above carries no\n`formats.markdown`. Request markdown explicitly:\n\n```bash\ncurl -X POST https://api.bytekit.com/v1/scrape \\\n -H \"Authorization: Bearer $BYTEKIT_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\":\"https://example.com\",\"formats\":[\"markdown\"]}'\n```\n\nMarkdown output is billed at **1.5×** the request's upstream wire bytes — the `endpoint`\nfactor in the `billing` node below is the rate your balance is charged, not a display\nweighting. See [Bandwidth billing](https://bytekit.com/docs/billing/bandwidth) for how the factors compose.\n\nThe response's `formats` object is keyed by what you asked for:\n\n```json\n{\n \"schema_version\": 1,\n \"status\": \"success\",\n \"id\": \"sc_f659fa67dfb244159767132c2aa50917\",\n \"url\": \"https://example.com\",\n \"final_url\": \"https://example.com\",\n \"content_type\": \"text/html\",\n \"content_length\": 318,\n \"status_code\": 200,\n \"retrieved_at\": \"2026-08-27T12:16:11.337Z\",\n \"formats\": {\n \"markdown\": \"---\\ntitle: \\\"Example Domain\\\"\\nurl: \\\"https://example.com\\\"\\ncaptured_at: \\\"2026-08-27T12:16:11.416Z\\\"\\n---\\nThis domain is for use in documentation examples without needing permission. Avoid use in operations.\\n\\n[Learn more](https://iana.org/domains/example)\"\n },\n \"metadata\": {\n \"title\": \"Example Domain\",\n \"description\": null,\n \"language\": \"en\",\n \"canonicalUrl\": null,\n \"ogTitle\": null,\n \"ogDescription\": null,\n \"ogImage\": null,\n \"ogUrl\": null,\n \"ogSiteName\": null,\n \"robots\": null,\n \"byline\": null,\n \"publishedAt\": null\n },\n \"cache\": \"hit\",\n \"cache_age_s\": 8,\n \"billing\": {\n \"raw_bytes\": 318,\n \"factors\": [\n { \"name\": \"endpoint\", \"value\": 1.5, \"reason\": \"scrape_md\" },\n { \"name\": \"cache_hit\", \"value\": 0.5, \"reason\": \"hit, age 8s\" }\n ],\n \"multiplier\": 0.75,\n \"billed_bytes\": 239\n }\n}\n```\n\nSee [Scraping](https://bytekit.com/docs/guides/scraping) for the other formats (`markdown`, `links`, `images`).\n\n## Prefer an SDK?\n\nSkip the raw HTTP and use an official client:\n\n- [TypeScript SDK](https://bytekit.com/docs/libraries/typescript) — `npm install @hunt-labs/bytekit-sdk`\n- [Python SDK](https://bytekit.com/docs/libraries/python) — `pip install bytekit-sdk`\n\n## Next steps\n\n- [Authentication](https://bytekit.com/docs/guides/authentication) — key formats, Bearer header, self-serve key management\n- [Scraping](https://bytekit.com/docs/guides/scraping) — formats, options, latency, and async polling\n- [Errors](https://bytekit.com/docs/guides/errors) — error shape, common codes, retry guidance\n- [Rate Limits](https://bytekit.com/docs/guides/rate-limits) — quota model, concurrency slots, rate limit headers\n- [Monitors](https://bytekit.com/docs/guides/monitors) — page-change detection (screenshot or scrape) with webhook notifications\n- [API Reference](https://bytekit.com/docs/api) — full endpoint documentation"
|
|
406
406
|
},
|
|
407
407
|
"sdk": {
|
|
408
408
|
"title": "SDK Reference",
|
|
@@ -507,7 +507,7 @@
|
|
|
507
507
|
"sdk/typescript/scrape": {
|
|
508
508
|
"title": "Scrape",
|
|
509
509
|
"section": "SDK Reference",
|
|
510
|
-
"body": "# Scrape\n\nFetch a URL as raw HTML, clean markdown, or structured content. Accessed via `client.scrape`.\n\n## create\n\n```ts\nclient.scrape.create(opts: ScrapeOpts, requestOptions?: RequestOptions): Promise<ScrapeCreateResponse>\n```\n\nPOST /v1/scrape — create a scrape job.\n\nResolves to the 200 success envelope, or the 202 queued envelope when\n`async: true`. Narrow on `status` before reading the result.\n\n`requestOptions` carries the CLIENT-side abort budget (`requestTimeoutMs`) and an\noptional caller `signal`; both override the constructor's `timeoutMs` default. They\nare a different axis from `opts.timeout_ms`, which is the SERVER-side scrape budget.\n\n## get\n\n```ts\nclient.scrape.get(id: ScrapeId, requestOptions?: RequestOptions): Promise<ScrapeGetResponse>\n```\n\nGET /v1/scrape/\\{id\\} — poll a scrape by ID\n\n## Options (`ScrapeOpts`)\n\n- `url` (required) — `string`\n- `formats` — `Array<'
|
|
510
|
+
"body": "# Scrape\n\nFetch a URL as raw HTML, clean markdown, or structured content. Accessed via `client.scrape`.\n\n## create\n\n```ts\nclient.scrape.create(opts: ScrapeOpts, requestOptions?: RequestOptions): Promise<ScrapeCreateResponse>\n```\n\nPOST /v1/scrape — create a scrape job.\n\nResolves to the 200 success envelope, or the 202 queued envelope when\n`async: true`. Narrow on `status` before reading the result.\n\n`requestOptions` carries the CLIENT-side abort budget (`requestTimeoutMs`) and an\noptional caller `signal`; both override the constructor's `timeoutMs` default. They\nare a different axis from `opts.timeout_ms`, which is the SERVER-side scrape budget.\n\n## get\n\n```ts\nclient.scrape.get(id: ScrapeId, requestOptions?: RequestOptions): Promise<ScrapeGetResponse>\n```\n\nGET /v1/scrape/\\{id\\} — poll a scrape by ID\n\n## Options (`ScrapeOpts`)\n\n- `url` (required) — `string`\n- `formats` — `Array<'raw' | 'markdown' | 'links' | 'images'>`\n- `country` — `string`\n- `delay_ms` — `number`\n- `timeout_ms` — `number` — SERVER-side scrape budget in ms — how long the gateway may spend on the scrape itself. For the CLIENT-side abort budget (when this SDK gives up on the wire), see `RequestOptions.requestTimeoutMs`.\n- `async` — `boolean`\n- `webhook_url` — `string`\n- `events` — `Array<'queued' | 'completed' | 'failed'>`\n- `markdown_mode` — `MarkdownMode` — Markdown processing mode. article=article extraction (default), raw=minimal cleanup, llm=compact LLM-optimised output.\n- `markdown_query` — `string` — BM25 query string for relevance-ranked content filtering. Omit or leave empty to disable.\n- `markdown_links` — `MarkdownLinks` — Link rendering style in the markdown output.\n- `markdown_images` — `MarkdownImages` — Image retention mode in the markdown output. Distinct from `markdown_filter_images` (which drops low-signal images before conversion).\n- `with_links_summary` — `boolean` — When true, appends a `Links:` footer to the markdown output. Automatically enabled when `markdown_links` is `'references'`.\n- `with_images_summary` — `boolean` — When true, appends an `Images:` footer to the markdown output.\n- `markdown_compact` — `boolean` — Collapse excessive whitespace for a more compact output.\n- `markdown_filter_images` — `boolean` — Filter low-signal images from the markdown output.\n- `markdown_include_media` — `boolean` — When true, `formats.links` and `formats.images` return `ScrapeScoredLink[]` / `ScrapeScoredImage[]` (rich objects) instead of `string[]`, and a top-level `tables` array is included. Only effective when `markdown` is in `formats`.\n- `markdown_include_warnings` — `boolean` — When true, the response includes markdown-pipeline and tag-filter warnings. `artifact_unavailable` may appear independently when a requested persisted format cannot be rehydrated.\n- `markdown_include_stats` — `boolean` — When true, the response includes a top-level `stats` object with `ScrapeStats` (chars, tokens, blocks). Only effective when `markdown` is in `formats`.\n- `token_budget` — `number` — Maximum token count for the markdown output. Truncates at the last paragraph → sentence → token boundary under the limit. Absent → no truncation.\n- `token_encoding` — `TokenEncoding` — Tokenizer encoding hint for `token_budget`. `cl100k_base` (default) matches GPT-4/4o; `o200k_base` matches GPT-4o-mini / o-series.\n- `mobile` — `boolean` — When true, emulate a mobile device (mobile UA + viewport). Default false (desktop). Part of the cache key, so mobile and desktop responses cache independently.\n- `remove_base64_images` — `boolean` — When true (default), base64-encoded `data:` image sources are stripped before markdown conversion. Set false to preserve them. Does not affect `raw`.\n- `include_tags` — `string[]` — HTML element names (not CSS selectors) to keep. When non-empty, only content within these elements is included in `markdown` output. Applied before `exclude_tags`. Does not affect `raw`.\n- `exclude_tags` — `string[]` — HTML element names (not CSS selectors) to strip from `markdown` output. Applied after `include_tags`. Does not affect `raw`.\n- `clean_markdown` — `boolean` — When true and `markdown` is in `formats`, the converted markdown is sent to Groq for cleaning before return. Graceful degradation on any Groq failure. Billing: 3× credits and bytes applied only when cleaning succeeds.\n- `cache_ttl` — `string | 0` — How long a freshly fetched URL may be served from cache. `'0'`/`0` skips the\ncache read (the result is still written), `'Nh'`/`'Nd'` set a TTL (capped at\n168h / 7d). Default `'48h'`. Honoured on both the synchronous and asynchronous\npaths; the async success envelope reports the outcome via the `cache` field.\n- `custom` — `Record<string, unknown>` — User-supplied JSON payload, echoed back on the success envelope so callers\ncan correlate the response to caller-side state (job IDs, batch metadata).\nCapped at 4096 UTF-8 bytes after JSON serialization. Does NOT affect\ncache-key inputs — two requests differing only in `custom` share the same\ncache slot."
|
|
511
511
|
},
|
|
512
512
|
"sdk/typescript/scrape-bulk": {
|
|
513
513
|
"title": "Scrape Bulk",
|
|
@@ -16,7 +16,7 @@ import type { ScrapeResult } from '../client.js';
|
|
|
16
16
|
* - failed: `{ status:'failed', id, error:{ code, message, ... } }` — flagged as a tool
|
|
17
17
|
* error, rendering the public error code + message (plus any `warnings` the envelope
|
|
18
18
|
* carries, issue #2679).
|
|
19
|
-
* - success: full envelope; every textual format present (markdown,
|
|
19
|
+
* - success: full envelope; every textual format present (markdown, raw) is
|
|
20
20
|
* rendered, in that fixed canonical order — the first present format is the
|
|
21
21
|
* unlabeled primary, each remaining one follows under its own
|
|
22
22
|
* `--- format: <name> ---` delimiter — plus an optional `warnings` block (issue #2679)
|
|
@@ -40,7 +40,7 @@ function presentWarnings(envelope) {
|
|
|
40
40
|
// Textual formats in canonical render order. The first one present in the envelope is
|
|
41
41
|
// the unlabeled primary (today's position); every other one present follows under its
|
|
42
42
|
// own delimiter. Module-local: nothing outside this file needs it (issue #2589).
|
|
43
|
-
const TEXTUAL_FORMATS = ['markdown', '
|
|
43
|
+
const TEXTUAL_FORMATS = ['markdown', 'raw'];
|
|
44
44
|
// Full delimiter templates for every possible secondary textual format, used only to
|
|
45
45
|
// detect and strip a DANGLING partial delimiter left by a byte-boundary truncation
|
|
46
46
|
// cut (issue #2589 cr-8) — never to detect a complete, legitimately-rendered one.
|
|
@@ -62,7 +62,7 @@ const FORMAT_DELIMITER_MARKERS = TEXTUAL_FORMATS.map((f) => `\n\n--- format: ${f
|
|
|
62
62
|
* - failed: `{ status:'failed', id, error:{ code, message, ... } }` — flagged as a tool
|
|
63
63
|
* error, rendering the public error code + message (plus any `warnings` the envelope
|
|
64
64
|
* carries, issue #2679).
|
|
65
|
-
* - success: full envelope; every textual format present (markdown,
|
|
65
|
+
* - success: full envelope; every textual format present (markdown, raw) is
|
|
66
66
|
* rendered, in that fixed canonical order — the first present format is the
|
|
67
67
|
* unlabeled primary, each remaining one follows under its own
|
|
68
68
|
* `--- format: <name> ---` delimiter — plus an optional `warnings` block (issue #2679)
|
|
@@ -1,36 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The scrape `formats` vocabulary this server speaks, in ONE place (issue #2959).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Since #3775 there is exactly one vocabulary. The public spec, the published SDKs, every
|
|
5
|
+
* bundled doc page and the gateway's internal `Format` type — which
|
|
6
6
|
* `scrape-contract.generated.ts` mirrors, because it is generated verbatim from
|
|
7
|
-
* `packages/scrape-shared/src/envelope-types.ts` —
|
|
7
|
+
* `packages/scrape-shared/src/envelope-types.ts` — all spell the unprocessed-source format
|
|
8
|
+
* `raw`, so nothing translates and nothing diverges.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* on an undocumented leniency it could not see. It now sends the public spelling, and
|
|
13
|
-
* depends on nothing.
|
|
14
|
-
*
|
|
15
|
-
* The legacy alias below is the other half: #2588 made the tool ACCEPT `rawHtml` from an
|
|
16
|
-
* agent, and #2959 does not take that back — it only changes what leaves. The alias lives
|
|
17
|
-
* here rather than in `tools/scrape-url.ts` so the wire-facing tool file names exactly one
|
|
18
|
-
* spelling (the pre-merge grep gate for #2959 pins that), and so the two halves of the
|
|
19
|
-
* vocabulary — what we accept, what we send — are read together instead of a file apart.
|
|
10
|
+
* The alias layer this file used to carry (#2588, #2959) is gone with the spellings it
|
|
11
|
+
* mapped: #3775 is a clean break, and an alias here would reintroduce on the MCP surface
|
|
12
|
+
* exactly the translation the gateway deleted.
|
|
20
13
|
*
|
|
21
14
|
* NOT in `scrape-contract.generated.ts`: that file is overwritten verbatim on every
|
|
22
15
|
* `pnpm generate:scrape-contract`, so anything hand-written into it is silently wiped
|
|
23
16
|
* (issue #2588 failure mode E2).
|
|
24
17
|
*/
|
|
25
18
|
/** Every format value the public spec enumerates. This is what goes on the wire. */
|
|
26
|
-
export declare const PUBLIC_SCRAPE_FORMATS: readonly ["
|
|
19
|
+
export declare const PUBLIC_SCRAPE_FORMATS: readonly ["raw", "markdown", "links", "images"];
|
|
27
20
|
export type PublicScrapeFormat = (typeof PUBLIC_SCRAPE_FORMATS)[number];
|
|
28
21
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
22
|
+
* Every value the tool's `formats` enum accepts — the public set, and nothing else.
|
|
23
|
+
*
|
|
24
|
+
* Spelled as a mutable copy of the same tuple because `z.enum` needs one; the element type
|
|
25
|
+
* stays `PublicScrapeFormat`, so a parsed value needs no narrowing on its way to the wire.
|
|
31
26
|
*/
|
|
32
|
-
export declare const
|
|
33
|
-
/** Every value the tool's `formats` enum accepts: the public set plus the legacy aliases. */
|
|
34
|
-
export declare const ACCEPTED_SCRAPE_FORMATS: [string, ...string[]];
|
|
35
|
-
/** Normalize one accepted value to the public spelling that goes on the wire. */
|
|
36
|
-
export declare function toPublicFormat(value: string): PublicScrapeFormat;
|
|
27
|
+
export declare const ACCEPTED_SCRAPE_FORMATS: [PublicScrapeFormat, ...PublicScrapeFormat[]];
|
|
@@ -1,42 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The scrape `formats` vocabulary this server speaks, in ONE place (issue #2959).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Since #3775 there is exactly one vocabulary. The public spec, the published SDKs, every
|
|
5
|
+
* bundled doc page and the gateway's internal `Format` type — which
|
|
6
6
|
* `scrape-contract.generated.ts` mirrors, because it is generated verbatim from
|
|
7
|
-
* `packages/scrape-shared/src/envelope-types.ts` —
|
|
7
|
+
* `packages/scrape-shared/src/envelope-types.ts` — all spell the unprocessed-source format
|
|
8
|
+
* `raw`, so nothing translates and nothing diverges.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* on an undocumented leniency it could not see. It now sends the public spelling, and
|
|
13
|
-
* depends on nothing.
|
|
14
|
-
*
|
|
15
|
-
* The legacy alias below is the other half: #2588 made the tool ACCEPT `rawHtml` from an
|
|
16
|
-
* agent, and #2959 does not take that back — it only changes what leaves. The alias lives
|
|
17
|
-
* here rather than in `tools/scrape-url.ts` so the wire-facing tool file names exactly one
|
|
18
|
-
* spelling (the pre-merge grep gate for #2959 pins that), and so the two halves of the
|
|
19
|
-
* vocabulary — what we accept, what we send — are read together instead of a file apart.
|
|
10
|
+
* The alias layer this file used to carry (#2588, #2959) is gone with the spellings it
|
|
11
|
+
* mapped: #3775 is a clean break, and an alias here would reintroduce on the MCP surface
|
|
12
|
+
* exactly the translation the gateway deleted.
|
|
20
13
|
*
|
|
21
14
|
* NOT in `scrape-contract.generated.ts`: that file is overwritten verbatim on every
|
|
22
15
|
* `pnpm generate:scrape-contract`, so anything hand-written into it is silently wiped
|
|
23
16
|
* (issue #2588 failure mode E2).
|
|
24
17
|
*/
|
|
25
18
|
/** Every format value the public spec enumerates. This is what goes on the wire. */
|
|
26
|
-
export const PUBLIC_SCRAPE_FORMATS = ['
|
|
19
|
+
export const PUBLIC_SCRAPE_FORMATS = ['raw', 'markdown', 'links', 'images'];
|
|
27
20
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
21
|
+
* Every value the tool's `formats` enum accepts — the public set, and nothing else.
|
|
22
|
+
*
|
|
23
|
+
* Spelled as a mutable copy of the same tuple because `z.enum` needs one; the element type
|
|
24
|
+
* stays `PublicScrapeFormat`, so a parsed value needs no narrowing on its way to the wire.
|
|
30
25
|
*/
|
|
31
|
-
export const LEGACY_FORMAT_ALIASES = {
|
|
32
|
-
rawHtml: 'raw_html',
|
|
33
|
-
};
|
|
34
|
-
/** Every value the tool's `formats` enum accepts: the public set plus the legacy aliases. */
|
|
35
26
|
export const ACCEPTED_SCRAPE_FORMATS = [
|
|
36
27
|
...PUBLIC_SCRAPE_FORMATS,
|
|
37
|
-
...Object.keys(LEGACY_FORMAT_ALIASES),
|
|
38
28
|
];
|
|
39
|
-
/** Normalize one accepted value to the public spelling that goes on the wire. */
|
|
40
|
-
export function toPublicFormat(value) {
|
|
41
|
-
return LEGACY_FORMAT_ALIASES[value] ?? value;
|
|
42
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type Format = '
|
|
1
|
+
export type Format = 'raw' | 'markdown' | 'links' | 'images';
|
|
2
2
|
/**
|
|
3
3
|
* Contract generation emitted by every newly produced scrape envelope.
|
|
4
4
|
*
|
|
@@ -41,9 +41,12 @@ export interface ScrapeStats {
|
|
|
41
41
|
}
|
|
42
42
|
export type ScrapeEnvelopeErrorCode = 'validation_error' | 'invalid_url' | 'request_too_large' | 'payload_too_large' | 'unsupported_content_type' | 'rate_limited' | 'upstream_error' | 'timeout' | 'blocked' | 'internal_error';
|
|
43
43
|
export interface ScrapeFormats {
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The untouched upstream source of whatever the URL served — HTML, JSON, XML or
|
|
46
|
+
* plain text. #3775 renamed it from the old raw-HTML spelling, which misdescribed
|
|
47
|
+
* the non-HTML bodies `isTextContentType` has admitted since #1853.
|
|
48
|
+
*/
|
|
49
|
+
raw?: string;
|
|
47
50
|
markdown?: string;
|
|
48
51
|
links?: string[] | ScrapeScoredLink[];
|
|
49
52
|
images?: string[] | ScrapeScoredImage[];
|
package/dist/tools/scrape-url.js
CHANGED
|
@@ -3,7 +3,7 @@ import { renderScrapeResult } from '../lib/render-scrape.js';
|
|
|
3
3
|
// The accepted-vs-sent format vocabulary (issue #2959). This server sends the PUBLIC
|
|
4
4
|
// spelling and depends on no gateway leniency; the legacy alias #2588 added stays
|
|
5
5
|
// accepted from the agent. Both halves live in ../lib/scrape-formats.js.
|
|
6
|
-
import { ACCEPTED_SCRAPE_FORMATS
|
|
6
|
+
import { ACCEPTED_SCRAPE_FORMATS } from '../lib/scrape-formats.js';
|
|
7
7
|
/**
|
|
8
8
|
* Issue #2687 item 11 — EXCLUDE side of the unexposed-option decision table.
|
|
9
9
|
*
|
|
@@ -37,7 +37,7 @@ export function scrapeUrlTool(server, client) {
|
|
|
37
37
|
// advertised here — it would be unreachable from this tool. Add a queue-reaching
|
|
38
38
|
// field (e.g. `delay_ms`) or `async` to the schema below and update this
|
|
39
39
|
// description to match (pinned by scrape-url-description-reachability.test.ts).
|
|
40
|
-
'Scrape a webpage and return its content. Returns markdown by default. Use the formats parameter to request additional representations (
|
|
40
|
+
'Scrape a webpage and return its content. Returns markdown by default. Use the formats parameter to request additional representations (raw, links, images); the raw format — the untouched upstream source, whether that is HTML, JSON, XML or plain text — is included under its own delimiter when it is not the primary, and links/images are appended under their own labeled sections. The rendered content (the requested formats plus any links/images) is capped at 100KB — on very large pages a requested format may be truncated or, in extreme cases, omitted to stay within that cap. A few header lines (id, URL, status, page title) are added on top and are not counted against it. Problems the API reports about the capture come back as warnings, rendered under a `Warnings (N):` section as one `code: message (element)` line each; `artifact_unavailable` there means a format you requested and were billed for is missing from this response, which is a different answer from the page having none of it.', {
|
|
41
41
|
url: z.string().url().describe('The URL to scrape'),
|
|
42
42
|
// `.min(1)` mirrors docs/api/openapi.yaml ScrapeRequest.formats (`minItems: 1`)
|
|
43
43
|
// exactly (issue #2687 item 3). Before it, `params.formats ?? ['markdown']` only
|
|
@@ -50,11 +50,11 @@ export function scrapeUrlTool(server, client) {
|
|
|
50
50
|
.array(z.enum(ACCEPTED_SCRAPE_FORMATS))
|
|
51
51
|
.min(1, 'formats must list at least one format; omit it entirely for the markdown default')
|
|
52
52
|
.optional()
|
|
53
|
-
.describe('Content formats to return. Default: ["markdown"]. Options: markdown,
|
|
53
|
+
.describe('Content formats to return. Default: ["markdown"]. Options: markdown, raw, links, images. Omit the parameter for the default; an empty array is rejected.'),
|
|
54
54
|
country: z.string().optional().describe('Two-letter country code for geo-targeted scraping'),
|
|
55
55
|
}, async (params) => {
|
|
56
56
|
try {
|
|
57
|
-
const formats =
|
|
57
|
+
const formats = params.formats ?? ['markdown'];
|
|
58
58
|
const result = await client.scrape({
|
|
59
59
|
url: params.url,
|
|
60
60
|
formats,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hunt-labs/bytekit-mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "ByteKit MCP server — exposes ByteKit web-data tools (scrape, screenshot, search, docs) to AI agents over the Model Context Protocol, hosted or as a local stdio server.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|