Skip to main content

The result union

No SDK method throws for API or network errors. Every scraping method returns an ApiResult, a discriminated union you narrow on the type field:
Checking type narrows the rest of the object — in the success branch data, timeMs, and creditsCost are all available and typed; in the error branch you get status and message.

Input validation

The SDK validates request inputs with Zod before making an HTTP request. Invalid inputs, such as an unsupported sort value or a count above the endpoint’s limit, can throw a Zod validation error. No request is sent and no credits are consumed when this validation fails. The client constructor also throws if apiKey is missing or empty. These local errors are separate from the typed results returned for API and network failures.

Error status codes

The error result’s status field normally carries the HTTP status code; 0 indicates a network failure. Branch on it rather than parsing the message string.