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

# Direct Web Search API

> Run direct web search requests with explicit query control, provider-specific options, and Sofya search, fetch, extract, and research operations

## Overview

Use `POST /api/web` when you want direct control over search requests and output formatting.

You can also call this tool through the unified [Data API](https://docs.nano-gpt.com/api-reference/endpoint/data-api.md) at `POST /api/v1/data/web/search`. The Data API preserves this endpoint's request body, response body, billing, and provider behavior while adding discovery and dispatch metadata.

For chat-first workflows, use `POST /api/v1/chat/completions` with model suffixes like `:online`, `:online/linkup`, or `:online/sofya`, including provider-specific suffixes such as `:online/exa-instant`, `:online/exa-deep-reasoning`, `:online/brave`, and `:online/valyu-web-deep`. See [Model Suffixes](https://docs.nano-gpt.com/api-reference/miscellaneous/model-suffixes.md#web-search-suffixes).

Sofya can do more than search on this endpoint. Set `provider: "sofya"` and choose the `search`, `fetch`, `extract`, or `research` operation.

See [hosted-key pricing](#pricing-hosted-key) before choosing a provider. Chat search also incurs the selected model's token charges. BYOK uses your own provider account and that provider's billing; it does not make provider usage free.

## When to use which endpoint

| Use case | Endpoint |
| - | - |
| You want the model to answer with web context in one call | `POST /api/v1/chat/completions` + `:online...` |
| You want one discoverable endpoint family for data tools | `POST /api/v1/data/web/search` |
| You need explicit control over `query`, `outputType`, domain/date filters, or structured schema output | `POST /api/web` |
| You need OpenAI-native web search | `POST /api/v1/chat/completions` or [Responses](https://docs.nano-gpt.com/api-reference/endpoint/responses.md#web-search-tool) (`POST /api/v1/responses`), on supported routes |

## Authentication

Either auth header is supported:

**Authorization** `string`

Bearer `YOUR_API_KEY`

**x-api-key** `string`

`YOUR_API_KEY`

## Accountless Lightning L402 Payment

For accountless payment, prefer the public Data API path:

```bash theme={null}
curl -i https://api.nano-gpt.com/api/v1/data/web/search \
  -H "Content-Type: application/json" \
  -H "x-x402: true" \
  -d '{
    "query": "What happened in AI this week?",
    "provider": "linkup",
    "depth": "standard",
    "outputType": "sourcedAnswer"
  }'
```

To request an accountless Lightning L402 quote, send the API request without `Authorization` or `x-api-key`, and include `x-x402: true`. NanoGPT will return `402 Payment Required` with the Lightning L402 payment option when available. This endpoint supports accountless Lightning L402 payments where listed by `GET /api/v1/x402/endpoints`, using only Lightning L402 when advertised. See [Accountless Lightning L402 API Payments](https://docs.nano-gpt.com/api-reference/miscellaneous/x402.md) for the full flow.

If you receive `401 missing_api_key` immediately, check that the initial quote request includes `x-x402: true`. Without that header, NanoGPT does not enter the accountless quote flow.

## Request body

**query** `string`

Search or research query. Required for every provider's search operation and for Sofya research. Not used by Sofya fetch or extract.

**provider** `string` (default: linkup)

Search provider: `linkup`, `tavily`, `exa`, `kagi`, `perplexity`, `valyu`, `brave`, `sofya`, or `firecrawl`. `openai-native` is not allowed on `/api/web`.

**operation** `string` (default: search)

Sofya operation: `search`, `fetch`, `extract`, or `research`. Other providers support `search` only.

**depth** `string` (default: standard)

Search depth. For Linkup: `standard` or `deep`.

> [!NOTE]
>
> For Linkup, `depth: "standard"` is executed as Linkup `fast` under the hood.

**outputType** `string` (default: searchResults)

Output mode. Allowed values: `searchResults`, `sourcedAnswer`, `structured`.

**structuredOutputSchema** `string`

Required when `outputType` is `structured`. Pass a JSON schema string.

**includeImages** `boolean` (default: false)

Include image results.

**fromDate** `string`

Earliest result date (`YYYY-MM-DD`).

**toDate** `string`

Latest result date (`YYYY-MM-DD`).

**includeDomains** `string[]`

Restrict results to these domains.

**excludeDomains** `string[]`

Exclude these domains.

> [!NOTE]
>
> Linkup supports `outputType: "searchResults"`, `"sourcedAnswer"`, and `"structured"`.
> Non-Linkup providers currently support only `outputType: "searchResults"`.

### Sofya operations

Sofya Search returns extracted page content instead of snippets alone. The other operations let you fetch known URLs, extract requested information from one page, or produce a cited multi-source research report.

#### Search

Use `operation: "search"` or omit `operation`.

* `query` (string, required)
* `maxResults` (integer, 1-20; default 10)
* `topic` (`general` or `news`)
* `freshness` (`day`, `week`, `month`, `year`, or `YYYY-MM-DD:YYYY-MM-DD`)
* `includeDomains` / `excludeDomains` (up to 10 strings each)

#### Fetch

Use `operation: "fetch"` with:

* `urls` (array of 1-10 URL strings, required)
* `includeRawHtml` or `include_raw_html` (boolean)

#### Extract

Use `operation: "extract"` with:

* `url` (string, required)
* `prompt` (string, required), describing what to extract

#### Research

Use `operation: "research"` with:

* `query` (string, required)
* `topic` (`general` or `news`)
* `freshness` (`day`, `week`, `month`, `year`, or `YYYY-MM-DD:YYYY-MM-DD`)
* `maxSources` or `max_sources` (integer, 5-30)

## Response shape

**data** `array|object`

Provider-formatted payload.

**metadata** `object`

**metadata**

**query** `string`

Executed query.

**provider** `string`

Resolved provider (for example, `linkup`).

**operation** `string`

Resolved operation. This is `search` except for Sofya fetch, extract, or research requests.

**depth** `string`

Resolved depth.

**outputType** `string`

Resolved output type.

**timestamp** `string`

ISO-8601 timestamp.

**cost** `number`

Request cost in USD.

For `searchResults`, `data` is normally an array of normalized results. Sofya extract and research return an object, while Sofya fetch returns an array.
For `sourcedAnswer` and `structured`, `data` is the provider response object.

### Example response

```json theme={null}
{
  "data": "... provider-formatted payload ...",
  "metadata": {
    "query": "string",
    "provider": "linkup",
    "depth": "standard",
    "outputType": "sourcedAnswer",
    "timestamp": "ISO-8601",
    "cost": 0.006
  }
}
```

## Pricing (hosted key)

| Mode | Price |
| - | - |
| Linkup standard | \$0.006 |
| Linkup deep | \$0.06 |
| Sofya search | \$0.01575 |
| Sofya fetch | \$0.00525 per URL |
| Sofya extract | \$0.02625 |
| Sofya research | \$0.13125 |

## Error codes

| HTTP status | Meaning |
| - | - |
| `400` | Invalid parameters |
| `401` | Invalid session or auth |
| `402` | Insufficient balance or usage cap |
| `429` | Rate limited |
| `503` | Provider key missing |
| `504` | Search failed or timed out |

## Examples

```bash cURL (Authorization) theme={null}
curl -X POST https://api.nano-gpt.com/api/web \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What happened in AI this week?",
    "provider": "linkup",
    "depth": "standard",
    "outputType": "sourcedAnswer"
  }'
```

```bash cURL (x-api-key) theme={null}
curl -X POST https://api.nano-gpt.com/api/web \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Latest OpenAI announcements",
    "provider": "linkup",
    "depth": "deep",
    "outputType": "searchResults"
  }'
```

```bash cURL (structured output) theme={null}
curl -X POST https://api.nano-gpt.com/api/web \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Top 5 AI coding tools in 2026 with pricing",
    "provider": "linkup",
    "depth": "standard",
    "outputType": "structured",
    "structuredOutputSchema": "{\"type\":\"object\",\"properties\":{\"tools\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"price\":{\"type\":\"string\"}},\"required\":[\"name\"]}}},\"required\":[\"tools\"]}"
  }'
```

```bash cURL (chat completions with Linkup) theme={null}
curl -X POST https://api.nano-gpt.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o:online/linkup",
    "messages": [
      { "role": "user", "content": "Summarize today'\''s top AI headlines." }
    ]
  }'
```

```bash cURL (chat completions with Sofya) theme={null}
curl -X POST https://api.nano-gpt.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o:online/sofya",
    "messages": [
      { "role": "user", "content": "Summarize today'\''s top AI headlines." }
    ]
  }'
```

### Sofya examples

```bash cURL (search) theme={null}
curl -X POST https://api.nano-gpt.com/api/web \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "sofya",
    "operation": "search",
    "query": "NanoGPT API documentation",
    "maxResults": 10,
    "topic": "general"
  }'
```

```bash cURL (fetch) theme={null}
curl -X POST https://api.nano-gpt.com/api/web \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "sofya",
    "operation": "fetch",
    "urls": ["https://sofya.co/docs"],
    "includeRawHtml": false
  }'
```

```bash cURL (extract) theme={null}
curl -X POST https://api.nano-gpt.com/api/web \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "sofya",
    "operation": "extract",
    "url": "https://sofya.co/pricing",
    "prompt": "Extract the available plans and their prices."
  }'
```

```bash cURL (research) theme={null}
curl -X POST https://api.nano-gpt.com/api/web \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "sofya",
    "operation": "research",
    "query": "Compare current AI web search APIs",
    "maxSources": 15
  }'
```

## Related docs

* [Chat Completion](https://docs.nano-gpt.com/api-reference/endpoint/chat-completion.md)
* [Data API](https://docs.nano-gpt.com/api-reference/endpoint/data-api.md)
* [Web Search in Text Generation Guide](https://docs.nano-gpt.com/api-reference/text-generation.md)
* [Model Suffixes](https://docs.nano-gpt.com/api-reference/miscellaneous/model-suffixes.md)


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