Choose the right way to call TinyFish Web Agent based on your use case
TinyFish Web Agent offers three ways to run automations. Each endpoint serves a different need. Pick the one that matches how you want to handle the request and response.
Pattern: Send request → Wait → Get resultThe simplest approach. You call the API, it blocks until the automation completes, then returns the result.
import { TinyFish } from "@tiny-fish/sdk";const client = new TinyFish();const run = await client.agent.run({ url: "https://example.com", goal: "Extract the page title",});console.log(run.result); // Your data
Runs created via /runcannot be cancelled. The request blocks until the automation completes, so there is no window to issue a cancellation. If you need the ability to cancel runs, use /run-async or /run-sse instead.
Pattern: Send request → Get run ID → Poll for resultThe request returns immediately with a run_id. You then poll a separate endpoint to check status and get the result when ready.1. Start the automation
import { TinyFish } from "@tiny-fish/sdk";const client = new TinyFish();const queued = await client.agent.queue({ url: "https://example.com", goal: "Extract all product data",});if (queued.error) { throw new Error(`Failed to queue run: ${queued.error.message}`);}const runId = queued.run_id;
2. Poll for the result
const run = await client.runs.get(runId);// run.status: PENDING, RUNNING, COMPLETED, FAILED, or CANCELLED// run.result: Your data (when COMPLETED)
3. Cancel a run (optional)If you need to stop a run before it completes, send a POST to the cancel endpoint:
Pattern: Send request → Receive event stream → Process events as they arriveUses Server-Sent Events (SSE) to push updates to you in real-time. You’ll receive events for each action the browser takes, plus a streaming URL you can embed in an iframe to watch the automation live.1. Start the automation and read events
import { TinyFish, EventType } from "@tiny-fish/sdk";const client = new TinyFish();const stream = await client.agent.stream({ url: "https://example.com", goal: "Extract all product data",});for await (const event of stream) { console.log(event.type, event);}