Mare Liberum

900 mTwilight zone

Guides · The engine room

Read a web page again for 51 tokens

An agent that watches a page (a price, a changelog, a status, a document it works on) reads it again and again, and pays for the whole page every time. The reader of the sea, /r/<address>, gives every Markdown answer an ETag. Send it back and the answer is only what changed. In the example of /engine#toll, a page of 9,128 tokens read again costs 51 tokens: the one line that says it is unchanged (9,077 saved). The line names the page's address, so a longer address makes it a little longer.

First: read once and keep the ETag

curl -sD - 'https://mareliberum.dev/r/https://example.com/'

The headers carry ETag: W/"e1-…" and x-sea-delta, the address to read the page again for only what changed. The body is the page as Markdown, the same as without them.

Then: read again with since=

curl -s 'https://mareliberum.dev/r/https://example.com/?since=e1-0123456789abcdef0123'

Three answers can come back:

Or: If-None-Match for a 304

curl -s -o /dev/null -w '%{http_code}\n' -H 'If-None-Match: W/"e1-0123456789abcdef0123"' 'https://mareliberum.dev/r/https://example.com/'

With the ETag of the page as it is now, the answer is 304 without a body. A HEAD with If-None-Match is answered the same way. The JSON form of the reader (format=json) knows neither since= nor If-None-Match; they are for the Markdown answer.

In your code

import urllib.request

seen = {}  # address -> the ETag of the last answer

def read(address: str) -> str:
    url = "https://mareliberum.dev/r/" + address
    tag = seen.get(address)
    if tag:
        url += ("&" if "?" in address else "?") + "since=" + tag.strip('W/"')
    with urllib.request.urlopen(url, timeout=30) as r:
        if r.headers.get("ETag"):
            seen[address] = r.headers["ETag"]
        return r.read().decode()
const seen = new Map<string, string>(); // address -> the ETag of the last answer

export async function read(address: string): Promise<string> {
  const tag = seen.get(address)?.replace(/^W\/"|"$/g, '');
  const url = 'https://mareliberum.dev/r/' + address + (tag ? (address.includes('?') ? '&' : '?') + 'since=' + tag : '');
  const r = await fetch(url);
  const etag = r.headers.get('etag');
  if (etag) seen.set(address, etag);
  return r.text();
}

Where it spares nothing

A page that changes on every read (a live counter, a feed, a time stamp in its text) sends its changed lines or the whole page each time. The first read of a page costs the page; the lever spares only from the second read on.

What it costs

The lever is lossless and counted in the public ledger of /savings, once a day per network and page. Example: an agent reads a page of 9,128 tokens again with since= and gets the one line that says it is unchanged: 9,077 tokens saved. Above the free quota that answer costs 0.2 × 9,077 × $2 / 1,000,000 = $0.003630 (about $0.0036). The toll is settled once the open sum reaches $0.05, about 14 such answers. An agent without a wallet gets the normal answer: the whole page.

Up to 10,000 tokens saved by the lossless levers stay free per network and UTC day; above that an answer costs 20 % of the tokens it saved, at USD 2 per million, settled over x402 in one payment from $0.05; without payment the lean answers pause and the normal answers continue, and unpaid tolls are not collected.

The reader as a whole: web page to Markdown · its OpenAPI description: /openapi/reader.json · the lever on /engine

More guides

Sources of every number on this page: /engine (the bench run) · /proof (the run) · the toll · the code: github.com/daoudandiaye98-alt/mare-liberum