# Quick start

Get a key, run a first search, read a page and handle errors.

## 1. Get a key

websearch.fast uses relay.fast accounts. Sign in to the [console](https://websearch.fast/console/keys) with your relay.fast account and create a key there, or create one on the relay.fast [keys page](https://relay.fast/keys). The same key calls the models and the Web API, and both are paid from the same balance.

```bash
export WEBSEARCH_API_KEY="sk-..."
```

## 2. Search

curl:

```bash
curl https://api.websearch.fast/v1/web/search \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"q": "postgres 18 release notes", "num": 5}'
```

Python:

```python
import os
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/search",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    json={
        "q": "postgres 18 release notes",
        "num": 5,
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/search", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    q: "postgres 18 release notes",
    num: 5,
  }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

Each result has `position`, `title`, `url`, `domain`, `snippet` and `origin`, and `published_at` when the page states a date. `url` is the address of the page itself. See [search](https://websearch.fast/docs/search) for every field.

## 3. Get the page text with the results

Add `content` to receive the cleaned text of the top pages in the same response, so the model does not need a second call to read them.

curl:

```bash
curl https://api.websearch.fast/v1/web/search \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "q": "postgres 18 release notes",
    "num": 5,
    "content": {"pages": 3, "max_chars_per_page": 4000}
  }'
```

Python:

```python
import os
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/search",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    json={
        "q": "postgres 18 release notes",
        "num": 5,
        "content": {"pages": 3, "max_chars_per_page": 4000},
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/search", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    q: "postgres 18 release notes",
    num: 5,
    content: { pages: 3, max_chars_per_page: 4000 },
  }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

## 4. Read a page

curl:

```bash
curl https://api.websearch.fast/v1/web/fetch \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://docs.example.org/guide/install",
    "max_chars": 4000
  }'
```

Python:

```python
import os
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/fetch",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    json={
        "url": "https://docs.example.org/guide/install",
        "max_chars": 4000,
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/fetch", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    url: "https://docs.example.org/guide/install",
    max_chars: 4000,
  }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

## 5. Handle errors

Errors have the same shape on every native path. Branch on the HTTP status first and on `error.code` second. The message is for people and can change. Quote `request_id` when you report a failure.

```json
{
  "error": {
    "code": "fetch_failed",
    "message": "The page could not be read. (request id: 20261128120008123456789a1b2c3d4Kx7Qm2Ph)",
    "type": "invalid_request_error",
    "param": "url"
  },
  "request_id": "20261128120008123456789a1b2c3d4Kx7Qm2Ph"
}
```

Retry `429` after `Retry-After`, and `500`, `503` and `504` with backoff and a cap. Do not retry other `4xx` unchanged. The [errors page](https://websearch.fast/docs/concepts/errors) lists every code.

## Base URLs

| Host | Base URL |
| --- | --- |
| websearch.fast | `https://api.websearch.fast/v1/web` |
| relay.fast | `https://relay.fast/v1/web` |
| relay.fast reserve host | `https://direct.relay-fast.com/v1/web` |

All hosts take the same relay.fast keys and serve the same paths. API paths never redirect, because a redirect can drop the `Authorization` header. A wrong path returns `404 invalid_endpoint`.

## For AI agents

- Read the key from an environment variable or a secret store. Do not print it or put it in a URL.
- Branch on the HTTP status and `error.code`, not on the message.
- Web calls cost money. One `search` with `content` costs less than a search plus several `fetch` calls. Do not loop over large URL sets unless the operator asked for it.
- On `429` wait for `Retry-After`. On `5xx` retry with backoff and a cap. Do not retry `site_refused`.
- Quote the `request_id` when you report a failure.

## What we do not promise

- Availability. Uptime, response times and the presence of an endpoint, type or result field are not promised. [Status](https://websearch.fast/docs/status) reports measured numbers.
- Results. Rankings, coverage and the results for a query can change at any time. We do not promise that results match any other service or that a given page is in the index.
- Prices. Prices and unit weights can change.
- Notice. Changes to prices, endpoints, fields or this API can happen without advance notice.
- Compatibility. The compatibility paths answer in the shape of the format they accept, but not every field is filled. The [migration guide](https://websearch.fast/docs/migrate) lists which.
