Skip to main content

What is fetch()?

Sometimes an agent doesn’t need to use a page, it needs to read one. browserbase.fetch() takes a URL and returns its content as markdown, structured JSON, or the raw body.
fetch() is a Browserbase cloud feature. The request runs on Browserbase infrastructure and needs a Browserbase API key, so local browsers have no equivalent.

Why use fetch()?

Freshness

Every call retrieves the live page, not a copy from a crawl index, so what the model reads is what the site serves right now.

Speed

No browser boot, no render, and no wait for the DOM to settle. Fast enough to sit inside a latency-sensitive agent loop.

Token-optimized output

Markdown and JSON strip the boilerplate and layout, so the model spends its context on content instead of markup.

Proxy support

Pages that block datacenter traffic are reachable by routing the request through Browserbase’s proxy network.

Setup

fetch() ships with the Stagehand SDK. The only requirement is a Browserbase API key:

Output formats

format decides what lands in content. Pick the cheapest representation that still answers your question.
Markdown is the default choice for agent context: headings, links, and text survive, while navigation chrome and layout markup don’t.
content is a string.

Proxies and transport

Some sites refuse datacenter traffic, some answer only after a redirect, and some serve a certificate you’d rather not argue with. Three booleans cover those cases, all off by default.
Turn proxies on only for the requests that need it. Proxied fetches cost more and add latency, so a per-domain fallback beats enabling it globally.

Response

Every fetch returns the content alongside the transport metadata, so you can tell a real page from a soft 404 or a bot wall before handing anything to a model.
Field names follow each language’s conventions: contentType and statusCode in TypeScript, content_type and status_code in Python, and ContentType and StatusCode on the Go structs. In Go, Content is a union: call AsString() for raw and markdown, and AsObject() for json.

API reference

Parameters

string
required
Your Browserbase API key. Fetches are billed to the project that owns the key.
string
required
The http or https URL to fetch. Validated locally before the request is sent.
"raw" | "json" | "markdown"
Which representation to return in content. Defaults to raw.
object
JSON Schema describing the object to extract. Required with format: "json", and rejected with any other format.
boolean
Route the request through Browserbase’s proxy network. Defaults to false.
boolean
Follow HTTP redirects. Defaults to false, so a redirect is reported as its 3xx status.
boolean
Skip TLS certificate verification. Defaults to false.

Returns

string
Identifier for this fetch request.
string | object
The page content. A string for raw and markdown, an object for json.
string
MIME type reported by the target.
string
utf-8 for text, base64 for binary responses.
Record<string, string>
Response headers from the target.
number
HTTP status code returned by the target. A fetch that reaches a 404 succeeds as a call and reports 404 here.

When to use a browser instead

fetch() never renders the page. It performs an HTTP request and converts the response, which is exactly why it is fast, and also why it cannot see anything that only exists after JavaScript runs.
Reach for browserbase.launch() and extract() when the content is client-rendered, sits behind a login, or appears only after interaction such as scrolling, clicking a tab, or dismissing a modal. A common pattern is to try fetch() first and fall back to a browser session when the content you need is missing.

Use cases

General agents and chatbots

Retrieve up-to-date information to produce more accurate answers.

Coding agents

Pull the documentation page for a library straight into context as markdown.

Vertical-specific agents

Pull fresh, domain-specific information tailored to a given industry or knowledge vertical.

AI workflows

Regularly collect news, people, company, or other frequently updated information for internal or production workflows.

Limits

Next steps

Web Search

Find the URLs worth fetching in the first place.

Browserbase Fetch

Endpoint details, pricing, and the underlying REST API.