# Extract quickstart

One page as Markdown, then what a failure looks like, then the labels.

## 1. Read one page

```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"],
    "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"
        ],
        "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"
    ],
    "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);
```

`live` fetches the page now. The answer has one entry per URL in `data.results`, in the order sent. A page that worked has `status: "ok"`, its `title`, and its main content in `markdown`.

## 2. Check each URL

The HTTP status is `200` whenever the request itself was valid, even when every URL failed. Look at each entry. One that failed looks like this:

```text
"url": "https://example.org/private",
"status": "error",
"error": {
  "code": "ROBOTS_DISALLOWED",
  "message": "This site's robots.txt does not allow our bot to fetch this page."
}
```

A URL that fails costs nothing, except a page that does not exist in a browser mode ([pricing](https://millionshort.com/docs/extract/pricing)). [Errors](https://millionshort.com/docs/extract/errors) lists the codes and what to try next.

## 3. Choose what comes back

```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"],
    "mode": "live",
    "formats": ["markdown", "metadata", "links"],
    "max_chars": 20000
  }'
```

```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"
        ],
        "mode": "live",
        "formats": [
            "markdown",
            "metadata",
            "links"
        ],
        "max_chars": 20000
    },
    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"
    ],
    "mode": "live",
    "formats": [
      "markdown",
      "metadata",
      "links"
    ],
    "max_chars": 20000
  }),
});
if (!res.ok) throw new Error(`POST /v1/extract failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

`formats` takes `markdown`, `text`, `links` and `metadata`. `max_chars` cuts long content, and `truncated` says when it did.

## 4. Read the labels

Every page that comes back says what it is, at no charge: `topic`, `page_type` and `source_hint`, each with a confidence. A program can route a page by them without reading it. See [Labels](https://millionshort.com/docs/extract/labels).

## Next

- [Parameters](https://millionshort.com/docs/extract/parameters): every field, the modes and the response.
- [Batch](https://millionshort.com/docs/extract/batch): up to 1,000 URLs as one job.
- [Pricing and limits](https://millionshort.com/docs/extract/pricing): what each mode costs.

The SDKs do not cover this endpoint yet. Call the endpoint over HTTP as above.
