interface BrowserTask { url: string; // required instruction?: string; // natural-language goal input?: Record<string, string>; // string inputs the agent uses during the run output?: Record<string, any>; // JSON Schema for the data to extract}
Fetch the status and results of a task submission by id. Works for in-progress and completed submissions.
const result = await predev.getBrowserAgent(id, { includeEvents?: boolean });
Parameters:
id(required): string — id returned from browserAgent(tasks, { async: true }) or from streaming
options.includeEvents(optional): boolean — include the full per-step event timeline (navigation, plan, screenshot, action, validation). Payloads can be large.
const result = await predev.browserAgent( [ { url: 'https://news.ycombinator.com', instruction: 'Extract the top 5 story titles.' }, { url: 'https://www.reddit.com/r/programming', instruction: 'Extract the top 5 post titles.' }, ], { concurrency: 2 },);for (const r of result.results) { console.log(r.status, r.data);}
The SDK throws typed exceptions for the most common gating cases. The two
billing-gate exceptions carry an actionUrl — a deep link back to pre.dev
that auto-opens the right modal (subscribe / buy credits) when the user
lands there. Same exceptions fire on REST and SSE error paths.
import { PredevAPIError, AuthenticationError, RateLimitError, SubscriptionRequiredError, InsufficientCreditsError, QueueFullError, BatchTooLargeError,} from 'predev-api';try { const result = await predev.browserAgent(tasks);} catch (err) { if (err instanceof InsufficientCreditsError) { // Subscription is fine, balance is too low — send the user to the credits modal. if (err.actionUrl) window.open(err.actionUrl, '_blank'); } else if (err instanceof SubscriptionRequiredError) { // Trial limit hit — send the user to the subscribe modal. if (err.actionUrl) window.open(err.actionUrl, '_blank'); } else if (err instanceof AuthenticationError) { // 401 — invalid or missing API key } else if (err instanceof RateLimitError) { // 429 RATE_LIMITED — back off and retry } else if (err instanceof QueueFullError) { // 429 QUEUE_FULL — wait for in-flight tasks to drain } else if (err instanceof BatchTooLargeError) { // 400 — split into smaller batches } else if (err instanceof PredevAPIError) { console.error(err.message); }}
Exception
HTTP
code
SubscriptionRequiredError
402
SUBSCRIPTION_REQUIRED
InsufficientCreditsError
402
INSUFFICIENT_CREDITS
RateLimitError
429
RATE_LIMITED
QueueFullError
429
QUEUE_FULL
BatchTooLargeError
400
BATCH_TOO_LARGE
AuthenticationError
401
—
PredevAPIError
other
—
Mid-stream errors on the SSE stream throw the same typed exceptions — a
for await loop wrapped in try/catch is enough.