# Botify Agent: SpeedWorkers Page History

**ID:** `speedworkers_page_history`

Get the SpeedWorkers indexation history of URLs: when they were cached, with which status code and whether they could be served to bots.


    List the past indexations of one or more URLs by Botify SpeedWorkers, newest
    first: date, whether the page was stored in the cache, HTTP status code
    returned by the origin, device variant, page size, matching cache behavior,
    whether the page could be served to bots (and why not), canonical URL, next
    refresh and expiration times, fetching and rendering times.

    Pass every URL in a single call. Each call scans the SpeedWorkers indexation
    table once, however many URLs it lists, so calling this tool with several
    URLs at once is what keeps the number of scans down.

    SpeedWorkers stores the history under the URL resolved before caching
    (ignored query parameters removed...): by default each URL is resolved
    first, and the requested URL is used when the resolved one has no history.

    Each event has an `event_id`: pass it to `speedworkers_page_snapshot` to get
    the HTML stored during this indexation. Use `speedworkers_page_preview` for
    the page currently delivered to bots.

    The project must have SpeedWorkers enabled.
    

## Authentication

All endpoints require a **Bearer token** in the `Authorization` header.

```
Authorization: Bearer <your-token>
```

## Calling this agent

This agent supports the following processing modes:

| Mode | Type | Description |
|------|------|-------------|
| **Process** | Synchronous | Single-item processing. Best for real-time requests with immediate response. |
| **Batch Process** | Synchronous | Process multiple items in a single request for efficiency. |
| **Async Process** | Asynchronous | Single-item processing for long-running tasks that exceed timeout limits. |
| **Async Batch Process** | Asynchronous | Large-scale batch jobs with background processing. |

# Synchronous Processing

Synchronous calls block until the result is ready. Use these for quick operations where you need immediate results.

## Single Item Processing

Process a single input and receive the result immediately.

```
POST https://agents.botify.com/{org}/{project}/speedworkers_page_history/process
```

### Request body

```json
{
  "item": {
    "urls": []
  }
}
```

### Response

Returns a single processed item (HTTP 200).

### cURL example

```bash
curl -X POST "https://agents.botify.com/{org}/{project}/speedworkers_page_history/process" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "item": {
    "urls": []
  }
}'
```

## Batch Processing

Process multiple inputs in a single synchronous request. More efficient than making individual calls. Items are processed concurrently on the server.

```
POST https://agents.botify.com/{org}/{project}/speedworkers_page_history/batch_process
```

### Request body

```json
{
  "items": [
    {
      "urls": []
    }
  ]
}
```

### Response

Returns an array of results. Each element is either a successful processed item (`"status": "success"`) or an error (`"status": "error"`).

### cURL example

```bash
curl -X POST "https://agents.botify.com/{org}/{project}/speedworkers_page_history/batch_process" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "items": [
    {
      "urls": []
    }
  ]
}'
```

### When to use synchronous calls

- Processing completes within timeout limits (typically 30 seconds)
- You need immediate results for user-facing features
- Small to medium batch sizes (up to ~100 items)

# Asynchronous Processing

Asynchronous calls return immediately with a batch ID. You then poll for results using the `async_batches/` endpoints.

### Async processing flow

1. **Submit job** -- `POST` to `async_process` or `async_batch_process`
2. **Receive batch ID** -- response contains `batch_id`
3. **Poll status** -- `HEAD` request to check readiness (lightweight, no body)
4. **Get results** -- `GET` request to retrieve processed results

## Async Single Item

Submit a single item for background processing. Use the `/single` endpoint to retrieve the result.

```
POST https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_process
```

### Request body

```json
{
  "item": {
    "urls": []
  }
}
```

### cURL example

```bash
# Step 1: Submit the job
curl -X POST "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_process" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "item": {
    "urls": []
  }
}'

# Response: { "batch_id": "abc123" }

# Step 2: Check if batch is ready (HEAD request -- lightweight check)
curl -I -X HEAD "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batches/abc123" \
  -H "Authorization: Bearer $TOKEN"
# Returns 200 if ready, 204 if still processing

# Step 3: Get the result (for single-item async)
curl -X GET "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batches/abc123/single" \
  -H "Authorization: Bearer $TOKEN"
# Returns 200 with result, 202 if still processing, 404 if batch not found
```

