# Extract guides

The jobs Extract is built for, each as the requests that do it.

## Search, then read

The common pair: search for pages, then read the ones worth reading.

1. Search, and choose results by title, snippet, `popularity` and `risk`:

```bash
curl https://api.millionshort.com/v1/search \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "query": "reading a tide table", "num_results": 10, "remove_top_sites": 1000, "max_highlights": 2 }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/search",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "query": "reading a tide table",
        "num_results": 10,
        "remove_top_sites": 1000,
        "max_highlights": 2
    },
    timeout=30,
)
r.raise_for_status()
for hit in r.json()["data"]["results"]:
    print(hit["position"], hit["title"], hit["url"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/search', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "query": "reading a tide table",
    "num_results": 10,
    "remove_top_sites": 1000,
    "max_highlights": 2
  }),
});
if (!res.ok) throw new Error(`POST /v1/search failed: ${res.status}`);
const { data } = (await res.json()) as {
  data: { results: { position: number; title: string; url: string }[] };
};
for (const hit of data.results) console.log(hit.position, hit.title, hit.url);
```

The same call as a tool of the MCP server:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "search",
    "arguments": {
      "query": "reading a tide table",
      "num_results": 10,
      "remove_top_sites": 1000,
      "max_highlights": 2
    }
  }
}
```

2. Send the chosen URLs, up to 20, to Extract:

```bash
curl https://api.millionshort.com/v1/extract \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": ["https://example.org/guides/tide-tables", "https://example.org/guides/tidal-range"],
    "mode": "live"
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/extract",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "urls": [
            "https://example.org/guides/tide-tables",
            "https://example.org/guides/tidal-range"
        ],
        "mode": "live"
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/extract', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "urls": [
      "https://example.org/guides/tide-tables",
      "https://example.org/guides/tidal-range"
    ],
    "mode": "live"
  }),
});
if (!res.ok) throw new Error(`POST /v1/extract failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

When the text we hold is enough, skip the second call: [`include_content`](https://millionshort.com/docs/search/highlights) on the search returns it for web and news results.

## Keep only the pages worth reading

Hand Extract a mixed list and let the [labels](https://millionshort.com/docs/extract/labels) sort it. With `page_types` or `topics` on the request, a page that does not match comes back as an entry with `filtered: true` and no content, so nothing unwanted reaches the model. The fetch of a filtered page is still charged.

## Many pages

More than 20 URLs is a [batch](https://millionshort.com/docs/extract/batch): up to 1,000 as one job. Poll it, or name a [webhook](https://millionshort.com/docs/webhooks) and be told when it ends. A page of a batch that is waiting for a busy site waits, at no cost, until the batch has run for 60 minutes; only after that can it fail as `HOST_BUSY`.

## A page that scripts build

When a `live` page looks like an empty shell that scripts fill in, the response carries a `looks_script_built` warning. Send that URL again with `mode: "rendered"`. No mode is ever upgraded for you, because `rendered` costs more.

## Staying within the limits

One site gets at most 2 fetches at once and 1 a second from all our customers together, and a team may fetch 2,000 pages of one site a day. Spread a large job over sites, not over one. [Pricing and limits](https://millionshort.com/docs/extract/pricing) has the numbers.
