> ## Documentation Index
> Fetch the complete documentation index at: https://docs.browserbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authenticated Fetch

> Use saved login state with Fetch for pages that require authentication.

Use a saved login session to fetch pages behind a login. Browserbase stores this login state in a context, and the API refers to it with `contextId`.

## Fetching with a context

Pass a `contextId` to fetch pages that require a login. Browserbase calls the saved login state a [context](https://docs.browserbase.com/platform/browser/core-features/contexts.md). Fetch sends only the cookies saved in that context. It follows normal browser cookie rules: each cookie goes only to the domains and paths it belongs to, including across redirects, and Fetch drops expired cookies.

> [tab] Node.js
>
> ```typescript Node.js theme={null}
> const response = await bb.fetchAPI.create({
>   url: "https://example.com/account/orders",
>   contextId: "<context-id>",
> });
> ```

> [tab] Python
>
> ```python Python theme={null}
> response = bb.fetch_api.create(
>     url="https://example.com/account/orders",
>     context_id="<context-id>",
> )
> ```

> [tab] cURL
>
> ```bash cURL theme={null}
> curl -X POST https://api.browserbase.com/v1/fetch \
>   -H "Content-Type: application/json" \
>   -H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
>   -d '{"url": "https://example.com/account/orders", "contextId": "<context-id>"}'
> ```

How it works:

* **Fetch uses the cookies saved when the browser session ends.** Log in with a browser session that uses the context with `persist: true`.
* **Fetch is read-only.** Fetch doesn't write cookies the site sets during a request back to the context.
* **Fetch requires a context saved on or after September 1, 2026.** To use an older context, run one browser session with that context and `persist: true`. The context works with Fetch after that session ends.
* **Bring-your-own-storage uses your existing role.** If your project stores contexts in your own S3 bucket, Fetch reads them with the role you configured for it. Fetch only needs `s3:GetObject` on your contexts bucket, which the [BYOS setup guide](https://docs.browserbase.com/account/enterprise/byos-setup-guide.md) already grants.

## Error handling

Requests with a `contextId` can return these errors, in the same format as other [Fetch errors](https://docs.browserbase.com/platform/fetch/overview.md#error-handling).

> [accordion] Context not found (400)
>
> The context doesn't exist or belongs to another project.
>
> ```json theme={null}
> {
>   "statusCode": 400,
>   "error": "Bad Request",
>   "message": "Context ID not found"
> }
> ```

> [accordion] No saved cookies (404)
>
> The context has no saved cookies yet, or was last saved before September 1, 2026. Run a browser session with the context and `persist: true`, then retry.
>
> ```json theme={null}
> {
>   "statusCode": 404,
>   "error": "Not Found",
>   "message": "This context has no saved cookies yet, or was last saved before September 1, 2026. Run a browser session with this context and `persist: true`, then retry."
> }
> ```

> [accordion] Context storage access denied (400)
>
> Your project stores contexts in your own S3 bucket, and Browserbase couldn't assume your BYOS role or your KMS key refused to decrypt the context. Check the role's trust policy, external ID, and KMS key policy.
>
> ```json theme={null}
> {
>   "statusCode": 400,
>   "error": "Bad Request",
>   "message": "Browserbase could not read this context from your bucket. Check the trust policy and external ID of the role configured for your contexts bucket, and the bucket policy."
> }
> ```

> [accordion] Context not supported for this project (400)
>
> Your project uses an older context configuration that Fetch can't read. Contact support to enable it.
>
> ```json theme={null}
> {
>   "statusCode": 400,
>   "error": "Bad Request",
>   "message": "Fetching with a context is not supported for this project. Please contact support."
> }
> ```

> [!NOTE]
>
> Some sites authenticate data requests with tokens that the page's JavaScript creates per session, such as an `Authorization` header. Fetch only sends cookies, so it can't authenticate those requests. Use a [browser session](https://docs.browserbase.com/platform/browser/getting-started/create-browser-session.md) with the saved login for those sites.

> [card] [Proxies](https://docs.browserbase.com/platform/fetch/proxies.md)
>
> Route Fetch requests through Browserbase's proxy network or target a specific location.

> [card] [Fetch](https://docs.browserbase.com/platform/fetch/overview.md)
>
> Return page content without an interactive browser session.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.