## Async Batch Processing

Submit multiple items for background processing. The request body uses **JSONL** (newline-delimited JSON) format.

```
POST https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batch_process
```

### Request body (JSONL, `Content-Type: text/plain`)

The first line contains `config` and `batch_config`. Each subsequent line is an item with a unique `id`.

```
{"config": {}, "batch_config": {}}
{"id": "item_1", "item": {"urls": []}}
```

### Response

Returns a JSON object with `batch_id`, `status`, and a `Location` header.

### cURL example

```bash
# Step 1: Submit the batch job
curl -X POST "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batch_process" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: text/plain" \
  -d '{"config": {}, "batch_config": {}}\n{"id": "item_1", "item": {"urls": []}}'

# Response: { "batch_id": "xyz789" }

# Step 2: Check if batch is ready (HEAD request)
curl -I -X HEAD "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batches/xyz789" \
  -H "Authorization: Bearer $TOKEN"
# Returns 200 if ready, 204 if still processing

# Step 3: Get all results
curl -X GET "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batches/xyz789" \
  -H "Authorization: Bearer $TOKEN"
```

## Checking Batch Status

Use a lightweight `HEAD` request to check if your batch is ready without transferring data.

```
HEAD https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batches/{batch_id}
```

```bash
curl -I -X HEAD "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batches/{batch_id}" \
  -H "Authorization: Bearer $TOKEN"

# Response headers indicate status:
# HTTP/1.1 200 OK        -> Batch is complete, results ready
# HTTP/1.1 204 No Content -> Still processing
# HTTP/1.1 404 Not Found -> Batch does not exist
```

## Retrieving Results

Once the batch is ready, fetch results using the appropriate endpoint.

```bash
# For async_process (single item) -- use /single endpoint
curl -X GET "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batches/{batch_id}/single" \
  -H "Authorization: Bearer $TOKEN"

# For async_batch_process (multiple items) -- use base endpoint
curl -X GET "https://agents.botify.com/{org}/{project}/speedworkers_page_history/async_batches/{batch_id}" \
  -H "Authorization: Bearer $TOKEN"
# Returns streaming JSONL where each line is a processed item or error
```

### Async response codes

| Code | Endpoint | Meaning | Action |
|------|----------|---------|--------|
| 200 | `HEAD` / `GET` | Batch complete, results ready | Read results from response body |
| 204 | `HEAD` | Still processing | Continue polling |
| 202 | `GET /single` | Still processing | Continue polling |
| 400 | `GET /single` | All items failed (client error) | Check error in response body |
| 404 | `HEAD` / `GET` | Batch does not exist | Verify `batch_id` is correct |

> **HEAD vs GET:** Use `HEAD` requests for lightweight status checks (no response body). Use `GET` only when ready to retrieve results to minimize bandwidth.

### When to use asynchronous calls

- Processing takes longer than 30 seconds
- Large batch sizes (100+ items)
- Background processing where immediate results aren't required
- Integration with job queues or workflow systems

## Python Example

A complete Python example showing both synchronous and asynchronous patterns.

