feat: add POST /v1/screenshots/batch endpoint
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
- Batch screenshot endpoint: take 1-10 screenshots in a single request - Concurrent processing with Promise.allSettled (partial success support) - Upfront quota check for all URLs before processing - Per-URL SSRF validation via existing takeScreenshot() - Added incrementUsage() to usage middleware for granular tracking - 10 new tests covering all edge cases - Updated OpenAPI docs (JSDoc on route) - Updated Node.js and Python SDK READMEs with batch method docs
This commit is contained in:
parent
65d2fd38cc
commit
8a36826e35
6 changed files with 506 additions and 0 deletions
|
|
@ -225,6 +225,29 @@ except SnapAPIError as e:
|
|||
| `css` | `str` | — | Custom CSS to inject before capture (max 5000 chars) |
|
||||
| `clip` | `dict` | — | Crop rectangle: `{"x": int, "y": int, "width": int, "height": int}` (mutually exclusive with full_page/selector) |
|
||||
|
||||
### `snap.batch(urls, **options) -> list[dict]`
|
||||
|
||||
Take multiple screenshots in a single request. Each URL counts as one screenshot toward usage limits.
|
||||
|
||||
```python
|
||||
results = snap.batch(
|
||||
["https://example.com", "https://example.org"],
|
||||
format="jpeg", width=1920, height=1080
|
||||
)
|
||||
|
||||
for result in results:
|
||||
if result["status"] == "success":
|
||||
with open(f"{result['url']}.jpg", "wb") as f:
|
||||
f.write(base64.b64decode(result["image"]))
|
||||
else:
|
||||
print(f"Failed: {result['url']} — {result['error']}")
|
||||
```
|
||||
|
||||
- **Max 10 URLs per batch**
|
||||
- All options (format, width, height, etc.) are shared across all URLs
|
||||
- Returns partial results — some may succeed while others fail
|
||||
- Response is always JSON with `{ "results": [...] }`
|
||||
|
||||
### `snap.health() -> dict`
|
||||
|
||||
Returns API health status.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue