api.tools

screenshot()

api.tools.screenshot({ url, viewport?, deviceScaleFactor?, wait?, timeout? }) → Promise<Screenshot>

Capture a public page as an image only. Choose a viewport and wait interval; without a viewport the capture keeps the full page.

POST /api/fetch1 creditviewport or full page, JPEG
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

It is fetch() with type: "screenshot", kept as its own name because that is how it reads at the call site and in a tool list.

Parameters

urlstringrequired

The page to capture. Checked by the same guard as fetch().

viewport{ width, height }1280 × 720

CSS viewport, width 320–2560 and height 480–1600. Explicit viewport returns viewport-only pixels.

deviceScaleFactor1 | 2 | 31

Use 1 for exact output dimensions; 2× or 3× increases raster dimensions.

waitinteger1000

Additional time for rendering, 0–10000 ms.

timeoutinteger20000

Milliseconds. Clamped between 5000 and 60000.

Returns

{
  ok: true,
  type: "screenshot",
  title: "Example Domain",
  url: "https://example.com/",
  mimeType: "image/jpeg",                  // the image's, on this path
  timedOut: false,
  screenshot: { mimeType: "image/jpeg", base64: "/9j/4AAQSkZJRgABAQ…" },
  captureMs: 1_480,
  cached: false,
  creditsUsed: 1,
  timing: { durationMs: 1_700 }
}
{
    "ok": True,
    "type": "screenshot",
    "title": "Example Domain",
    "url": "https://example.com/",
    "mimeType": "image/jpeg",                 # the image's, on this path
    "timedOut": False,
    "screenshot": {"mimeType": "image/jpeg", "base64": "/9j/4AAQSkZJRgABAQ…"},
    "captureMs": 1_480,
    "cached": False,
    "creditsUsed": 1,
    "timing": {"durationMs": 1_700},
}

With viewport: { width: 1920, height: 1080 } and deviceScaleFactor: 1, the returned raster is 1920 × 1080 pixels. That is a viewport capture, so content below the fold is not included. Omit viewport for the whole page; a long page then produces a tall image. JPEG at quality 86.

Saving it

const shot = await api.tools.screenshot({ url: "https://example.com", viewport: { width: 1920, height: 1080 }, deviceScaleFactor: 1, wait: 1200 });
const bytes = Buffer.from(shot.screenshot.base64, "base64");

// To this machine
await pc.files.write("Captures/example.jpg", bytes);

// Or to the account
await api.files.create({ name: "example.jpg", content: bytes, mimeType: "image/jpeg" }).save();
import base64

shot = api.tools.screenshot({"url": "https://example.com"})
data = base64.b64decode(shot["screenshot"]["base64"])

# To this machine
pc.files.write("Captures/example.jpg", data)

# Or to the account
api.files.create(name="example.jpg", content=data, mime_type="image/jpeg").save()

Which of the two to call

You wantCall
The image only at an exact viewportscreenshot({ url, viewport: { width: 1920, height: 1080 } })
The text onlyfetch({ url })
Bothfetch({ url, screenshot: true }) — one credit
Two calls for one page is two credits

screenshot() then fetch() on the same address is charged twice, since the two answers are cached apart. When you want the picture and the words, ask for them together.

Here mimeType is the image; on a page capture it is the page

On this path the top-level mimeType is image/jpeg, the same as screenshot.mimeType. Asking fetch() for an image with screenshot: true is the other case: the top-level field then describes the page that was loaded, and only screenshot.mimeType describes the image. Read the nested one in code that handles both.

A capture that fails here fails the call

The two paths part company on a failed capture

When the image is the whole point, a capture that cannot be taken — a page too tall, memory — raises fetch_failed and the credit is given back. On fetch({ screenshot: true }) the page is worth keeping, so the answer arrives with its text and the screenshot field carries an error instead of an image.

Errors

The same set as fetch(): url_required, url_refusee, invalid_url, fetch_failed, and NotEnoughCredits. The credit is refunded before the failure is raised.