Извлечение данных
Достаёт из страниц структурированные данные по JSON Schema.
Справочник написан на английском. Названия полей, примеры и коды ошибок на всех языках одинаковые.
Reads pages, or takes text you send, and returns data that matches your JSON Schema. The output is validated against the schema before it is returned. A value the pages do not contain is null when the schema allows null, and is never invented.
The schema supports type, properties, required, items, enum, const, description, format (date, date-time, uri, email), minimum, maximum, minItems, maxItems and anyOf. The root must be an object; the schema is at most 16 KB, depth 5 and 200 properties.
What is charged
Each item that comes back with status: ok is charged: the page read and the extraction. Output that does not validate after our own retries is reported as 422 extraction_failed and is free.
Units: fetch_page, extract_page. usage.items in the response lists them.
Request
POST https://api.websearch.fast/v1/web/extractPlanned. Until it ships, calls return 501 api_not_implemented.
Body
| Name | Type | Description |
|---|---|---|
urls | array of string | 1 to 10 items. |
text | string | 1 to 200,000 characters. |
schemarequired | object | JSON Schema 2020-12 subset; root must be an object; at most 16 KB, depth 5, 200 properties. |
instructions | string | At most 4000 characters. |
merge | boolean | Default false. |
max_chars_per_page | integer | 1000 to 200,000. Default 50000. |
include_sources | boolean | Default true. |
max_age | integer | Accept a stored copy up to this age in seconds. 0 to 2,592,000. |
no_cache | boolean | Never answer from a stored copy. Default false. |
timeout_ms | integer | 5000 to 60,000. |
Example request
curl https://api.websearch.fast/v1/web/extract \
-H "Authorization: Bearer $WEBSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"urls": ["https://shop.example.com/p/kettle-k2"],
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"price": {"type": "number"},
"currency": {"type": "string"},
"in_stock": {"type": "boolean"}
},
"required": ["name"]
}
}'import os
import httpx
response = httpx.post(
"https://api.websearch.fast/v1/web/extract",
headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
json={
"urls": ["https://shop.example.com/p/kettle-k2"],
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"price": {"type": "number"},
"currency": {"type": "string"},
"in_stock": {"type": "boolean"},
},
"required": ["name"],
},
},
timeout=60,
)
response.raise_for_status()
print(response.json())const response = await fetch("https://api.websearch.fast/v1/web/extract", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
urls: ["https://shop.example.com/p/kettle-k2"],
schema: {
type: "object",
properties: {
name: { type: "string" },
price: { type: "number" },
currency: { type: "string" },
in_stock: { type: "boolean" },
},
required: ["name"],
},
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());Example response
{
"object": "web.extract",
"request_id": "20261128120002123456789a1b2c3d4Kx7Qm2Pc",
"created": 1795867202,
"input": {
"urls": ["https://shop.example.com/p/kettle-k2"],
"merge": false
},
"items": [
{
"url": "https://shop.example.com/p/kettle-k2",
"status": "ok",
"data": {
"name": "Kettle K2",
"price": 49.9,
"currency": "EUR",
"in_stock": true
},
"sources": {"price": ["https://shop.example.com/p/kettle-k2"]}
}
],
"schema_valid": true,
"usage": {
"charged": true,
"items": [
{"unit": "fetch_page", "count": 1},
{"unit": "extract_page", "count": 1}
]
}
}Response fields
Validated data.
| Name | Type | Description | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
objectrequired | string | Always web.extract. | |||||||||||||||||||||||||||
request_idrequired | string | Same as the X-Request-Id header. | |||||||||||||||||||||||||||
createdrequired | integer | Unix seconds (UTC). | |||||||||||||||||||||||||||
inputrequired | object | The parameters as applied, defaults filled in. | |||||||||||||||||||||||||||
usagerequired | object | Show fields
| |||||||||||||||||||||||||||
cache | object | Show fields
| |||||||||||||||||||||||||||
warnings | array of object | Show fields
| |||||||||||||||||||||||||||
data | object | With merge: true. | |||||||||||||||||||||||||||
items | array of object | Show fields
| |||||||||||||||||||||||||||
sources | object | ||||||||||||||||||||||||||||
schema_validrequired | boolean | Always true. |
Errors
| Status | Codes |
|---|---|
400 | invalid_request, invalid_url, invalid_schema or invalid_image. Not charged. |
401 | invalid_token. Not charged. |
403 | pre_consume_token_quota_failed (the key's own spending limit), access_denied, web_not_allowed or model_not_in_plan (customer keys while plans cannot include the web tools). Not charged. |
404 | not_found or invalid_endpoint. Not charged. |
413 | read_request_body_failed: the request body is over the limit. Not charged. |
415 | unsupported_content. Not charged. |
422 | fetch_failed, site_refused, page_too_large or extraction_failed. Not charged. |
429 | rate_limited, concurrency_limited, api_key_temporarily_frozen, or the failure guard. Not charged. |
500 | internal_error. Not charged. |
501 | api_not_implemented: the endpoint, type or option has not shipped. Not charged. |
503 | source_unavailable, web_api_disabled, token_cache_busy or billing_busy (the charge could not be prepared in time; retry after Retry-After). Not charged. |
504 | timeout. Not charged. |