# Browser Automation

Web scraping, screenshots, and AI-powered browser tasks

## Navigation

**Getting Started:** [All You Need](/index.md) | [Getting Started](/introduction.md) | [How Sapiom Works](/how-it-works.md) | [Quick Start](/quick-start.md) | [Using Services](/using-services.md) | [For AI Tools](/for-agents.md)  
**Capabilities:** [Overview](/capabilities.md) | [Verify Users](/capabilities/verify.md) | [Search the Web](/capabilities/search.md) | [AI Model Access](/capabilities/ai-models.md) | [Generate Images](/capabilities/images.md) | [Audio Services](/capabilities/audio.md) | **Browser Automation**  
**Integration / Agent Frameworks:** [Overview](/integration/agent-frameworks.md) | [LangChain](/integration/agent-frameworks/langchain.md) | [LangChain Classic](/integration/agent-frameworks/langchain-classic.md)  
**Integration / HTTP Clients:** [Overview](/integration/http-clients.md) | [Axios](/integration/http-clients/axios.md) | [Fetch](/integration/http-clients/fetch.md) | [Node.js HTTP](/integration/http-clients/node-http.md)  
**Governance:** [Overview](/governance.md) | [Setting Up Rules](/governance/rules.md) | [Agents & Identity](/governance/agents.md) | [Activity](/governance/activity.md)  
**Reference / API Reference:** [Introduction](/api-reference/introduction.md)  
**Reference / API Reference / Endpoints:** [Agents Endpoints](/api-reference/endpoints/agents.md) | [Get agent by ID](/api-reference/endpoints/agents/v1-agents-by-id-get.md) | [Update agent](/api-reference/endpoints/agents/v1-agents-by-id-patch.md) | [List all agents](/api-reference/endpoints/agents/v1-agents-get.md) | [Create a new agent](/api-reference/endpoints/agents/v1-agents-post.md) | [API Endpoints](/api-reference/endpoints.md) | [Get Sapiom payment JWKS](/api-reference/endpoints/other/.well-known-sapiom-jwks.json-get.md) | [Analytics Endpoints](/api-reference/endpoints/other.md) | [Get analytics chart](/api-reference/endpoints/other/v1-analytics-chart-get.md) | [Get analytics leaderboards](/api-reference/endpoints/other/v1-analytics-leaderboards-get.md) | [Get analytics summary](/api-reference/endpoints/other/v1-analytics-summary-get.md) | [Rules Endpoints](/api-reference/endpoints/rules.md) | [Get rule by ID](/api-reference/endpoints/rules/v1-spending-rules-by-id-get.md) | [Update a rule](/api-reference/endpoints/rules/v1-spending-rules-by-ruleId-put.md) | [List all rules](/api-reference/endpoints/rules/v1-spending-rules-get.md) | [Create a new rule](/api-reference/endpoints/rules/v1-spending-rules-post.md) | [Transactions Endpoints](/api-reference/endpoints/transactions.md) | [Complete a transaction](/api-reference/endpoints/transactions/v1-transactions-by-transactionId-complete-post.md) | [List transaction costs](/api-reference/endpoints/transactions/v1-transactions-by-transactionId-costs-get.md) | [Add cost to transaction](/api-reference/endpoints/transactions/v1-transactions-by-transactionId-costs-post.md) | [Add facts to transaction](/api-reference/endpoints/transactions/v1-transactions-by-transactionId-facts-post.md) | [Get transaction details](/api-reference/endpoints/transactions/v1-transactions-by-transactionId-get.md) | [Reauthorize a transaction with x402 payment data](/api-reference/endpoints/transactions/v1-transactions-by-transactionId-reauthorize-post.md) | [List transactions](/api-reference/endpoints/transactions/v1-transactions-get.md) | [Create a new transaction](/api-reference/endpoints/transactions/v1-transactions-post.md) | [Verification Endpoints](/api-reference/endpoints/verification.md) | [Check verification code](/api-reference/endpoints/verification/v1-services-verify-check-post.md) | [Send verification code](/api-reference/endpoints/verification/v1-services-verify-send-post.md)  
**Reference / SDK Reference:** [@sapiom/axios](/reference/sdk/axios.md) | [@sapiom/fetch](/reference/sdk/fetch.md) | [SDK Reference](/reference/sdk.md) | [@sapiom/langchain-classic](/reference/sdk/langchain-classic.md) | [@sapiom/langchain](/reference/sdk/langchain.md) | [@sapiom/node-http](/reference/sdk/node-http.md)  
**Reference:** [Concepts](/reference/concepts.md)

---

Extract content from web pages, capture screenshots, or execute complex browser tasks using AI — all through a single API with no account setup required.

## Quick Example

```typescript

// Create a Sapiom-tracked fetch function
const sapiomFetch = createFetch({
  apiKey: process.env.SAPIOM_API_KEY,
  agentName: "my-agent",
});

// Extract webpage content - SDK handles payment/auth automatically
const response = await sapiomFetch(
  "https://anchor-browser.services.sapiom.ai/v1/tools/fetch-webpage",
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      url: "https://example.com",
      format: "markdown",
    }),
  }
);

const data = await response.json();
console.log("Page content:", data.content);
```

