# Search the web

> POST /v1/search: web search results as JSON – title, address, snippet, related searches – and, if you like, every result page fetched as Markdown in the same call.

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

`POST /v1/search` sends your query to a web search engine (DuckDuckGo) and returns the results as JSON. With `scrape` it also fetches every result page – as Markdown, text or data – so an agent gets the answer and the sources in one call.

## Search

**cURL**

```bash
curl https://api.virginproxy.com/v1/search \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "web scraping api pricing",
    "limit": 5,
    "language": "en",
    "country": "us"
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/search",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "query": "web scraping api pricing",
        "limit": 5,
        "language": "en",
        "country": "us",
    },
    timeout=30,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["results"])
print(data["credits"])
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/search", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    query: "web scraping api pricing",
    limit: 5,
    language: "en",
    country: "us",
  }),
  signal: AbortSignal.timeout(30_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.results);
console.log(data.credits);
```

**Python SDK**

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

vp = VirginProxy()  # reads VP_KEY
data = vp.call("POST", "/v1/search", {
    "query": "web scraping api pricing",
    "limit": 5,
    "language": "en",
    "country": "us",
})
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.call("POST", "/v1/search", { body: {
  query: "web scraping api pricing",
  limit: 5,
  language: "en",
  country: "us",
} });
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/search");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VP_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "query" => "web scraping api pricing",
        "limit" => 5,
        "language" => "en",
        "country" => "us",
    ], JSON_UNESCAPED_SLASHES),
]);
$data = json_decode(curl_exec($ch), true);
if (isset($data["error"])) {
    exit($data["error"]["code"] . ": " . $data["error"]["message"] . PHP_EOL);
}
echo json_encode($data["results"], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
echo $data["credits"], PHP_EOL;
```

**Go**

```go
package main

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

func main() {
	payload := []byte(`{
  "query": "web scraping api pricing",
  "limit": 5,
  "language": "en",
  "country": "us"
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/search", 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: 30 * 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["results"])
	fmt.Println(data["credits"])
}
```

POST`/v1/search`

*Response:*

```json
{
  "query": "web scraping api pricing",
  "engine": "duckduckgo",
  "results": [
    { "position": 1, "title": "Pricing – Example Scraper", "url": "https://scraper.example/pricing", "snippet": "Plans from $29 a month …" },
    { "position": 2, "title": "Web scraping APIs compared (2026)", "url": "https://blog.example/compare", "snippet": "We tested eight services …", "date": "2026-10-14" }
  ],
  "ads": [],
  "related": ["web scraping api free", "best web scraping api"],
  "questions": ["How much does a web scraping API cost?"],
  "credits": 1,
  "requests": ["req_8PqT2nL0aZx4mWcVb7sE"]
}
```

## Search and read the results

`scrape` takes the options of [POST /v1/requests](https://docs.virginproxy.com/reference/) without `url`. `true` means Markdown of the main content. Each result then has a `page` with `body`, `format`, `tokens`, `status` and its `credits` – or `error` with the code when that page could not be fetched; the other results are not affected.

**cURL**

```bash
curl https://api.virginproxy.com/v1/search \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "site:docs.virginproxy.com crawl",
    "limit": 3,
    "scrape": {
      "format": "markdown",
      "main_content": true
    }
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/search",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "query": "site:docs.virginproxy.com crawl",
        "limit": 3,
        "scrape": {"format": "markdown", "main_content": True},
    },
    timeout=30,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["status"], data["cost"]["credits"])
```

**Node.js**

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

**Python SDK**

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

vp = VirginProxy()  # reads VP_KEY
data = vp.call("POST", "/v1/search", {
    "query": "site:docs.virginproxy.com crawl",
    "limit": 3,
    "scrape": {"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.call("POST", "/v1/search", { body: {
  query: "site:docs.virginproxy.com crawl",
  limit: 3,
  scrape: { format: "markdown", main_content: true },
} });
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/search");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VP_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "query" => "site:docs.virginproxy.com crawl",
        "limit" => 3,
        "scrape" => ["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["status"], " ", $data["cost"]["credits"], PHP_EOL;
```

**Go**

```go
package main

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

func main() {
	payload := []byte(`{
  "query": "site:docs.virginproxy.com crawl",
  "limit": 3,
  "scrape": {
    "format": "markdown",
    "main_content": true
  }
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/search", 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: 30 * 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["status"], data["cost"].(map[string]any)["credits"])
}
```

POST`/v1/search`

## Options

| Field | Default | Meaning |
| --- | --- | --- |
| `query` | required | 1 to 400 characters. The engine's operators work: quotes, `site:`, `-word`. |
| `engine` | `"duckduckgo"` | `duckduckgo`. Further engines are described in the [member guides](https://dash.virginproxy.com/guides/). |
| `limit` | `10` | 1 to 50 results. Up to 5 result pages are read to reach it. |
| `language` | `"en"` | Language of the results, e.g. `de` or `pt-BR`. |
| `country` | – | Two letters, e.g. `us`: the country the engine picks results for. It is a search setting – it does not change where the request comes from. |
| `time_range` | – | `day`, `week`, `month`, `year`: only results from this period. |
| `include_domains` | – | Up to 20 domains: only results from them (subdomains included). |
| `exclude_domains` | – | Up to 20 domains: no results from them. |
| `scrape` | – | `true` or the options of a request: also fetch every result. |
| `max_credits` | – | 1 to 10,000: cap for the whole call, fetched results included. Results not fetched any more get `"error": "budget_exhausted"`. |
| `tag` | – | Your tag; every request of the call is in your log with it. |

## What it costs

Every result page of the engine and every fetched result is an ordinary request in your [request log](https://docs.virginproxy.com/account/#list) and costs what a request costs – usually 1 credit each. A search is mostly 1 credit. With `scrape` add about 1 credit per fetched result. `credits` is the sum, `requests` lists every request.

Each result has its real address in `url`; `display_url` is the address as the engine shows it, when it does.

When the engine sends no page that can be read, the call fails with `search_failed` (424): the page that came is charged like any request, and `error.credits` says how much. Retry a little later.

> **Tip:** In the MCP server this is the tool `search`: an AI agent can search, read the sources and quote them – in one tool call.

## Test keys

With a [test key](https://docs.virginproxy.com/test-mode/) you get sample results that keep to your options (limit, domains), nothing is fetched and nothing charged.
