# Output formats

> Get a page as Markdown, plain text or clean HTML instead of raw markup, optionally reduced to its main content. Works in POST /v1/requests and in raw mode.

Source: https://docs.virginproxy.com/formats/

Most of a web page is navigation, scripts and layout. With `format` you get what you actually read: Markdown for language models and notes, plain text for search and analysis, or clean HTML that is safe to store and show.

**cURL**

```bash
curl https://api.virginproxy.com/v1/requests \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://quotes.toscrape.com/",
    "format": "markdown",
    "main_content": true
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/requests",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "url": "https://quotes.toscrape.com/",
        "format": "markdown",
        "main_content": True,
    },
    timeout=180,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["format"], data["cost"]["credits"])
print(data["body"])
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/requests", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    url: "https://quotes.toscrape.com/",
    format: "markdown",
    main_content: true,
  }),
  signal: AbortSignal.timeout(180_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.format, data.cost.credits);
console.log(data.body);
```

**Python SDK**

```pysdk
from virginproxy import VirginProxy  # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy()  # reads VP_KEY
data = vp.request({
    "url": "https://quotes.toscrape.com/",
    "format": "markdown",
    "main_content": True,
})
print(data)
```

**Node SDK**

```nodesdk
import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.request({
  url: "https://quotes.toscrape.com/",
  format: "markdown",
  main_content: true,
});
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/requests");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 180,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VP_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "url" => "https://quotes.toscrape.com/",
        "format" => "markdown",
        "main_content" => true,
    ], JSON_UNESCAPED_SLASHES),
]);
$data = json_decode(curl_exec($ch), true);
if (isset($data["error"])) {
    exit($data["error"]["code"] . ": " . $data["error"]["message"] . PHP_EOL);
}
echo $data["format"], " ", $data["cost"]["credits"], PHP_EOL;
echo $data["body"], PHP_EOL;
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	payload := []byte(`{
  "url": "https://quotes.toscrape.com/",
  "format": "markdown",
  "main_content": true
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/requests", bytes.NewReader(payload))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("VP_KEY"))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 180 * time.Second}
	res, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var data map[string]any
	if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
		log.Fatal(err)
	}
	if res.StatusCode >= 300 {
		e := data["error"].(map[string]any)
		log.Fatalf("%v: %v", e["code"], e["message"])
	}
	fmt.Println(data["format"], data["cost"].(map[string]any)["credits"])
	fmt.Println(data["body"])
}
```

POST`/v1/requests`[≈ 1 credit](https://docs.virginproxy.com/billing/#cost)[Open in Playground](https://dash.virginproxy.com/playground#request=eyJ1cmwiOiJodHRwczovL3F1b3Rlcy50b3NjcmFwZS5jb20vIiwiZm9ybWF0IjoibWFya2Rvd24iLCJtYWluX2NvbnRlbnQiOnRydWV9)

*Response · 200 OK:*

```json
{
  "id": "req_V7dLq2mTzR9aKc4xWb0E",
  "status": 200,
  "final_url": "https://quotes.toscrape.com/",
  "headers": { "content-type": "text/html; charset=utf-8" },
  "format": "markdown",
  "body": "# Quotes to Scrape\n\n> “The world as we have created it is a process of our thinking.”\n>\n> by [Albert Einstein](https://quotes.toscrape.com/author/Albert-Einstein)\n\n…",
  "body_encoding": "utf8",
  "truncated": false,
  "exit": { "ip": "203.0.113.42", "country": "DE" },
  "bytes": { "up": 2004, "down": 14871 },
  "duration_ms": 641,
  "cost": { "credits": 1, "credits_used": 31, "credits_included": 1000 }
}
```

## The formats

| Value | What you get |
| --- | --- |
| `raw` | Default. The body exactly as the target sent it. |
| `markdown` | Headings as `#`, lists, links as `[text](absolute URL)`, images as `![alt](absolute URL)`, tables as GitHub-style tables, code as fenced blocks. |
| `text` | The readable text only, blocks separated by an empty line, no markup at all. |
| `clean_html` | HTML without `script`, `style`, `noscript`, `iframe` and `template`, without `on…` event attributes and comments. Links and images are made absolute. |

## Only the main content

`"main_content": true` keeps only the part of the page that carries its content before converting it. We take the `<main>` or `<article>` element with the most text; without one, the `<body>` without navigation, header, footer, sidebars, forms, scripts, frames and graphics. It works with every format, `raw` included.

> **Tip:** Markdown plus `main_content` is usually the smallest input you can give a language model: often a tenth of the raw HTML.

## Shape the conversion: format_options

| Field | Default | Meaning |
| --- | --- | --- |
| `include_selector` | – | A CSS selector: keep only this part of the page, e.g. `article` or `#content`. |
| `exclude_selector` | – | A CSS selector: leave these parts out, e.g. `nav, .ads, .cookie-banner`. |
| `images` | `true` | `false`: no images in the Markdown. |
| `links` | `true` | `false`: links become plain text. |
| `max_pages` | `100` | For [documents](https://docs.virginproxy.com/documents/): pages, slides or sheets at most, 1 to 500. |

Every converted answer carries `tokens`: about how many tokens the body is (about 4 characters per token in Latin script, 1 per character in Chinese, Japanese and Korean) – to plan what fits into a prompt.

## Black out personal data: redact

`redact` replaces personal data in the text you get – the converted body, `extracted`, `parsed` and `auto_extracted` – before it leaves us. It needs a `format` (`markdown`, `text` or `clean_html`): a raw body is never changed. Kinds: `email`, `phone`, `iban`, `card`, `ip`, or `true` for all. Each becomes a marker such as `[email]`; `redacted` counts them, e.g. `{"email": 2, "phone": 1}`. Card numbers are checked with their check digit, so prices and order numbers stay.

*Request:*

```json
{
  "url": "https://example.com/contact",
  "format": "text",
  "redact": [
    "email",
    "phone"
  ]
}
```

## What changes in the response

- `format` says which format was actually applied.
- `body` holds the converted text, always with `"body_encoding": "utf8"`.
- `headers` keep the target's original `content-type`.
- Formats apply to HTML and to [documents](https://docs.virginproxy.com/documents/) (PDF, Word, Excel, PowerPoint, OpenDocument, CSV). Any other answer (JSON, images) comes back unchanged and the response says `"format": "raw"`.
- `tokens` estimates the length of the converted text for a language model.

## In raw mode

`GET /v1/raw` takes `format` as a query parameter and returns the converted text directly, with a matching `Content-Type`: `text/markdown`, `text/plain` or `text/html`, each with `charset=utf-8`.

```bash
curl "https://api.virginproxy.com/v1/raw?url=https%3A%2F%2Fquotes.toscrape.com%2F&format=markdown" \
  -H "Authorization: Bearer $VP_KEY" -o quotes.md
```

*Response:*

```http
HTTP/2 200
content-type: text/markdown; charset=utf-8
x-vp-request-id: req_P3sNw8YhQe1bLt6uVx2C
x-vp-credits: 1

# Quotes to Scrape

> “The world as we have created it is a process of our thinking.”
…
```

## Cost

Converting costs nothing extra. You pay for what the target sent (`bytes.down`), not for the shorter output. Combine `format` with [parse](https://docs.virginproxy.com/parse/) and [extract](https://docs.virginproxy.com/extract/) freely: both always read the original HTML.
