---
title: "Wayback Machine"
description: "The Internet Archive's CDX API, with collapse and filter, and original responses replayed under id_."
canonical_url: "https://archives.agntn.dev/providers/wayback"
---
# Wayback Machine

> The Internet Archive's CDX API, with collapse and filter, and original responses replayed under id_.

<provider-facts slug="wayback">



</provider-facts>

## Load it

```ts
import { createArchive, providers } from "@agntn/archives";

const archive = createArchive(providers.wayback());
const yearly = createArchive(providers.wayback({ collapse: "timestamp:4" }));
const okOnly = createArchive(providers.wayback({ filter: "statuscode:200" }));
```

Or import `WaybackProvider` from `@agntn/archives` and construct it yourself.

## What it lists

`snapshots("example.com")` asks `web.archive.org/cdx/search/cdx` for `example.com/*`, so a domain lists everything under it. A full URL is looked up as is. Rows come back as `original`, `timestamp`, `statuscode`, `digest`, `mimetype` and `length`. `_meta` keeps the raw stamp of fourteen digits, the status, and `digest`, `mime` and `length` whenever the index knows them. The digest is the base32 SHA-1 of the archived body, so `filter: "digest:<value>"` finds every capture of those exact bytes. `length` is the size of the compressed WARC record, not of the page. The tool prints all four under each capture.

`collapse` defaults to `timestamp:4`, one capture per year, which keeps a domain with millions of captures answerable. Pass `collapse: "timestamp:8"` for one per day, or `collapse: "digest"` for one per distinct body. `filter` is passed through untouched (`statuscode:200`, `mimetype:text/html`, `!statuscode:3..`).

`from` and `to` narrow the CDX query itself, so a window is cheap here.

## Reading bodies

```ts
const capture = await archive.getContent("https://example.com", { timestamp: "2002" });
capture.snapshot; // https://web.archive.org/web/20021129054348id_/http://www.example.com:80/
```

Bodies are read under the `id_` modifier, which replays the original response without the toolbar or rewritten links. The capture is the newest at or before the timestamp, or the closest after it when nothing older exists. Got one of those? Its `_meta.selection` reads `after`. No posing as the older page. A snapshot URL from a listing works as the target too, and when it carries all fourteen digits it is still replayed if the CDX index is down, with `_meta.selection` set to `pinned` because the index never confirmed that capture.

## Gotchas

- The CDX index answers oldest first. A merged `providers.all()` listing sorted newest first can cut every Wayback row when other archives hold newer captures. Ask Wayback alone for early history. Want this year's captures of one page instead? `order: "newest"` turns `limit` negative, and CDX sends the last rows.
- CDX queries for busy domains take seconds, sometimes close to a minute. That's why Wayback waits 60 seconds unless you name a `timeout` yourself, and why caching pays off here.
- `collapse: "timestamp:4"` is a default, not a fact about the archive. Drop it when you count captures.

## Where it lives

`src/providers/wayback.ts`. CDX row mapping is shared with Archive-It and Common Crawl through `mapCdxRows` in `src/utils/_utils.ts`; `id_` playback through `readPlaybackCapture` in `src/utils/_content.ts`.


## Sitemap

See the full [sitemap](https://archives.agntn.dev/sitemap.md) for all pages.
