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

# Web Extract

> Extract structured data from any web page — either as clean markdown or as JSON matching CSS/XPath selectors you provide.

## Authentication

Requires an API key in the `Authorization` header.

```bash theme={"dark"}
Authorization: Bearer YOUR_API_KEY
```

## Request

<ParamField body="url" type="string" required>
  The URL to extract from. Must be a valid `http://` or `https://` URL.
</ParamField>

<ParamField body="mode" type="string">
  Extraction mode. `markdown` (default) returns clean page content; `selectors`
  returns structured JSON keyed by the `selectors` map.
</ParamField>

<ParamField body="selectors" type="object">
  Map of output field name → CSS/XPath selector. Used when `mode` is `selectors`.
</ParamField>

<ParamField body="render_js" type="boolean">
  Render the page in a headless browser before extracting. Default: `true`.
</ParamField>

<ParamField body="block_ads" type="boolean">
  Block ad networks while loading. Default: `true`.
</ParamField>

<ParamField body="block_trackers" type="boolean">
  Block tracking scripts while loading. Default: `true`.
</ParamField>

<ParamField body="wait_for" type="string">
  CSS selector to wait for before extracting (useful for lazy-loaded content).
</ParamField>

<ParamField body="timeout" type="integer">
  Page load timeout in milliseconds. Default: `30000`. Maximum: `60000`.
</ParamField>

<ParamField body="headers" type="object">
  Optional custom request headers to send with the page load.
</ParamField>

### Example request

<CodeGroup>
  ```bash cURL theme={"dark"}
  curl -X POST "https://encrata.com/api/agent/extract" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "url": "https://example.com/product/123",
      "mode": "selectors",
      "selectors": { "title": "h1", "price": ".price" }
    }'
  ```

  ```python Python theme={"dark"}
  import requests

  resp = requests.post(
      "https://encrata.com/api/agent/extract",
      headers={"Authorization": "Bearer YOUR_API_KEY"},
      json={
          "url": "https://example.com/product/123",
          "mode": "selectors",
          "selectors": {"title": "h1", "price": ".price"},
      },
  )
  print(resp.json())
  ```

  ```javascript JavaScript theme={"dark"}
  const resp = await fetch("https://encrata.com/api/agent/extract", {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      url: "https://example.com/product/123",
      mode: "selectors",
      selectors: { title: "h1", price: ".price" },
    }),
  });
  const data = await resp.json();
  ```
</CodeGroup>

## Response

<ResponseField name="success" type="boolean">
  Whether the extraction succeeded.
</ResponseField>

<ResponseField name="url" type="string">
  The final URL that was extracted (after redirects).
</ResponseField>

<ResponseField name="status_code" type="integer">
  HTTP status code returned by the target page.
</ResponseField>

<ResponseField name="extracted" type="object">
  The extracted data — markdown content, or a JSON object keyed by your `selectors`.
</ResponseField>

<ResponseField name="metadata" type="object">
  Page metadata such as `title`, `description`, and `language`.
</ResponseField>

<ResponseField name="error_code" type="string">
  Machine-readable error code when `success` is `false`.
</ResponseField>

<ResponseField name="error" type="string">
  Human-readable error message when `success` is `false`.
</ResponseField>

<ResponseField name="credits" type="integer">
  Credits consumed. `0` on a failed (refunded) extraction.
</ResponseField>

<ResponseField name="latency_ms" type="integer">
  Total processing time in milliseconds.
</ResponseField>

<ResponseExample>
  ```json theme={"dark"}
  {
    "success": true,
    "url": "https://example.com/product/123",
    "status_code": 200,
    "extracted": {
      "title": "Wireless Headphones",
      "price": "$129.00"
    },
    "metadata": {
      "title": "Wireless Headphones — Example",
      "language": "en"
    },
    "credits": 3,
    "latency_ms": 2140
  }
  ```
</ResponseExample>

## Credits

3 credits per request. Failed extractions (blocked, captcha, rate-limited) are
automatically refunded.
