> ## 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.

**Node.js**

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

**Python**

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

**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.

Errors specific to fetching with a context:

| Status | Message starts with | Meaning |
| - | - | - |
| `400` | `Context ID not found` | The context doesn't exist or belongs to another project. |
| `404` | `context_cookies_unavailable` | 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. |
| `400` | `context_storage_access_denied` | 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. |
| `400` | `Fetching with a context is not supported for this project` | Your project uses an older context configuration that Fetch can't read. Contact support to enable it. |

> [!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.

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

> **[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.