```python
import requests
import time

API_TOKEN = "your_api_token"
BASE_URL = "https://agents.botify.com/{organization}/{project}"
AGENT = "speedworkers_page_history"

headers = {
    "Authorization": f"Bearer {API_TOKEN}",
    "Content-Type": "application/json"
}

single_payload = {
  "item": {
    "urls": []
  }
}


def process_sync(payload: dict) -> dict:
    """Synchronous single-item processing."""
    response = requests.post(
        f"{BASE_URL}/{AGENT}/process",
        headers=headers,
        json=payload
    )
    response.raise_for_status()
    return response.json()


def process_async(
    payload: dict,
    poll_interval: int = 5,
    max_retries: int = 60
) -> dict:
    """Asynchronous single-item processing with polling."""
    # Submit job
    response = requests.post(
        f"{BASE_URL}/{AGENT}/async_process",
        headers=headers,
        json=payload
    )
    batch_id = response.json()["batch_id"]

    # Poll for results using HEAD (lightweight check)
    for _ in range(max_retries):
        status = requests.head(
            f"{BASE_URL}/{AGENT}/async_batches/{batch_id}",
            headers=headers
        )

        if status.status_code == 200:
            result = requests.get(
                f"{BASE_URL}/{AGENT}/async_batches/{batch_id}/single",
                headers=headers
            )
            return result.json()
        elif status.status_code == 204:
            time.sleep(poll_interval)
        else:
            raise Exception(f"Unexpected status: {status.status_code}")

    raise Exception("Max retries exceeded")


def process_async_batch(
    items: list,
    config: dict | None = None,
    poll_interval: int = 5
) -> dict:
    """Asynchronous batch processing with polling."""
    import json as _json

    # Build JSONL payload: first line is config, subsequent lines are items
    lines = [_json.dumps({"config": config or {}, "batch_config": {}})]
    for i, item in enumerate(items):
        lines.append(_json.dumps({"id": f"item_{i}", "item": item}))
    body = "\n".join(lines)

    # Submit batch (JSONL, text/plain)
    response = requests.post(
        f"{BASE_URL}/{AGENT}/async_batch_process",
        headers={**headers, "Content-Type": "text/plain"},
        data=body
    )
    batch_id = response.json()["batch_id"]

    # Poll until ready
    while True:
        status = requests.head(
            f"{BASE_URL}/{AGENT}/async_batches/{batch_id}",
            headers=headers
        )

        if status.status_code == 200:
            results = requests.get(
                f"{BASE_URL}/{AGENT}/async_batches/{batch_id}",
                headers=headers
            )
            return results.json()

        time.sleep(poll_interval)


# Example usage
# result = process_sync(single_payload)
# result = process_async(single_payload)
# results = process_async_batch([{"input": "item1"}, {"input": "item2"}])
```

## Billing

Fixed cost per call, plus the data read from the SpeedWorkers indexation table. That table is scanned once per call, however many URLs the call lists, so grouping URLs in one call is what keeps this down.

These usage SKUs can be charged on a call, including SKUs from tools this one may call.

| SKU | Credits | Description | Used by |
| --- | ------- | ----------- | ------- |
| Tool call | 1 per request | Charged once per successful item, on top of any usage below. | This tool |
| Data scanned | 6,250 per TiB scanned | Analytical queries are billed on the volume of data the query reads, not on the rows it returns: a narrow filter over a large table can still scan the whole table. | Tables Query (`tables_query`) |
| Query billed to your cloud project | 4 per query | A flat fee per query run in your organization's own cloud project, in place of the charge on the data it scans. | Tables Query (`tables_query`) |


## Schemas

### Item

```json
{
  "type": "object",
  "properties": {
    "urls": {
      "description": "URLs to get the SpeedWorkers indexation history of. Pass several URLs in one call: they are read in a single scan of the indexation table. One call returns at most 10000 events (URLs x limit). Resolving URLs counts each URL twice, once for the resolved form and once for the requested one.",
      "items": {
        "type": "string"
      },
      "maxItems": 1000,
      "minItems": 1,
      "title": "URLs",
      "type": "array"
    },
    "days": {
      "default": 15,
      "description": "Number of past days to look for indexation events in.",
      "maximum": 90,
      "minimum": 1,
      "title": "Days",
      "type": "integer"
    },
    "limit": {
      "default": 50,
      "description": "Maximum number of indexation events to return per URL, newest first.",
      "maximum": 500,
      "minimum": 1,
      "title": "Limit",
      "type": "integer"
    },
    "resolve_url": {
      "default": true,
      "description": "Resolve each URL the way SpeedWorkers does before caching it (ignored query parameters removed...), since the indexation history is stored under the resolved URL.",
      "title": "Resolve URL",
      "type": "boolean"
    }
  },
  "required": [
    "urls"
  ]
}
```

### Config

This agent uses the default config (no custom fields).

