---
agent:
  instructions: "Search crawlapi docs via GET /.well-known/search?q={query} (add &format=json or Accept: application/json for JSON)."
  endpoint: "https://docs.crawlapi.dev/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.crawlapi.dev/llms.txt"
---

> Documentation index: https://docs.crawlapi.dev/llms.txt
> Search docs: https://docs.crawlapi.dev/.well-known/search?q={query}
> OpenAPI 3.1 specification: https://docs.crawlapi.dev/openapi.json

# Timeouts

> Configure request deadlines, client timeouts, and disconnect behavior.

Control how long crawlapi spends on a request with the `timeout` field, and set your HTTP client timeout at least **5 seconds longer** so your client never gives up right as the API finishes.

## Setting `timeout`

| Setting | Range | Default | Behavior when exceeded |
| --- | --- | --- | --- |
| `timeout` (request body) | `1,000`–`60,000` ms | `30,000` ms | Returns [`408 TIMEOUT`](https://docs.crawlapi.dev/errors.md#TIMEOUT) (`retryable: true`) |
| HTTP client timeout | `timeout + 5` seconds | `35`–`65` s | Gives the server time to return its response cleanly |

**cURL**

```bash
curl -sS --max-time 50 https://api.crawlapi.dev/v1/scrape \
  -H "Authorization: Bearer $CRAWLAPI_API_KEY" \
  -H 'content-type: application/json' \
  --data '{"url": "https://example.com", "timeout": 45000}'
```

**TypeScript**

```typescript
const response = await fetch('https://api.crawlapi.dev/v1/scrape', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.CRAWLAPI_API_KEY}`,
    'content-type': 'application/json',
  },
  body: JSON.stringify({ url: 'https://example.com', timeout: 45000 }),
  signal: AbortSignal.timeout(50_000),
});
const body = await response.json();
if (!body.success) throw new Error(`${body.error.code}: ${body.error.message}`);
console.log(body.data.markdown);
```

**Python**

```python
import os
import requests

response = requests.post(
    "https://api.crawlapi.dev/v1/scrape",
    headers={"Authorization": f"Bearer {os.environ['CRAWLAPI_API_KEY']}"},
    json={"url": "https://example.com", "timeout": 45000},
    timeout=50,
)
body = response.json()
if not body["success"]:
    raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")
print(body["data"]["markdown"])
```

## Client timeouts and disconnects

- **Client disconnects:** Closing the connection early cancels in-flight work on the server.
- **Avoid duplicate retries:** Keep your HTTP client timeout longer than the request `timeout`. If your client drops the socket right as the server finishes and immediately retries, the retry runs as a second request.

> **Set a hard cap in the request body, not the socket**
>
> If your app needs a 15-second cap, pass `"timeout": 15000` in the JSON body and set your HTTP client timeout to `20` seconds.

## Choosing a deadline

| Workload | Request `timeout` | HTTP client timeout |
| --- | --- | --- |
| User-facing / interactive requests | `15,000`–`30,000` ms | `20`–`35` s |
| JavaScript-heavy apps or large PDFs | `45,000`–`60,000` ms | `50`–`65` s |
| Background jobs and URL batches | `30,000`–`60,000` ms | `65` s (or use [`crawl -i`](https://docs.crawlapi.dev/cli.md)) |

## Locale

Pages are requested in a locale matching the site's country domain or URL path when present (such as `.fr` or `/de-de/`), and `en-US` otherwise.
