WebExtract · Docs · Examples
Shell scripts. Download one (or copy it from below) and run it with bash.
#!/usr/bin/env bash
# WebExtract curl quickstart. Free tier: 20 calls/day per IP, no key; opt in with the header X-Billing: free.
# (Without a key, a payment or X-Billing: free, the REST API answers 402 x402_required.)
# Usage: ./quickstart.sh [url] (set WEBEXTRACT_KEY to use prepaid credits)
set -euo pipefail
BASE="${WEBEXTRACT_BASE:-https://api.webextract.dev}"
TARGET="${1:-https://example.com}"
AUTH=(-H "X-Billing: free"); [ -n "${WEBEXTRACT_KEY:-}" ] && AUTH=(-H "Authorization: Bearer ${WEBEXTRACT_KEY}")
echo "== balance (free calls left today, or prepaid credits)"
curl -sS "${AUTH[@]}" "$BASE/v1/balance"; echo
echo "== /v1/markdown (Markdown only; 0.4 credit / \$0.002 x402)"
# -G + --data-urlencode encodes the target URL safely (needed when it has its own ?query¶ms)
curl -sS -G "${AUTH[@]}" -D /dev/stderr "$BASE/v1/markdown" --data-urlencode "url=$TARGET" 2> >(grep -iE '^(HTTP|x-free|x-credits)' >&2); echo
echo "== /v1/extract (Markdown + metadata/product/tables; 1 credit / \$0.005 x402)"
curl -sS -G "${AUTH[@]}" "$BASE/v1/extract" --data-urlencode "url=$TARGET" \
| python3 -c 'import json,sys; d=json.load(sys.stdin); print(json.dumps({k:d.get(k) for k in ("final_url","word_count","metadata","product")}, indent=2, ensure_ascii=False)[:1500]); print("tables:", len(d.get("tables") or []))'
#!/usr/bin/env bash
# Get the x402 payment requirements WITHOUT paying anything.
# The server answers 402 + PAYMENT-REQUIRED (x402 v2, base64 JSON) to any request without a key, payment or X-Billing: free;
# `X-Billing: x402` makes that explicit (reason x402_requested).
# Usage: ./x402-inspect.sh [extract|markdown] [url]
# Sandbox (Base Sepolia test USDC only): WEBEXTRACT_BILLING=x402-testnet ./x402-inspect.sh
set -euo pipefail
BASE="${WEBEXTRACT_BASE:-https://api.webextract.dev}"
EP="${1:-extract}"; TARGET="${2:-https://example.com}"
HDRS=$(mktemp); BODY=$(mktemp); trap 'rm -f "$HDRS" "$BODY"' EXIT
code=$(curl -sS -G -o "$BODY" -D "$HDRS" -w '%{http_code}' -H "X-Billing: ${WEBEXTRACT_BILLING:-x402}" "$BASE/v1/$EP" --data-urlencode "url=$TARGET")
echo "HTTP $code"
echo "== body"; cat "$BODY"; echo
echo "== decoded PAYMENT-REQUIRED header"
grep -i '^payment-required:' "$HDRS" | cut -d' ' -f2- | tr -d '\r\n' | base64 -d | python3 -c '
import json,sys
d=json.load(sys.stdin)
print("x402Version:", d["x402Version"], "| resource:", d["resource"]["url"])
print(f"{"network":<14} {"amount":>7} {"asset":<44} payTo / extra")
for a in d["accepts"]:
print(f"{a["network"]:<14} {a["amount"]:>7} {a["asset"]:<44} {a["payTo"]} {a.get("extra")}")
'