## How It Works

Sapiom routes browser automation requests to [Anchor Browser](https://anchorbrowser.io), which provides AI-powered browser automation in the cloud. The SDK handles payment negotiation automatically — you pay based on the operation type and complexity.

The service supports two operations:

1. **Extract** — Get page content as markdown or HTML
2. **Screenshot** — Capture page screenshots at various sizes

## Provider

Powered by [Anchor Browser](https://anchorbrowser.io). Anchor provides headless browser infrastructure with AI capabilities for intelligent web automation.

## API Reference

### Extract Content

**Endpoint:** `POST https://anchor-browser.services.sapiom.ai/v1/tools/fetch-webpage`

Extract the main content from a webpage as clean markdown or HTML.

#### Request

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `url` | string | Yes | URL to extract content from |
| `format` | string | No | Output format: `markdown` or `html` (default: `markdown`) |
| `wait` | number | No | Wait time in milliseconds for JavaScript execution |
| `new_page` | boolean | No | Open URL in a new browser page (default: `false`) |
| `page_index` | number | No | Target page index in multi-page session |
| `return_partial_on_timeout` | boolean | No | Return partial content if page times out (default: `false`) |

```json
{
  "url": "https://example.com/blog/article-title",
  "format": "markdown"
}
```

#### Response

```json
{
  "content": "# Article Title\n\nThis is the main content of the article...",
  "title": "Article Title",
  "url": "https://example.com/blog/article-title"
}
```

### Capture Screenshot

**Endpoint:** `POST https://anchor-browser.services.sapiom.ai/v1/tools/screenshot`

Capture a screenshot of a webpage.

#### Request

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `url` | string | Yes | URL to screenshot |
| `width` | number | No | Viewport width in pixels, 320-3840 (default: 1280) |
| `height` | number | No | Viewport height in pixels, 240-2160 (default: 720) |
| `image_quality` | number | No | JPEG quality, 1-100 (default: 80) |
| `wait` | number | No | Wait time in milliseconds for JavaScript execution |
| `scroll_all_content` | boolean | No | Scroll through page to capture all content (default: `false`) |
| `capture_full_height` | boolean | No | Capture full page height, not just viewport (default: `false`) |
| `format` | string | No | Image format: `png` or `jpeg` (default: `png`) |
| `s3_target_address` | string | No | S3 URL for direct upload instead of returning image |
| `fullPage` | boolean | No | **Deprecated** — use `capture_full_height` + `scroll_all_content` instead |
| `quality` | number | No | **Deprecated** — use `image_quality` instead |

```json
{
  "url": "https://example.com",
  "capture_full_height": false,
  "format": "png",
  "width": 1280,
  "height": 720
}
```

#### Response

The response is binary image data with the appropriate `Content-Type` header (`image/png` or `image/jpeg`). Use `responseType: "arraybuffer"` (Axios) or `response.arrayBuffer()` (Fetch) to handle the binary response.

### Price Estimation

**Endpoints:**
- `POST https://anchor-browser.services.sapiom.ai/v1/tools/fetch-webpage/price`
- `POST https://anchor-browser.services.sapiom.ai/v1/tools/screenshot/price`

Get the estimated cost before making a request. Accepts the same parameters as the main endpoint.

```json
{
  "price": "$0.02",
  "currency": "USD"
}
```

### Error Codes

| Code | Description |
|------|-------------|
| 400 | Invalid request — check URL and parameters |
| 402 | Payment required — ensure you're using the Sapiom SDK |
| 404 | Page not found or unreachable |
| 429 | Rate limit exceeded |

## Complete Example

```typescript

const sapiomFetch = createFetch({
  apiKey: process.env.SAPIOM_API_KEY,
  agentName: "my-agent",
});

const baseUrl = "https://anchor-browser.services.sapiom.ai/v1";

async function scrapeArticle(url: string) {
  // Extract article content as markdown
  const response = await sapiomFetch(`${baseUrl}/tools/fetch-webpage`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      url,
      format: "markdown",
    }),
  });

  const data = await response.json();
  return {
    title: data.title,
    content: data.content,
  };
}

async function capturePagePreview(url: string) {
  // Capture a screenshot for social preview
  const response = await sapiomFetch(`${baseUrl}/tools/screenshot`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      url,
      width: 1200,
      height: 630,
      format: "jpeg",
      image_quality: 90,
    }),
  });

  return Buffer.from(await response.arrayBuffer());
}

// Usage
const article = await scrapeArticle("https://blog.example.com/post");
console.log("Article:", article.title);

const preview = await capturePagePreview("https://example.com");
console.log("Preview image size:", preview.byteLength, "bytes");
```

## Pricing

| Operation | Price |
|-----------|-------|
| Extract | $0.01 flat |
| Screenshot | $0.01 flat |