### Response

```json
{
  "$defs": {
    "SpeedWorkersIndexationEvent": {
      "properties": {
        "event_id": {
          "description": "Opaque ID of the indexation event. Pass it to the `speedworkers_page_snapshot` tool to get the HTML SpeedWorkers stored during this indexation.",
          "title": "Event Id",
          "type": "string"
        },
        "indexed_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "When the indexation happened",
          "title": "Indexed At"
        },
        "indexed": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Whether the page was stored in the SpeedWorkers cache",
          "title": "Indexed"
        },
        "http_code": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "HTTP status code returned by the origin",
          "title": "Http Code"
        },
        "device": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Device variant (desktop, mobile, na)",
          "title": "Device"
        },
        "page_size": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Page size, in bytes",
          "title": "Page Size"
        },
        "section_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "ID of the matching cache behavior (section)",
          "title": "Section Id"
        },
        "section_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Name of the matching cache behavior (section)",
          "title": "Section Name"
        },
        "ready_to_be_served": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Whether the page can be served to bots (indexed, a servable status code, and no failed or errored quality control)",
          "title": "Ready To Be Served"
        },
        "not_ready_to_be_served_reason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Why the page cannot be served to bots (status_code, quality_controls, not_indexed)",
          "title": "Not Ready To Be Served Reason"
        },
        "not_deliverable_reason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Why the page would not be delivered to bots (e.g. not_cached, quality_controls_failed, last_refresh_5xx). `delivered` when it was delivered, `cached` when it was served from cache with no blocking reason.",
          "title": "Not Deliverable Reason"
        },
        "canonical_url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Canonical URL found in the page",
          "title": "Canonical Url"
        },
        "canonical_equal": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Whether the canonical URL is the page URL",
          "title": "Canonical Equal"
        },
        "next_refresh_time": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "When the page is due for a refresh",
          "title": "Next Refresh Time"
        },
        "expiration_time": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "When the cached page expires",
          "title": "Expiration Time"
        },
        "ttl_minutes": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Time between the indexation and the next refresh, in minutes",
          "title": "Ttl Minutes"
        },
        "time_to_fetch_ms": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Time spent fetching the page, in ms",
          "title": "Time To Fetch Ms"
        },
        "time_to_render_ms": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Time spent rendering the page, in ms",
          "title": "Time To Render Ms"
        }
      },
      "required": [
        "event_id"
      ],
      "title": "SpeedWorkersIndexationEvent",
      "type": "object"
    },
    "SpeedWorkersUrlHistory": {
      "properties": {
        "queried_url": {
          "description": "The URL from the request",
          "title": "Queried Url",
          "type": "string"
        },
        "resolved_url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "The URL as resolved by SpeedWorkers before caching, when it differs from the requested one",
          "title": "Resolved Url"
        },
        "events": {
          "default": [],
          "description": "Indexation events, newest first",
          "items": {
            "$ref": "#/$defs/SpeedWorkersIndexationEvent"
          },
          "title": "Events",
          "type": "array"
        },
        "reason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Why no indexation event was returned, if any",
          "title": "Reason"
        }
      },
      "required": [
        "queried_url"
      ],
      "title": "SpeedWorkersUrlHistory",
      "type": "object"
    }
  },
  "properties": {
    "pages": {
      "description": "Indexation history of each requested URL, in the order given",
      "items": {
        "$ref": "#/$defs/SpeedWorkersUrlHistory"
      },
      "title": "Pages",
      "type": "array"
    }
  },
  "required": [
    "pages"
  ],
  "title": "SpeedWorkersPageHistoryProcessedItem",
  "type": "object"
}
```

## Best Practices

**Use exponential backoff for polling.** Start with short intervals (1-2 seconds) and increase the delay between polls to reduce API load.

**Set reasonable timeouts.** For synchronous calls, configure your HTTP client with appropriate timeout values (30-60 seconds).

**Handle rate limits gracefully.** Implement retry logic with backoff when you receive 429 (Too Many Requests) responses.

**Batch when possible.** Use batch endpoints to reduce the number of API calls and improve throughput.
