websearch.fast
КонсольПолучить ключ

Извлечение данных

Достаёт из страниц структурированные данные по 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/extract

Planned. Until it ships, calls return 501 api_not_implemented.

Body

NameTypeDescription
urlsarray of string1 to 10 items.
textstring1 to 200,000 characters.
schemarequiredobjectJSON Schema 2020-12 subset; root must be an object; at most 16 KB, depth 5, 200 properties.
instructionsstringAt most 4000 characters.
mergeboolean Default false.
max_chars_per_pageinteger1000 to 200,000. Default 50000.
include_sourcesboolean Default true.
max_ageintegerAccept a stored copy up to this age in seconds. 0 to 2,592,000.
no_cachebooleanNever answer from a stored copy. Default false.
timeout_msinteger5000 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.

NameTypeDescription
objectrequiredstringAlways web.extract.
request_idrequiredstringSame as the X-Request-Id header.
createdrequiredintegerUnix seconds (UTC).
inputrequiredobjectThe parameters as applied, defaults filled in.
usagerequiredobject
Show fields
NameTypeDescription
chargedrequiredboolean
itemsrequiredarray of object
Show fields
NameTypeDescription
unitrequiredstringBillable unit, for example search_web, content_page, fetch_page, geocode, autocomplete, knowledge.
countrequiredinteger
cacheobject
Show fields
NameTypeDescription
hitrequiredbooleanThe response, or every page in it, came from a stored copy.
data_age_secondsrequiredintegerAge of the oldest part of the response.
fetched_atrequiredintegerUnix seconds when the oldest part was read.
warningsarray of object
Show fields
NameTypeDescription
coderequiredstringFor example no_results, content_partial, answer_unavailable, partial, all_failed, reach_reduced.
messagestring
paramstring
dataobjectWith merge: true.
itemsarray of object
Show fields
NameTypeDescription
urlstring
statusrequiredstringOne of ok, failed.
dataobject
errorobject
Show fields
NameTypeDescription
coderequiredstring
messagestring
sourcesobjectTop-level property to the URLs its value came from.
sourcesobject
schema_validrequiredbooleanAlways true.

Errors

StatusCodes
400invalid_request, invalid_url, invalid_schema or invalid_image. Not charged.
401invalid_token. Not charged.
403pre_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.
404not_found or invalid_endpoint. Not charged.
413read_request_body_failed: the request body is over the limit. Not charged.
415unsupported_content. Not charged.
422fetch_failed, site_refused, page_too_large or extraction_failed. Not charged.
429rate_limited, concurrency_limited, api_key_temporarily_frozen, or the failure guard. Not charged.
500internal_error. Not charged.
501api_not_implemented: the endpoint, type or option has not shipped. Not charged.
503source_unavailable, web_api_disabled, token_cache_busy or billing_busy (the charge could not be prepared in time; retry after Retry-After). Not charged.
504timeout. Not charged.