websearch.fast
控制台获取密钥

搜索建议

根据输入的前缀给出查询建议。

本参考页为英文。字段名、示例和错误码在所有语言版本中都一样。

Returns query suggestions for the start of a query, for a search box or for an agent that refines its own query. Suggestions come from open encyclopedic data: names of people, places, organizations and things, and article titles.

q is the prefix, at most 256 bytes and 200 characters. Leading spaces are removed; a trailing space is kept and asks for the next word. num is 1 to 20, default 10. language is detected from q when it is not sent. timeout_ms is 500 to 5000, default 5000. location is not accepted.

The response lists suggestions in rank order without repeats, the language they were looked up in, and attribution with the open data sets they come from. Show the attribution as you show other licence notices; the licences page lists the data sets.

What is charged

One autocomplete unit per answer with at least one suggestion, whatever their number. An empty list carries the warning no_results and is free, as is every error.

Units: autocomplete. usage.items in the response lists them.

Request

POST https://api.websearch.fast/v1/web/autocomplete

Body

NameTypeDescription
qrequiredstringThe prefix, at most 200 characters. Leading spaces are removed; a trailing space asks for the next word. 1 to 256 characters.
countrystringISO 3166-1 alpha-2 country code, case-insensitive.
languagestringBCP 47 language tag. Detected from q when absent. At most 12 characters.
numinteger1 to 20. Default 10.
timeout_msintegerUpper bound for the call. 500 to 5000. Default 5000.

Example request

curl https://api.websearch.fast/v1/web/autocomplete \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"q": "marie cu", "num": 3}'
import os
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/autocomplete",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    json={
        "q": "marie cu",
        "num": 3,
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
const response = await fetch("https://api.websearch.fast/v1/web/autocomplete", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    q: "marie cu",
    num: 3,
  }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());

Example response

{
  "object": "web.autocomplete",
  "request_id": "20261128120000223456789a1b2c3d4Kx7Qm2Pa",
  "created": 1795867200,
  "input": {"q": "marie cu", "num": 3, "timeout_ms": 5000},
  "language": "en",
  "suggestions": [
    {"value": "Marie Curie"},
    {"value": "Marie Curie Hospice"},
    {"value": "Marie Curie Medal"}
  ],
  "attribution": [
    {
      "source": "Open encyclopedic data",
      "url": "https://data.example.org/",
      "license": "CC BY-SA 4.0"
    }
  ],
  "usage": {
    "charged": true,
    "items": [{"unit": "autocomplete", "count": 1}]
  }
}

Response fields

Suggestions.

NameTypeDescription
objectrequiredstringAlways web.autocomplete.
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
warningsarray of object
Show fields
NameTypeDescription
coderequiredstringFor example no_results, content_partial, answer_unavailable, partial, all_failed, reach_reduced.
messagestring
paramstring
suggestionsrequiredarray of object
Show fields
NameTypeDescription
valuerequiredstring
languagestringLanguage of the suggestions.
attributionarray of objectThe open data projects the data comes from, with their licences. Show it with the data.
Show fields
NameTypeDescription
sourcerequiredstringName of the open data set the fact comes from.
urlrequiredstring
licenserequiredstringFor example CC BY-SA 4.0 or CC0 1.0.

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.
429rate_limited, concurrency_limited, api_key_temporarily_frozen, or the failure guard. Not charged.
500internal_error. 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.