> ## Documentation Index
> Fetch the complete documentation index at: https://docs.styne.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch

> POST /v1/fetch returns the clean text of up to 100 URLs as Markdown or plain text. It reads the Styne index first and fetches the page live when the index has no copy or the copy is older than you accept. PDFs come back as text.

[//]: # "smoke: not executed, the search endpoints are served by the main API host and bill the account that calls them"

Base URL: `https://api.styne.ai`. Every request carries `Authorization: Bearer $STYNE_API_KEY`.

## Quick start

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/v1/fetch \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"urls": ["https://example.com/"], "max_age_hours": 24}'
```

```python theme={"theme":"css-variables"}
import os
import requests

r = requests.post(
    "https://api.styne.ai/v1/fetch",
    headers={"Authorization": f"Bearer {os.environ['STYNE_API_KEY']}"},
    json={"urls": ["https://example.com/"], "max_age_hours": 24},
    timeout=30,
)
for page in r.json()["results"]:
    print(page["url"], page["status"], page["tokens"])
    print(page["content"])
```

```typescript theme={"theme":"css-variables"}
const res = await fetch("https://api.styne.ai/v1/fetch", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.STYNE_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ urls: ["https://example.com/"], max_age_hours: 24 }),
});
const { results } = await res.json();
for (const page of results) console.log(page.url, page.status, page.content);
```

## Request fields

Only `urls` is required.

| Field | Type | What it does |
| - | - | - |
| `urls` | list of strings, 1 to 100 | Absolute `http` or `https` URLs. A repeated URL is fetched and billed once. |
| `live` | `auto`, `never` or `always` | `auto` (default): the index first, live for a miss. `never`: the index only. `always`: live only. |
| `max_age_hours` | number, 0.1 to 8,760 | The oldest index copy you accept. An older copy is fetched live. |
| `disable_cache_fallback` | boolean | With `max_age_hours`: report a failed live read instead of returning the older copy. |
| `format` | `markdown` or `text` | Default `markdown`. |
| `timeout_ms` | integer, 1,000 to 25,000 | Deadline for the whole request. Default 15,000. Pages not done by then end as `timeout` and are free. |
| `query` | string | Each result then also carries `passages`: the best passages of the page for this query, verbatim. |
| `max_passages_per_result` | integer, 1 to 8 | Passages per page with `query`. Default 3. |
| `links` | boolean | Return the links of each page, in page order, up to 500. |
| `subpages` | integer, 1 to 20 | Also return up to this many pages the page links to on its own site, nested in `subpages`. Each is billed when it returns content. |
| `subpage_target` | string | With `subpages`: words that rank which links are read first. |
| `subpages_max_depth` | integer, 1 to 3 | How deep the subpage reads go. Default 1. |
| `structure` | boolean | Return tables and lists of the page as JSON beside the text. |
| `as_of` | string | The latest stored version at or before this time (RFC 3339, or `YYYY-MM-DD` for the end of that UTC day). |
| `ocr` | boolean | Read scanned PDF pages with OCR. |

## Response fields

`results` has one entry per requested URL, in order.

| Field | What it is |
| - | - |
| `url`, `final_url` | The URL as sent, and where it ended after redirects. |
| `status` | `ok`, or why there is no text, for example `http_error`, `invalid_url`, `blocked_destination`, `timeout`, `no_text_layer`. Only `ok` carries content. |
| `reason` | A short code for a status that is not `ok`. |
| `source` | `index`, `live`, `cache`, `history` or `wayback`: where the text came from. |
| `http_status` | The status of the page. |
| `title`, `language`, `content_type` | Page metadata. |
| `content` | The clean Markdown or text. `null` unless `status` is `ok`. PDF pages are separated by a form feed. |
| `format` | `markdown` or `text`. |
| `published_at`, `crawled_at` | The page's date, null when it gives none, and when the text was read. |
| `tokens` | Tokens of `content` (the count `tiktoken` gives for `cl100k_base`). |
| `truncated` | `true` when the text was cut at a size cap. |
| `billed` | `true` when this page was charged. |
| `passages`, `links`, `subpages`, `structure` | Only when asked for. |

Beside `results`: `request_id`, `warnings` and `usage` (`billable_units` pages billed, `pages_requested`, `pages_returned`, `tokens_returned`, `cost_usd`, `billed_from`, `balance_usd`, `free_remaining_usd`).

## Limits

| Limit | Value |
| - | - |
| URLs per request | 1 to 100 |
| Deadline per request | 1 to 25 seconds, 15 by default |
| Requests per minute, per account | 600; 1,200 once the account has added credit; plans have their own |
| Requests in flight, per account | 10; 20 once the account has added credit; plans have their own |

Private, loopback and link-local addresses are refused. Each site is read at a polite rate.

## Pricing

$1 per 1,000 pages ($0.001 a page), charged for each page returned with text. A blocked page, an error, a timeout, an empty page and a repeated URL are free. It is billed from your prepaid credit, which never expires; an account with no credit gets `402`. See [Plans and billing](https://docs.styne.ai/billing.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.