> For the complete documentation index, see [llms.txt](https://docs.meganova.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.meganova.ai/api-reference/platform-api/search/fetch-url.md). Agents can also search and read this documentation through its [MCP server](https://docs.meganova.ai/~gitbook/mcp).

# Fetch URL

Convert any web URL or PDF to clean markdown.

Convert any web URL or PDF to clean markdown. Useful when you already have a URL and just want the readable text without standing up your own scraper.

Handles HTML pages (including JavaScript-rendered SPAs) and PDFs.

## HTTP Request

`POST` `{API_URL}/serverless/fetch`

## Request Body

| Parameter   | Type              | Default      | Description                                                    |
| ----------- | ----------------- | ------------ | -------------------------------------------------------------- |
| `url`       | URL string        | **required** | Must be a fully-qualified `http(s)://` URL                     |
| `max_bytes` | int (1024–131072) | `32768`      | Soft cap on extracted content size; longer pages get truncated |

### Optional Headers

| Header               | Purpose                                                                                                                                                                                       |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `X-Request-Group-Id` | Optional UUID. Recorded in audit logs for cross-endpoint correlation but does **not** affect `/fetch` quota (every URL extraction is its own unit of work, no group dedup like `/search` has) |

## Response

```json
{
  "data": {
    "url":          "https://arxiv.org/pdf/2310.06825.pdf",
    "markdown":     "Mistral 7B Albert Q. Jiang, Alexandre Sablayrolles ...",
    "content_type": "application/pdf",
    "bytes":        24718,
    "backend":      "routing:pdf",
    "usage": {
      "request_id":          "req_78000fe7a72f4e329d4f818ea44bcd43",
      "cost_usd":            0.0,
      "overage_charged_usd": 0.0,
      "duration_ms":         3323
    }
  },
  "message": "Fetch completed",
  "status":  "success"
}
```

### Fields

| Field                            | Description                                                                                                                               |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `data.url`                       | Echo of the requested URL                                                                                                                 |
| `data.markdown`                  | Extracted page text in markdown format. Up to `max_bytes` long                                                                            |
| `data.content_type`              | MIME type detected by the fetcher (e.g. `text/html`, `application/pdf`)                                                                   |
| `data.bytes`                     | Length of the markdown payload in bytes                                                                                                   |
| `data.backend`                   | Diagnostic label for the fetch path that served the request. Customers don't need to act on this                                          |
| `data.usage.request_id`          | Unique identifier for this call. Cache for support tickets                                                                                |
| `data.usage.cost_usd`            | Informational only — not what you're billed. **Always `0.0`** for `/fetch`                                                                |
| `data.usage.overage_charged_usd` | Real $ debited. `0.0` while inside today's free `/fetch` quota (default 50 / day); jumps to `\$0.002` once you've crossed the daily limit |
| `data.usage.duration_ms`         | Wall-clock latency on our side                                                                                                            |

## Quota & Billing

`/fetch` has its own quota dimension, **independent** of `/search`:

* First **50** successful calls per UTC day are free
* Each call past that costs **$0.002**, debited from `credit_balance` in real time (the same rate as a `/search` prompt-group)
* Failed fetches (`5xx`) do **not** consume quota and are **not** charged
* `X-Request-Group-Id` does not affect `/fetch` quota — every URL extraction counts

See the [Web Search overview](https://docs.meganova.ai/api-reference/platform-api/search.md#quota-model) for the full quota model.

## Examples

### Fetch a PDF

```bash
curl -X POST '{API_URL}/serverless/fetch' \
  -H 'Authorization: Bearer {TOKEN/KEY}' \
  -H 'Content-Type: application/json' \
  -d '{ "url": "https://arxiv.org/pdf/2310.06825.pdf" }'
```

### Fetch a JavaScript-rendered page

```bash
curl -X POST '{API_URL}/serverless/fetch' \
  -H 'Authorization: Bearer {TOKEN/KEY}' \
  -H 'Content-Type: application/json' \
  -d '{ "url": "https://example.com" }'
```

### Limit extracted content size

```bash
curl -X POST '{API_URL}/serverless/fetch' \
  -H 'Authorization: Bearer {TOKEN/KEY}' \
  -H 'Content-Type: application/json' \
  -d '{ "url": "https://very-long-page.example", "max_bytes": 8192 }'
```

### Python — batch RAG ingestion

```python
import os
import requests

BASE = "{API_URL}/serverless"
HEADERS = {
    "Authorization": f"Bearer {os.environ['MEGANOVA_API_KEY']}",
    "Content-Type": "application/json",
}


def fetch(url):
    r = requests.post(f"{BASE}/fetch", headers=HEADERS,
                      json={"url": url}, timeout=30)
    r.raise_for_status()
    return r.json()["data"]


urls = [
    "https://arxiv.org/abs/2310.06825",
    "https://openai.com/research/some-paper",
    "https://anthropic.com/research/another-paper",
]
docs = [fetch(u)["markdown"] for u in urls]
# docs is a list of markdown strings, ready to embed and load into a vector DB
```

### JavaScript / TypeScript

```typescript
const BASE = "{API_URL}/serverless";
const KEY  = process.env.MEGANOVA_API_KEY!;

export async function fetchUrl(url: string, maxBytes = 32768) {
  const r = await fetch(`${BASE}/fetch`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ url, max_bytes: maxBytes }),
  });
  if (!r.ok) throw new Error(`Fetch failed: ${r.status} ${await r.text()}`);
  return (await r.json()).data;
}
```

## When to use `/fetch` vs `/search`

| Scenario                                                          | Use                                                                                     |
| ----------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| User has a question, no specific URL                              | [`/search`](https://docs.meganova.ai/api-reference/platform-api/search/search-query.md) |
| User pastes a URL ("summarize this article")                      | `/fetch`                                                                                |
| User has a question + already provided one or more reference URLs | Both — fetch the URLs for context, run `/search` for any gaps                           |
| Agent in a ReAct loop deciding when to read a specific page       | Register `/fetch` as a tool; let the LLM decide                                         |
| Batch URL → markdown for a vector DB                              | `/fetch` (no search needed)                                                             |
| Snippet-only feed where full text isn't needed                    | `/search` with `enrich=false` (skips automatic fetch)                                   |

## Related

* [Web Search overview](https://docs.meganova.ai/api-reference/platform-api/search.md)
* [Search query](https://docs.meganova.ai/api-reference/platform-api/search/search-query.md) — natural-language search with built-in enrichment
* [Get search usage](https://docs.meganova.ai/api-reference/platform-api/search/get-search-usage.md) — today's quota and spend
