# Stretch: Shrink Pages & PDFs, Watch for Changes (`geeky_goth_gamer/stretch`) Actor

Shrink pages and long PDFs into query packs; watch URLs and wake only on change. 1 Dec 2026, tiktoken cl100k_base, input only: six jobs 12,497,152→80,869 tokens (155×), or 5,151,402→80,869 (64×) from Markdown. $0.003/page, $0.01/doc, $0.002/check, $0.02/change. Cache hits free. No free hosted tier.

- **URL**: https://apify.com/geeky_goth_gamer/stretch.md
- **Developed by:** [Chris Day](https://apify.com/geeky_goth_gamer) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions, Single-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 pages shrink

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Stretch: Shrink Pages & PDFs, Watch for Changes

Hosted Apify Actor for AI agents that need to spend fewer tokens on the same jobs: shrink a web page, pack a long PDF around a question, or watch URLs and only wake when the content actually changed.

This is a paid, pay-per-event Actor. There is no free hosted tier. Cache hits and failed fetches are free. It does not change the prices of any existing Actors.

### Pricing

| Event | USD |
|---|---:|
| Actor start | $0.00005 |
| Page shrink (`page-distilled`) | $0.003 |
| Large document (`doc-converted`) | $0.01 |
| Watch check (`source-checked`) | $0.002, including unchanged |
| Change / wake (`change-notified`) | $0.02 when a change is delivered |
| Cache hit / failed fetch | $0 |

Standby HTTP: `POST /shrink`, `/doc`, `/watch`, `/research`, or `/run` with `"operation"`. Readiness probes and 4xx input errors are never charged.

### Measured savings (method, then numbers)

On 1 December 2026 we ran six typical agent workflows against real public pages and one public PDF (IRS Publication 17, 2025). We counted **input tokens only** with **tiktoken `cl100k_base`** — the text that would be pasted into a model, not replies, system prompts, or tool wrappers. Monitoring was simulated (24 hourly snapshots from one fetch per URL, with two scripted changes) so we did not hit live sites 240 times. Full method, raw tables and caveats: `apify-tools/usage-savings/SAVINGS-BENCHMARK.md`.

Headlines we will stand behind (and only these):

1. **Six-job mix:** 12,496,992 tokens without the toolkit versus 80,869 with it (**about 155×**). If the agent already had clean Markdown, the same jobs were 5,151,402 versus 80,869 (**about 64×**). Accuracy on this toolkit: **87/87** source-grounded questions (see SAVINGS-BENCHMARK.md section 4). An AI given only Stretch’s packs gave the same answers as with full sources, **42/42 blind questions** (section 4.5). Quote “reads less / faster / cheaper” only with that accuracy result attached. An AI given only Stretch’s packs answered all 18 questions about the 2.6M-word Mahabharata correctly, the same as with the full book, while sent 680× fewer tokens (blind test; outreach/book-demo/WRITE-UP.md).
2. **Long PDF, targeted questions:** IRS Pub 17 went from 295,581 tokens to a 3,647-token pack (**about 81×**). The pack body contained every required figure we asked for ($15,750, $31,500, $23,625, $33,100, $23,850, $96,950, a referral to Pub. 550, and April 15, 2026). Publication 17 does not itself print the 0/15/20% long-term capital-gain table.
3. **Already-clean Markdown still shrinks when you ask a question:** 16 pricing pages, 65,043 Markdown tokens → 5,880 in one pack (**about 11×**). 16 Python docs pages, 144,496 → 11,322 (**about 13×**; a low-confidence 24k pack now auto-expands — at a hard 24k cap this job was 4,855 / about 30×, which we no longer quote alone).

Caveats, stated plainly: these are job-mix estimates, not a promise that any plan "stretches N times" (official plan pages we checked do not publish a fixed token cap). A query pack can still drop a passage that did not rank. Tiny pages barely shrink. A JavaScript-rendered shell (for example a pricing page that returns almost no HTML text) is flagged `NEEDS_BROWSER_RENDER` rather than silently returned as empty; we try embedded JSON first.

### Speed (measured on this box, 1 Dec 2026, 7:25–7:28am Australia/Hobart)

Fetch + processing, same sources as the token benchmark. After parallel fetches and cache reuse: 16 pricing pages **10.954s → 2.161s** (5.07×); one watch cycle of 10 sources **7.255s → 1.935s** (3.75×); 20 repeated lookups **16.289s → 6.643s** (2.45×). A local 142-page PDF still takes about **3.14s** cold (`pdftotext` + pack); the same bytes reused by hash skip `pdftotext` (**0.767s**). On already-fast docs hosts, Stretch can spend *more* wall-clock on HTML→Markdown and packing (16 Python pages: 1.089s raw GET vs 3.620s with Stretch).

Prefill / time-to-first-token is an **estimate**, not an API measurement: **2,000 input tokens/s**, rounded down from Microsoft’s published ~2,667 prompt tok/s for Llama 3.1 8B Instruct on 1×H100 (vLLM, chat profile, 26 Aug 2025; https://techcommunity.microsoft.com/blog/azurehighperformancecomputingblog/inference-performance-of-llama-3-1-8b-using-vllm-across-various-gpus-and-cpus/4448420). At that rate, the six-job mix (12,496,992 → 80,869 tokens) is about **104 minutes** of prefill vs about **40 seconds**. Method, caveats and the per-workflow table: `apify-tools/usage-savings/SAVINGS-BENCHMARK.md` section 3.

Local documents may be up to 80 MB by default (URL fetches 40 MB). Over-limit inputs are refused with a clear error; they are never silently truncated. Set `STRETCH_MAX_LOCAL_BYTES` / `STRETCH_MAX_URL_BYTES` (or `STRETCH_MAX_BYTES`) to raise a cap.

### Input

- `operation`: `shrink` | `doc` | `watch` | `research`
- `urls`: public http(s) URLs (up to 40; 10 for `doc`)
- `query`: optional question (required for `research`); builds a BM25 pack, drops nav/boilerplate, keeps tables
- `questions`: optional list of questions; builds a multi-question briefing pack (per-question sections, key facts, coverage). `research` may omit `query` when `questions` is set.
- `required`: optional strings that must appear in a pack
- `maxChars`, `ttl`, `returnBody`, `html` (inline shrink)

On a cache hit with no query, the default text is a trusted one-line summary (age, sha256, "unchanged since") so the agent can skip re-pasting the body. Pass `returnBody: true` to get the stored Markdown (still free for a no-query shrink).

### Licence

Proprietary. Copyright 2026 Chris Day. All rights reserved.

# Actor input Schema

## `operation` (type: `string`):

What to do in this run.

## `urls` (type: `array`):

Public http(s) URLs to shrink, convert, watch, or pack. Up to 40 (10 for doc).

## `query` (type: `string`):

Optional question. When set, the result is a query-focused pack (BM25, boilerplate dropped, tables kept). Required for research unless questions is set.

## `questions` (type: `array`):

Optional list of questions for a multi-question briefing pack: per-question sections (deduped), plus KEY FACTS, an OUTLINE, and a mandatory COVERAGE line listing omitted sources or pages with a fetch-more pointer. Does not change the single-query 24,000-character default. If set on research, query may be omitted.

## `required` (type: `array`):

Optional strings that must appear in a doc or research pack (for example figures you need quoted).

## `maxChars` (type: `integer`):

Pack or extract budget (500–200000). Defaults: 8000 for a single page shrink, 24000 for a research or document pack.

## `ttl` (type: `integer`):

If set, a cached extract older than this is treated as STALE and rebuilt. Omit to trust a hash match indefinitely.

## `returnBody` (type: `boolean`):

On a cache hit, return the stored Markdown instead of the short trusted summary (still free for a no-query shrink). Default false.

## `html` (type: `string`):

Optional. Shrink this HTML or text instead of fetching a URL (still billed as page-distilled).

## Actor input object example

```json
{
  "operation": "shrink",
  "urls": [
    "https://example.com/"
  ],
  "query": "What is this page about?",
  "returnBody": false
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "operation": "shrink",
    "urls": [
        "https://example.com/"
    ],
    "query": "What is this page about?"
};

// Run the Actor and wait for it to finish
const run = await client.actor("geeky_goth_gamer/stretch").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "operation": "shrink",
    "urls": ["https://example.com/"],
    "query": "What is this page about?",
}

# Run the Actor and wait for it to finish
run = client.actor("geeky_goth_gamer/stretch").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "operation": "shrink",
  "urls": [
    "https://example.com/"
  ],
  "query": "What is this page about?"
}' |
apify call geeky_goth_gamer/stretch --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,geeky_goth_gamer/stretch"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/yYSNGQd3EaO7nJ8jd/builds/oae3gOhhRWewdDmVB/openapi.json
