openapi: 3.1.0
info:
  title: SerpKite SERP API
  version: 1.19.0
  description: |
    Public search API (api.serpkite.com). Google results as clean JSON or Markdown
    for AI agents, plus a Google Custom Search–compatible endpoint. Official SDKs:
    `serpkite` on npm and PyPI, `github.com/serpkite/serpkite-go`.

    **Auth:** `Authorization: Bearer skt_live_…`. A bare `Authorization: skt_live_…`
    (no scheme) is also accepted, for MCP hosts that can't add one. GET requests
    may pass `?api_key=` instead. `/customsearch/v1` also accepts Google's `?key=`.

    **Bodies:** every vertical accepts `POST` with a JSON object or `GET` with the
    same parameters in the query string (only `GET /v1/search` is spelled out
    here). Unknown parameters are rejected with 400, and so is a parameter the
    endpoint would ignore (e.g. `time` on `/v1/scholar`, `ll` on `/v1/search`). To run many queries at once,
    use `POST /v1/batches`.

    **Formats:** `format=json` (default) returns the schemas below.
    `format=markdown` returns `text/markdown` for every vertical.
    `format=compact` and `fields=` return a reduced JSON object (same top-level
    keys, fewer item fields, `meta` always kept), so required item fields may be
    absent there.

    **Responses** share one envelope: `request` (the normalised request),
    `results` (the vertical's primary list), vertical-specific extras and `meta`.
    All keys are snake_case.

    **Credits** are decimal numbers (e.g. `0.5`). Failed, empty and blocked
    responses are refunded. Every billed response carries `X-Credits-Used`,
    `X-Credits-Remaining`, `X-Cost-USD`, `X-Cache` (`HIT`|`MISS`), `X-Latency-Ms`,
    `X-Tokens-Estimate` and `X-Request-Id`.

    **Errors** share one body: `{"error":{"code","message","request_id"}}`.
    Upstream failures (`upstream_error`, `upstream_blocked`, `upstream_timeout`)
    are `503` with `Retry-After`, never billed and safe to retry. The API never
    returns `502` or `504`. `429` also carries `Retry-After`: `rate_limited` is
    the per-second limit (per key; the keys of an account that never bought a
    pack share one), or a full batch queue or crawl/research task limit
    (`Retry-After: 30`); `daily_limit_reached` is reserved for a free daily
    limit on accounts that never bought a pack (none applies at the moment;
    it would reset at 00:00 UTC and name the billing page).
    `403 account_restricted` means the account's free use is paused because it
    appears to be one of several accounts run by the same person (same device
    or network, requests in step with other accounts, or email domains set up
    together) or uses a disposable email address; buying any pack lifts it.

    **CORS:** `Access-Control-Allow-Origin: *` without credentials; the `X-*`
    headers above are exposed, so a browser playground can call the API with a key.
    The keyless `/playground/search` is the exception: it only answers serpkite.com
    and app.serpkite.com (other `Origin`s get 403).

    Credit table: search/news/images/videos/maps/places/shopping/scholar/patents/
    webpage/customsearch = 1 per page; place details = 1; `num=100` depth bundle = 7; reviews = 1 per 10;
    autocomplete = 0.5; `include_content` = +1 per fetched page;
    batches ×0.5 (from 2026-11-23 a batch depth request is 0.5 per page with
    results, without the bundle cap: `num=100` = 5); cache hit via `max_age` ×0.5. `engine=consensus` (search only) =
    the sum of one page per provider that returned results.

    **AI** (Claude writes, OpenAI's Decisions API runs typed checks; a failed
    model step is never billed): an answer (`include_answer` on `/v1/search` and
    `/v1/news`, the model part of `/v1/answer`) = +2 over the result page, +4
    when it read pages (`include_content`, `/v1/answer` depth=standard);
    `/v1/extract` `summary` = +4 and `output_schema` = +4 per page;
    `/v1/research` = lite 30, standard 75, deep 200. Responses that used a
    model carry `meta.llm`.

    **AI assistants** (`/v1/chatgpt`, `/v1/gemini`, `/v1/copilot`,
    `/v1/ai_mode`, `/v1/brave_ai`): a `prompt` sent to the public assistant
    as a logged-out user; the response is its answer
    (`text`, `markdown`) with the `sources` it cited or listed,
    `search_queries`, `products` and `places` where the assistant shows them,
    and `mentions` for the brands and domains in `track`. ChatGPT 4, Gemini 3,
    Copilot 3, AI Mode 2, Brave AI 2 credits per answer, the same in batches;
    a cache hit (`max_age`) ×0.5; failed, refused and empty answers are free.
    Answers take 10–90 s: run many through `POST /v1/batches` or a monitor.
servers:
  - url: https://api.serpkite.com
  - url: http://localhost:8080
security:
  - bearer: []
paths:
  /healthz:
    get:
      summary: Service health
      security: []
      responses:
        "200": { description: OK }
        "503": { description: A dependency is down }
  /livez:
    get:
      summary: Liveness only
      security: []
      responses:
        "200": { description: OK }

  /v1/search:
    post:
      summary: Google web search (organic results, knowledge graph, answer box, people also ask, top stories, local pack…)
      operationId: search
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/SearchOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
    get:
      summary: Same as POST /v1/search with query-string parameters
      operationId: searchGet
      parameters:
        - { name: q, in: query, required: true, schema: { type: string } }
        - { name: country, in: query, schema: { type: string } }
        - { name: language, in: query, schema: { type: string } }
        - { name: location, in: query, schema: { type: string } }
        - { name: num, in: query, schema: { type: integer } }
        - { name: page, in: query, schema: { type: integer } }
        - { name: uule, in: query, schema: { type: string } }
        - { name: ll, in: query, schema: { type: string } }
        - { name: time, in: query, schema: { type: string } }
        - { name: tbs, in: query, schema: { type: string } }
        - { name: device, in: query, schema: { type: string } }
        - { name: safe, in: query, schema: { type: string } }
        - { name: autocorrect, in: query, schema: { type: boolean } }
        - { name: format, in: query, schema: { type: string } }
        - { name: fields, in: query, schema: { type: string } }
        - { name: include_content, in: query, schema: { type: integer } }
        - { name: ads, in: query, schema: { type: boolean } }
        - { name: max_age, in: query, schema: { type: integer } }
        - { name: engine, in: query, schema: { type: string }, description: "google (default), auto, consensus, one provider, or a comma-separated list (e.g. google,brave)" }
        - { name: include_domains, in: query, schema: { type: string }, description: "Comma-separated domains, or the key repeated (see SearchRequest.include_domains)" }
        - { name: exclude_domains, in: query, schema: { type: string }, description: "Comma-separated domains, or the key repeated" }
        - { name: boost_domains, in: query, schema: { type: string }, description: "Comma-separated domains, or the key repeated" }
        - { name: start_date, in: query, schema: { type: string, format: date } }
        - { name: end_date, in: query, schema: { type: string, format: date } }
        - { name: highlights, in: query, schema: { type: boolean }, description: Needs include_content }
        - { name: include_answer, in: query, schema: { type: boolean }, description: Add a cited AI answer (+2 credits; +4 with include_content) }
        - { name: api_key, in: query, schema: { type: string } }
      responses:
        "200": { $ref: "#/components/responses/SearchOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/images:
    post:
      summary: Google Images
      description: "One page is a block of up to 100 images for 1 credit; page 2 starts at position 101. `num` returns only the first `num` images of the page (same credit). A page past the last one returns empty `results`, free."
      operationId: images
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/ImagesOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/videos:
    post:
      summary: Google Videos
      operationId: videos
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/VideosOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/news:
    post:
      summary: Google News
      operationId: news
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/NewsOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/maps:
    post:
      summary: Google Maps search (places with coordinates). Accepts `ll` ("@lat,lng,zoomz") to search around a point
      operationId: maps
      description: |
        Google Maps search results: name, full address, coordinates, categories, rating, website,
        phone, opening hours and the place's identifiers (`place_id`, `cid`, `fid`) for
        `/v1/place` and `/v1/reviews`. Categories, addresses and hours are in `language`.

        **Where:** `ll` ("@lat,lng,zoomz") searches the map at that point and zoom; `location`
        (or `uule`) searches the named place. Without either, Google picks the area from the
        query (an exact name or address) or from where the request comes from, so local queries
        such as "coffee" need `location` or `ll`.

        **Yandex Maps:** with `engine=yandex` (where the deployment enables it) the results come
        from Yandex Maps, which covers Russia and the CIS in depth. They have the same fields,
        with the Yandex organisation id in `oid` (for `/v1/place`) and `yandex_maps_url` instead
        of Google's identifiers; categories, addresses and hours follow `language` (`ru` for
        Russian). Pass `ll` or a `location` (a city, appended to the query); `uule` and `tbs`
        are refused.
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/PlacesOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/places:
    post:
      summary: Google local results (places)
      operationId: places
      description: Same results as `/v1/maps` (Google Maps search), with the same fields and location rules.
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/PlacesOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/place:
    post:
      summary: Details of one place (by `place_id`, `cid`, `fid` or Yandex `oid`); 1 credit
      operationId: place
      description: |
        The full Google Maps listing of one place: address, country, coordinates, time zone,
        categories, opening hours (as text and as structured `weekly_hours`), website, phone,
        rating, description and photos, in `language`. `results` holds the place, or is empty
        (not charged) when no place has that identifier.

        With `oid` (a Yandex Maps organisation id, e.g. from an `engine=yandex` maps result or
        `yandex.ru/maps/org/<name>/<oid>/`) the listing comes from Yandex Maps, where the
        deployment enables it: `oid` implies `engine=yandex` and can't be combined with Google's
        identifiers. Closed listings (temporarily or permanently) carry no hours.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/PlaceRequest" }
      responses:
        "200": { $ref: "#/components/responses/PlacesOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/reviews:
    post:
      summary: Reviews of a place (by `place_id`, `cid` or `fid`); 1 credit per 10 reviews
      operationId: reviews
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ReviewsRequest" }
      responses:
        "200": { $ref: "#/components/responses/ReviewsOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/shopping:
    post:
      summary: Google Shopping
      operationId: shopping
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/ShoppingOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/scholar:
    post:
      summary: Google Scholar
      operationId: scholar
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/ScholarOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/patents:
    post:
      summary: Google Patents
      operationId: patents
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/PatentsOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/autocomplete:
    post:
      summary: Google autocomplete suggestions (0.5 credit)
      operationId: autocomplete
      requestBody: { $ref: "#/components/requestBodies/Search" }
      responses:
        "200": { $ref: "#/components/responses/AutocompleteOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/webpage:
    post:
      summary: Fetch any public URL (HTML or PDF) and return clean Markdown + metadata (1 credit)
      operationId: webpage
      description: |
        Fetches the page and returns its main content as Markdown and plain
        text. Pages in any charset (windows-1251, KOI8-R, Latin-1, UTF-16)
        come back as UTF-8: the declared charset is used when the bytes match
        it, otherwise it is detected. `html` (with `include_html`) is decoded
        to UTF-8 too.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/WebpageRequest" }
      responses:
        "200": { $ref: "#/components/responses/WebpageOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/chatgpt:
    post:
      summary: Ask ChatGPT as a logged-out user and get its answer, cited sources, products and places (4 credits)
      operationId: chatgpt
      description: |
        Opens chatgpt.com as a logged-out visitor in a standard browser, sends
        `prompt` and returns the answer. With `web_search` (default true) ChatGPT
        searches the web; `false` lets it decide. ChatGPT localises prices, shops
        and places to where the visitor is: set `country` to ask as a visitor in
        that country. Guests get ChatGPT's default free model (`model`).
        Usually takes 10–30 s; failed or refused answers are free.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ChatGPTRequest" }
            example: { prompt: "What are the best CRMs for a 10-person startup?", track: ["hubspot.com", "Pipedrive"] }
      responses: &assistantResponses
        "200": { $ref: "#/components/responses/AssistantOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/gemini:
    post:
      summary: Ask Google Gemini as a logged-out user and get its answer with the sources it grounded on (3 credits)
      operationId: gemini
      description: |
        Opens gemini.google.com as a logged-out visitor and sends `prompt`. Most
        answers take 5–30 s; answers that search the web take longer. `country`
        asks as a visitor in that country.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/AssistantRequest" }
            example: { prompt: "How do heat pumps work in cold climates?" }
      responses: *assistantResponses
  /v1/copilot:
    post:
      summary: Ask Microsoft Copilot Search on Bing and get its answer, cited sources and products (3 credits)
      operationId: copilot
      description: |
        Microsoft Copilot Search (bing.com/copilotsearch, Bing's AI answer).
        The Copilot app itself has no logged-out access. `country` and `language`
        set Bing's market. Products are Bing's sponsored product cards. 15–40 s.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/AssistantRequest" }
            example: { prompt: "best mattress for side sleepers", country: us }
      responses: *assistantResponses
  /v1/ai_mode:
    post:
      summary: Ask Google AI Mode and get its answer, cited sources and products (2 credits)
      operationId: aiMode
      description: |
        Google's AI Mode (`udm=50`) for `prompt`, logged out. `country` is the
        country Google answers for; `location` (or `uule`) the place, so
        "near me" prompts answer for that city. 10–45 s.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/AssistantRequest" }
            example: { prompt: "how to remove a red wine stain from a wool carpet" }
      responses: *assistantResponses
  /v1/brave_ai:
    post:
      summary: Ask Brave Search's AI answer and get it with cited sources, the searches it ran and products (2 credits)
      operationId: braveAi
      description: |
        Brave Search's AI answer ("Ask Brave") for `prompt`, logged out. `country`
        sets Brave's market (prices and shops follow it); `location` (or `uule`)
        the place local answers are for. About 10 s. Brave doesn't
        answer every query: then `text` is empty, `meta.parse_quality` is `empty` and
        the request costs nothing.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/AssistantRequest" }
            example: { prompt: "best budget noise cancelling headphones under $100" }
      responses: *assistantResponses
  /v1/extract:
    post:
      summary: Up to 20 URLs (HTML or PDF) as Markdown, text or HTML, with query-ranked highlights, links, images, an AI summary or JSON extracted with a schema (1 credit per URL read)
      operationId: extract
      description: |
        Every URL is billed only when it comes back: 1 credit, 0.5 from cache. URLs that
        fail are listed in `failed` and cost nothing. The response is `200` even when every
        URL failed. Highlights are ranked with BM25 (lexical, no model).

        **AI:** `summary: true` adds a 3–6 sentence summary of each page (+4 credits per
        page); `output_schema` (a JSON Schema, at most 16 KB, optionally guided by
        `prompt`) returns each page's data as JSON in `output` (+4 credits per page).
        Claude Haiku writes both; a schema whose fields are all booleans or enums is
        answered by a decision model instead (always valid against the schema). A
        summary or extraction that fails is reported in `summary_error` /
        `output_error` and not charged. With either, `timeout` defaults to 75 seconds
        and the last 25 are kept for the model.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ExtractRequest" }
            example: { urls: ["https://example.com/pricing", "https://example.com/docs/limits.pdf"], query: "enterprise price", highlights: 2 }
      responses:
        "200": { $ref: "#/components/responses/ExtractOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/map:
    post:
      summary: The URLs of a site, from robots.txt sitemaps and the start page's links, optionally ranked by a search (1 credit; free when nothing is found)
      operationId: map
      description: |
        Reads the sitemaps listed in robots.txt (or `/sitemap.xml`), following sitemap
        indexes; XML, gzip, RSS/Atom and plain-text sitemaps are understood. URLs are
        cleaned (fragment and tracking parameters such as `utm_*`, `gclid` and `fbclid`
        dropped), kept on the site, filtered by `include_paths` / `exclude_paths` and
        de-duplicated (`www.`, scheme and trailing slash folded). `search` ranks the URLs
        by their path words and titles (BM25) and drops the ones that don't match. Takes
        at most about 30 seconds.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/MapRequest" }
            example: { url: "https://docs.example.com/", search: "install guide", limit: 50 }
      responses:
        "200": { $ref: "#/components/responses/MapOK" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/crawl:
    post:
      summary: Start an async crawl of one site (1 credit per page read; `limit` credits reserved up front, the rest refunded)
      operationId: createCrawl
      description: |
        From `url` and (unless `sitemap: skip`) the site's sitemaps, same host (optionally
        subdomains), up to `limit` pages and `max_depth` link hops, filtered by
        `include_paths` / `exclude_paths` (regular expressions matched against the URL
        path). Breadth first, or best first with `query` (pages whose URL and link text
        match it are read first). Each host's robots.txt is honoured (RFC 9309: rules,
        `Crawl-delay`; a robots.txt that answers 5xx stops the crawl at the start page).
        URLs are canonicalised (fragments and tracking parameters dropped, `www.`,
        trailing slashes and redirects folded) so each page is read once. Each page comes
        back as Markdown (or text) with its metadata. A crawl runs for at most 30 minutes
        and returns up to 16 MB of pages; `result.stats.stopped` says why it ended.

        Returns `202` with a task; poll `GET /v1/crawl/{id}` or wait for the signed
        `crawl.completed` webhook. Pages read cost 1 credit each (0.5 from cache); a crawl
        that read nothing fails (`no_pages`) and is refunded. At most 20 crawls per account
        may be queued or running at once (`429`); a crawl interrupted by a deploy restarts
        from the beginning.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/CrawlRequest" }
            example: { url: "https://docs.example.com/", limit: 50, max_depth: 2, include_paths: ["^/guides/"] }
      responses:
        "202": { $ref: "#/components/responses/TaskAccepted" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/crawl/{id}:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    get:
      summary: Poll a crawl (kept for 24 hours)
      operationId: getCrawl
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CrawlTask" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
    delete:
      summary: Cancel a crawl. A queued crawl is canceled and refunded at once; a running one stops at its next checkpoint and is charged for the pages read
      description: "`404` when there is no such crawl, `409` when it already finished."
      operationId: cancelCrawl
      responses:
        "200": { $ref: "#/components/responses/TaskCanceled" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }

  /v1/answer:
    post:
      summary: A cited answer grounded on live Google results, written by Claude (fast = 1 + 2 credits; standard = 1 + 1 per page read + 4)
      operationId: answer
      description: |
        Runs the query on Google, then Claude (Haiku by default) writes a concise answer
        that cites the numbered `results` with `[n]` markers. `depth=fast` answers from
        the result page (snippets, answer box, knowledge panel); `depth=standard`
        (default) also reads the top `num_sources` pages and answers from their
        query-ranked passages. Sources are untrusted: instructions inside pages are
        ignored.

        **Billing:** the search part is priced like `/v1/search` with `include_content`
        (1 credit + 1 per page read, cache rules as usual); the model adds 2 credits at
        `fast` and 4 when it read pages (`standard`; 2 if no page could be read).
        `meta.credits` splits the two. When the model fails the answer part is refunded
        (`503 ai_unavailable`); a search that returned nothing to answer from is answered
        with `answer: null`, a warning, and no model charge.

        **Structured output:** with `output_schema` (a JSON Schema, at most 16 KB) the
        answer is a JSON value in `output` (and `answer` is null). Can't be combined
        with `stream`.

        **Streaming:** `stream: true` returns `text/event-stream` with these events, in
        order: `results` (`{request, results}`), `delta` (`{text}`, repeated), then
        `done` (`{answer, citations, meta}`) or `error` (`{error}`). Billing headers on a
        stream carry the search part only; the final `meta` has the total.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/AnswerRequest" }
            example: { q: "what is retrieval-augmented generation", depth: standard, num_sources: 3 }
      responses:
        "200":
          description: OK (`text/event-stream` when `stream` is true)
          headers:
            X-Credits-Used: { $ref: "#/components/headers/CreditsUsed" }
            X-Credits-Remaining: { $ref: "#/components/headers/CreditsRemaining" }
            X-Cost-USD: { $ref: "#/components/headers/CostUSD" }
            X-Cache: { $ref: "#/components/headers/Cache" }
            X-Latency-Ms: { $ref: "#/components/headers/LatencyMs" }
            X-Tokens-Estimate: { $ref: "#/components/headers/TokensEstimate" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AnswerResponse" }
              example:
                request: { endpoint: answer, engine: google, q: "what is retrieval-augmented generation", country: us, language: en, num: 10, page: 1, autocorrect: true, device: desktop, include_content: 3, depth: standard, num_sources: 3 }
                answer: "Retrieval-augmented generation (RAG) grounds a language model's answer in documents retrieved at query time [1], which reduces hallucinations and keeps answers current [2]."
                citations:
                  - { index: 1, title: "Retrieval-augmented generation", link: "https://en.wikipedia.org/wiki/Retrieval-augmented_generation", domain: en.wikipedia.org }
                  - { index: 2, title: "What is RAG?", link: "https://www.ibm.com/think/topics/retrieval-augmented-generation", domain: ibm.com }
                results:
                  - { index: 1, title: "Retrieval-augmented generation", link: "https://en.wikipedia.org/wiki/Retrieval-augmented_generation", domain: en.wikipedia.org }
                  - { index: 2, title: "What is RAG?", link: "https://www.ibm.com/think/topics/retrieval-augmented-generation", domain: ibm.com }
                meta:
                  request_id: req_01J9
                  credits_used: 6
                  credits: { search: 4, answer: 2 }
                  cached: false
                  engine: google
                  latency_ms: 4410
                  llm: { provider: anthropic, model: claude-haiku-5-5, input_tokens: 3120, output_tokens: 88 }
            text/event-stream:
              schema:
                type: string
                description: |
                  Server-Sent Events. Each event is `event: <name>\ndata: <JSON>\n\n`:
                  `results` → AnswerStreamResults, `delta` → AnswerStreamDelta,
                  `done` → AnswerStreamDone, `error` → Error.
              example: |
                event: results
                data: {"request":{"endpoint":"answer","q":"what is retrieval-augmented generation"},"results":[{"index":1,"title":"Retrieval-augmented generation","link":"https://en.wikipedia.org/wiki/Retrieval-augmented_generation","domain":"en.wikipedia.org"}]}

                event: delta
                data: {"text":"Retrieval-augmented generation grounds "}

                event: done
                data: {"answer":"Retrieval-augmented generation grounds a model's answer in documents retrieved at query time [1].","citations":[{"index":1,"title":"Retrieval-augmented generation","link":"https://en.wikipedia.org/wiki/Retrieval-augmented_generation","domain":"en.wikipedia.org"}],"meta":{"request_id":"req_01J9","credits_used":3,"cached":false}}
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/research:
    post:
      summary: Start an async deep-research task — planned searches, page reading, a cited Markdown report written by Claude (lite 30, standard 75, deep 200 credits)
      operationId: createResearch
      description: |
        Claude plans Google queries for `input`, the pages they find are read and
        ranked, a decision model checks whether the notes already cover the task (and
        drops off-topic sources), Claude reviews gaps and plans follow-up rounds, then
        writes a Markdown report citing numbered sources (and, with `output_schema`, a
        JSON value in `output`).

        | effort | credits | first-round queries | rounds | pages per query |
        |---|---:|---:|---:|---:|
        | lite | 30 | 3 | 1 | 2 |
        | standard | 75 | 5 | 2 | 3 |
        | deep | 200 | 8 | 3 | 4 |

        The flat price is reserved at enqueue and charged only when the report is
        written; failed research is refunded. A canceled task is charged 1 credit per
        search already run. Returns `202`; poll `GET /v1/research/{id}` or wait for the
        signed `research.completed` webhook. At most 20 crawl and research tasks per
        account may be queued or running at once (`429`).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ResearchRequest" }
            example: { input: "compare espresso machines under $500 for a small office", effort: standard, output_schema: { type: object, properties: { winner: { type: string } } } }
      responses:
        "202": { $ref: "#/components/responses/TaskAccepted" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }
  /v1/research/{id}:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    get:
      summary: Poll a research task (kept for 24 hours)
      operationId: getResearch
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ResearchTask" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
    delete:
      summary: Cancel a research task. A queued task is refunded at once; a running one stops at its next round and is charged for the searches run
      description: "`404` when there is no such task, `409` when it already finished."
      operationId: cancelResearch
      responses:
        "200": { $ref: "#/components/responses/TaskCanceled" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }

  /v1/monitors:
    post:
      summary: Create a monitor — a saved /v1/search or /v1/news request (new results) or a /v1/webpage URL (content changes) that runs on a schedule and reports what is new (signed webhook and run history)
      operationId: createMonitor
      description: |
        Runs hourly to monthly (`interval` or `interval_seconds`, default daily); the
        first run is due right away (unless `active: false`). With `endpoint: webpage`
        the monitor watches `url` and reports the page (Markdown, `change: new|changed`)
        whenever its content changes (1 credit per check). Each run is billed like the
        search it makes (1 credit per 10 results, `num: 100` is 7; empty and failed runs
        are free) on the monitor's key: the key that created it, or last changed or ran
        it, under that key's limits and the account's spend cap. Only the fields below
        are kept; any other search field is a `400`. Results among the
        top `num` not seen in earlier runs are POSTed as a `monitor.results` webhook when
        the monitor has a `webhook_url`, and are always listed in its run history
        (`GET /v1/monitors/{id}/runs`, results kept 24 hours). At most 100 monitors per
        account (403 `forbidden`). A monitor pauses itself after 10 failed runs in a row
        (search errors, insufficient credits or webhook failures) or when its key is
        revoked; set `active: true` to resume.

        With an AI assistant `endpoint` (chatgpt, gemini, copilot, ai_mode,
        brave_ai) the monitor asks `prompt` every run and reports every answer
        (AI visibility is tracked over time): `text`, `markdown`, `sources`,
        `new_sources` (links not seen in earlier runs), `search_queries`,
        `products` and, with `track`, `mentions`. Each run costs the endpoint's
        price.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/MonitorCreateRequest" }
            example: { q: "ai agents", endpoint: news, interval: hourly, name: "agents news", webhook_url: "https://example.com/hooks/serpkite" }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Monitor" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
    get:
      summary: List the account's monitors
      operationId: listMonitors
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/MonitorList" }
        "401": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/monitors/{id}:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    get:
      summary: Get a monitor
      operationId: getMonitor
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Monitor" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
    patch:
      summary: "Update a monitor: name, interval, webhook_url (empty string removes it), active, and the saved search (endpoint, q and search options; a changed search starts a new baseline)"
      operationId: updateMonitor
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/MonitorUpdateRequest" }
            example: { active: false, interval: daily }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Monitor" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
    delete:
      summary: Delete a monitor
      operationId: deleteMonitor
      responses:
        "204": { description: Deleted }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/monitors/{id}/runs:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 20 } }
      - { name: before, in: query, description: "`next_before` of the previous page", schema: { type: string, format: uuid } }
    get:
      summary: A monitor's run history, newest first (runs are kept 30 days, their results 24 hours)
      operationId: listMonitorRuns
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/MonitorRunList" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/monitors/{id}/run:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    post:
      summary: Run a monitor now (it becomes due at the next scheduler poll, within about 30 seconds)
      description: |
        The monitor must be active. A paused monitor returns 409; resume it with
        PATCH {"active": true} first (resuming also makes it due immediately).
        The monitor is bound to the calling key, which this and later runs are billed to.
      operationId: runMonitor
      responses:
        "202":
          description: Scheduled
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Monitor" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }

  /customsearch/v1:
    get:
      summary: Google Custom Search JSON API–compatible endpoint (for apps moving off CSE)
      operationId: customSearch
      description: |
        Takes the Custom Search JSON API's parameters and answers in its `customsearch#search` shape,
        always from Google. Result indexes follow Google's pages (result `i` is on page `(i-1)/10+1`);
        a `start`/`num` window that spans two pages reads both and is billed for both. Query-shaping
        parameters (`exactTerms`, `excludeTerms`, `orTerms`, `hq`, `fileType`, `lowRange`/`highRange`,
        `siteSearch`) become operators in Google's query, as the API documents them. Accepted and
        ignored: `cx`, `c2coff`, `googlehost`, `filter`, `linkSite` (Google retired `link:`), `alt`,
        `fields`, `prettyPrint`, `quotaUser`, `callback`. Errors use Google's error body
        (`CSEError`), not the `/v1` one.
        `GET /customsearch/v1/siterestrict` (the API's Site Restricted variant) is served by the same
        handler.
      parameters:
        - { name: key, in: query, schema: { type: string }, description: API key (or Authorization Bearer) }
        - { name: cx, in: query, schema: { type: string }, description: Accepted and ignored }
        - { name: q, in: query, required: true, schema: { type: string } }
        - { name: start, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 1 }, description: "First result (1-based); start + num - 1 must be at most 100" }
        - { name: num, in: query, schema: { type: integer, minimum: 1, maximum: 10, default: 10 } }
        - { name: gl, in: query, schema: { type: string }, description: Country the search is made from }
        - { name: hl, in: query, schema: { type: string }, description: Interface language }
        - { name: lr, in: query, schema: { type: string, examples: [lang_de, "lang_de|lang_fr"] }, description: Only documents in these languages (Google's lr) }
        - { name: cr, in: query, schema: { type: string, examples: [countryDE] }, description: Only documents from these countries (Google's cr) }
        - { name: safe, in: query, schema: { type: string, enum: [active, off, high, medium] }, description: "high and medium are the API's retired levels and mean active" }
        - { name: dateRestrict, in: query, schema: { type: string, examples: [d7, w2, m6, y1] } }
        - { name: sort, in: query, schema: { type: string, examples: [date, "date:r:20240101:20241231"] }, description: "date (newest first) or date:r:YYYYMMDD:YYYYMMDD (a date range)" }
        - { name: exactTerms, in: query, schema: { type: string }, description: Phrase every result contains }
        - { name: excludeTerms, in: query, schema: { type: string }, description: Word or phrase no result contains }
        - { name: orTerms, in: query, schema: { type: string }, description: Space-separated terms of which each result contains at least one }
        - { name: hq, in: query, schema: { type: string }, description: Terms added to q }
        - { name: fileType, in: query, schema: { type: string, examples: [pdf] } }
        - { name: lowRange, in: query, schema: { type: string } }
        - { name: highRange, in: query, schema: { type: string } }
        - { name: siteSearch, in: query, schema: { type: string } }
        - { name: siteSearchFilter, in: query, schema: { type: string, enum: [e, i], default: i } }
        - { name: searchType, in: query, schema: { type: string, enum: [image] } }
        - { name: imgSize, in: query, schema: { type: string, enum: [icon, small, medium, large, xlarge, xxlarge, huge] }, description: "Images; Google's sizes are icon, medium and large" }
        - { name: imgType, in: query, schema: { type: string, enum: [clipart, face, lineart, stock, photo, animated] } }
        - { name: imgColorType, in: query, schema: { type: string, enum: [color, gray, mono, trans] } }
        - { name: imgDominantColor, in: query, schema: { type: string, enum: [black, blue, brown, gray, green, orange, pink, purple, red, teal, white, yellow] } }
        - { name: rights, in: query, schema: { type: string }, description: "Images; any cc_* value asks for Creative Commons licences" }
      responses:
        "200":
          description: CSE-shaped response
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CSEResponse" }
        "400": { $ref: "#/components/responses/CSEError" }
        "401": { $ref: "#/components/responses/CSEError" }
        "402": { $ref: "#/components/responses/CSEError" }
        "429": { $ref: "#/components/responses/CSEError" }
        "503": { $ref: "#/components/responses/CSEError" }

  /v1/rank:
    post:
      summary: Position of a domain for a keyword in the top N (default 100; priced like /v1/search depth, 7 credits for 100)
      operationId: rank
      description: |
        Reads the same results as `/v1/search` with that `num`. Google serves several variants of
        one results page, so a position can differ between calls, and a domain can be absent from
        one variant: `position: null` means absent from this page, not from Google. Average several
        checks to track a rank.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RankRequest" }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RankResponse" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }

  /v1/resolve:
    post:
      summary: Destinations of Google /goto links a response returned with `link_resolved false`. Free
      operationId: resolve
      description: |
        Google sometimes holds back where a result leads for longer than a request lasts. Such a
        result comes back with `link_resolved: false` and Google's `https://www.google.com/goto?url=…`
        redirect as its `link`. SerpKite goes on following that redirect for up to 2 minutes
        after Google's delay (usually 5-30 s), including after a live response. Send such links
        here to get their destinations; a `pending` link has `retry_after` seconds to wait.
        A link becomes `failed` when the continuation fails or exhausts its time budget.
        Batch jobs and monitor runs wait for those destinations themselves. Only links SerpKite returned in the last 24 hours are known; anything else is
        `unknown`. Not billed; counts toward the rate limit.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ResolveRequest" }
      responses:
        "200":
          description: OK
          headers:
            Retry-After:
              description: Seconds until the pending links are expected to settle (only when some are `pending`)
              schema: { type: integer }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ResolveResponse" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }

  /v1/status:
    get:
      summary: Public live status — requests, success rate, p50/p95 latency per endpoint over the last hour
      operationId: status
      security: []
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Status" }
  /v1/status/ai:
    get:
      summary: AI answer health for the watched (endpoint, country) pairs over the last 30 minutes; 503 while one is degraded
      operationId: statusAI
      description: |
        For uptime monitors. A pair is degraded when at least 4 requests in the
        window succeeded less than 80% of the time, or when 2 or more got no
        answer at all. A success is a 200 with an answer: empty answers and 5xx
        count as failures, while 4xx errors are the caller's and are left out.
        When customers are quiet, a canary asks each watched pair, so the
        figure stays current. Both 200 and 503 return the same body.
      security: []
      responses:
        "200":
          description: Every watched pair is operational
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AIStatus" }
        "503":
          description: A watched pair is degraded
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AIStatus" }

  /v1/batches:
    post:
      summary: Queue up to 100 requests for one endpoint at half price. Each request becomes one batch job
      operationId: createBatches
      description: |
        Credits for the whole batch are reserved together: if the balance, spend cap, key limit or
        free daily cap can't cover every valid request, none is queued and each gets the error
        (invalid requests get their own 400 entry either way). Each job is settled and refunded on
        its own once it runs. Half price applies to the search part; an AI surcharge
        (`include_answer`) is charged in full.

        **Retries.** Send an `Idempotency-Key` to make the call safe to retry: for 24 hours a
        repeat with the same key and the same body returns the first response (with
        `Idempotent-Replayed: true`) without queueing or billing again. The same key with a
        different body is rejected with 422 `idempotency_key_reused`; a repeat while the first
        call is still running gets 409.

        **Webhooks.** Every delivery is a `POST` with `X-SerpKite-Event: batch.completed`,
        `X-SerpKite-Delivery` (the job id), `X-SerpKite-Timestamp` (Unix seconds) and
        `X-SerpKite-Signature: v1=<hex HMAC-SHA256(secret, "<timestamp>.<raw body>")>`. Deliveries
        are always signed; the account's secret is created with its first webhook and revealed by
        rotating it (dashboard Settings → Webhooks). Verify by recomputing the HMAC over the raw
        body, comparing in constant time, and rejecting timestamps older than 5 minutes. The SDKs
        ship `verifyWebhook` / `verify_webhook` / `VerifyWebhook`.
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          description: 1-255 printable ASCII characters (e.g. a UUID). Retries with the same key and body replay the first response for 24 h
          schema: { type: string, minLength: 1, maxLength: 255 }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/BatchCreateRequest" }
      responses:
        "202":
          description: Queued. One entry per request, in order; an entry is a batch job or an error object
          headers:
            Idempotent-Replayed:
              description: "`true` when this is the stored response of an earlier call with the same Idempotency-Key"
              schema: { type: string, enum: ["true"] }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/BatchCreateResponse" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Unavailable" }

  /v1/batches/{id}:
    get:
      summary: Poll a batch job
      operationId: getBatch
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Batch" }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }

  /v1/account:
    get:
      summary: Balance, limits and this month's usage for the calling key's account
      operationId: account
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Account" }
        "401": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }

  /playground/search:
    post:
      summary: No-login demo of /v1/search (and news, images, autocomplete via `endpoint`). Per-IP rate limited (IPv6 per /64), not billed. Browser calls only from serpkite.com and app.serpkite.com
      operationId: playground
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/SearchRequest"
                - type: object
                  properties:
                    endpoint: { type: string, enum: [search, news, images, autocomplete], default: search }
                    turnstile_token: { type: string, description: "Cloudflare Turnstile token, required when the server enforces Turnstile. Single-use: get a fresh one for every request" }
      responses:
        "200":
          description: Same body as the corresponding endpoint
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        "400": { $ref: "#/components/responses/Error" }
        "403":
          description: Bot check failed (missing, spent or foreign Turnstile token) or the Origin is not one of our sites
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429": { $ref: "#/components/responses/Error" }

  /v1/mcp:
    post:
      summary: Remote MCP server (streamable HTTP, JSON-RPC 2.0). Tools search, news, maps, place, scholar, webpage
      operationId: mcp
      description: |
        Authenticates with an API key (`Authorization: Bearer skt_live_…`) or an
        OAuth 2.1 access token (`skt_oat_…`) issued by app-api.serpkite.com for
        this resource (MCP authorization spec). Without a valid credential the
        401 carries `WWW-Authenticate: Bearer resource_metadata="…/.well-known/oauth-protected-resource/v1/mcp", scope="mcp"`
        (plus `error="invalid_token"` when a credential was rejected). OAuth
        access tokens are only accepted here, not on the REST endpoints.
      security:
        - bearer: []
        - oauth: [mcp]
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, additionalProperties: true }
      responses:
        "200":
          description: JSON-RPC response
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
        "202": { description: Notification accepted }
        "401":
          description: Missing, invalid, expired or revoked credential
          headers:
            WWW-Authenticate:
              description: RFC 9728 challenge pointing at the protected resource metadata
              schema: { type: string }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
  /.well-known/oauth-protected-resource/v1/mcp:
    get:
      summary: OAuth protected resource metadata for the MCP server (RFC 9728)
      operationId: mcpProtectedResourceMetadata
      security: []
      responses:
        "200":
          description: Metadata
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ProtectedResourceMetadata" }
  /.well-known/oauth-protected-resource:
    get:
      summary: OAuth protected resource metadata (root form; same document)
      operationId: protectedResourceMetadata
      security: []
      responses:
        "200":
          description: Metadata
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ProtectedResourceMetadata" }

webhooks:
  crawl.completed:
    post:
      operationId: crawlCompletedWebhook
      summary: A crawl finished (completed, failed or canceled)
      description: |
        Sent to the crawl's `webhook_url` (or the account webhook). Signed like batch
        webhooks: `X-SerpKite-Event: crawl.completed`, `X-SerpKite-Delivery` (the task id),
        `X-SerpKite-Timestamp` and `X-SerpKite-Signature: v1=<hex HMAC-SHA256(secret,
        "<timestamp>.<raw body>")>`. Retried with backoff until a 2xx.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/TaskCompletedEvent" }
      responses:
        "200": { description: Any 2xx acknowledges the delivery }
  research.completed:
    post:
      operationId: researchCompletedWebhook
      summary: A research task finished (completed, failed or canceled)
      description: |
        Sent to the task's `webhook_url` (or the account webhook), signed like
        `crawl.completed` with `X-SerpKite-Event: research.completed`. `result` is the
        ResearchResult.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/TaskCompletedEvent" }
      responses:
        "200": { description: Any 2xx acknowledges the delivery }
  monitor.results:
    post:
      operationId: monitorResultsWebhook
      summary: A monitor run found results it had not seen before
      description: |
        Sent to the monitor's `webhook_url` (when it has one) only when a run finds new results (the first
        run sends everything it found, with `first_run: true`). Same signature headers as
        the other webhooks, with `X-SerpKite-Event: monitor.results` and
        `X-SerpKite-Delivery: <run id>`. Tried up to 3 times per run; results that could
        not be delivered stay new for the next run (and are in the run history either way).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/MonitorResultsEvent" }
      responses:
        "200": { description: Any 2xx acknowledges the delivery }

components:
  securitySchemes:
    bearer: { type: http, scheme: bearer }
    oauth:
      type: oauth2
      description: OAuth 2.1 for the remote MCP server only (authorization code + PKCE S256; app-api.serpkite.com is the authorization server).
      flows:
        authorizationCode:
          authorizationUrl: https://app-api.serpkite.com/oauth/authorize
          tokenUrl: https://app-api.serpkite.com/oauth/token
          refreshUrl: https://app-api.serpkite.com/oauth/token
          scopes:
            mcp: Use the SerpKite MCP tools, billed to your account
            offline_access: Stay connected with refresh tokens

  requestBodies:
    Search:
      required: true
      content:
        application/json:
          schema: { $ref: "#/components/schemas/SearchRequest" }

  headers:
    CreditsUsed: { schema: { type: number } }
    CreditsRemaining: { schema: { type: number } }
    CostUSD: { schema: { type: number } }
    Cache: { schema: { type: string, enum: [HIT, MISS] } }
    LatencyMs: { schema: { type: integer } }
    TokensEstimate: { schema: { type: integer } }
    RetryAfter:
      description: Seconds to wait before retrying
      schema: { type: integer }

  responses:
    Error:
      description: Error
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Unavailable:
      description: |
        Temporarily unavailable, not billed, safe to retry after `Retry-After`.
        Codes: `upstream_error` (the upstream page couldn't be fetched or parsed),
        `upstream_blocked` (the upstream is rate limiting us or refused the query), `upstream_timeout`
        (the search took too long), `unavailable` (endpoint or dependency down).
        The API never sends 502 or 504.
      headers:
        Retry-After: { $ref: "#/components/headers/RetryAfter" }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    CSEError:
      description: |
        Google's error body (`error.code` is the HTTP status, `errors[0].reason` Google's reason,
        `details[0].reason` the SerpKite error code). Not billed. A 503 carries `Retry-After`.
      headers:
        Retry-After: { $ref: "#/components/headers/RetryAfter" }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/CSEError" }
    TaskAccepted:
      description: Queued. Poll `poll_url` or wait for the webhook
      headers:
        X-Credits-Reserved: { description: "The maximum price, reserved until the task ends", schema: { type: number } }
        X-Credits-Remaining: { $ref: "#/components/headers/CreditsRemaining" }
        Location: { description: "Path of the task (`/v1/{kind}/{id}`)", schema: { type: string } }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/TaskCreated" }
          example: { id: "01926a3e-7b2c-7c4e-9f1a-2b3c4d5e6f70", kind: crawl, status: queued, created_at: "2026-10-03T12:00:00Z", poll_url: "https://api.serpkite.com/v1/crawl/01926a3e-7b2c-7c4e-9f1a-2b3c4d5e6f70", credits_reserved: 50, webhook_url: null }
    TaskCanceled:
      description: "`canceled` (it was queued: refunded at once) or `canceling` (it is running and stops at its next checkpoint)"
      content:
        application/json:
          schema: { $ref: "#/components/schemas/TaskCancelResponse" }
    SearchOK:
      description: OK (text/markdown when format=markdown)
      headers: &billingHeaders
        X-Credits-Used: { $ref: "#/components/headers/CreditsUsed" }
        X-Credits-Remaining: { $ref: "#/components/headers/CreditsRemaining" }
        X-Cost-USD: { $ref: "#/components/headers/CostUSD" }
        X-Cache: { $ref: "#/components/headers/Cache" }
        X-Latency-Ms: { $ref: "#/components/headers/LatencyMs" }
        X-Tokens-Estimate: { $ref: "#/components/headers/TokensEstimate" }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/SearchResponse" }
        text/markdown:
          schema: { type: string }
    ImagesOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ImagesResponse" }
        text/markdown:
          schema: { type: string }
    VideosOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/VideosResponse" }
        text/markdown:
          schema: { type: string }
    NewsOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/NewsResponse" }
        text/markdown:
          schema: { type: string }
    PlacesOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/PlacesResponse" }
        text/markdown:
          schema: { type: string }
    ReviewsOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ReviewsResponse" }
        text/markdown:
          schema: { type: string }
    ShoppingOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ShoppingResponse" }
        text/markdown:
          schema: { type: string }
    ScholarOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ScholarResponse" }
        text/markdown:
          schema: { type: string }
    PatentsOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/PatentsResponse" }
        text/markdown:
          schema: { type: string }
    AutocompleteOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/AutocompleteResponse" }
        text/markdown:
          schema: { type: string }
    ExtractOK:
      description: OK
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ExtractResponse" }
          example:
            request: { endpoint: extract, urls: ["https://example.com/pricing", "https://example.com/missing"], format: markdown, query: "enterprise price" }
            results:
              - url: "https://example.com/pricing"
                status_code: 200
                title: Pricing
                metadata: { title: Pricing, content_type: text/html }
                cached: false
                markdown: "# Pricing\n\n…"
                highlights: [{ text: "Enterprise: $499 per month …", score: 4.83, heading: "Plans" }]
            failed:
              - { url: "https://example.com/missing", error: { code: target_unavailable, message: "could not fetch the page: the site answered 404; you were not charged" } }
            meta: { request_id: req_01J9, credits_used: 1, latency_ms: 2210, succeeded: 1, failed: 1 }
    MapOK:
      description: OK
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/MapResponse" }
          example:
            request: { endpoint: map, url: "https://docs.example.com/", limit: 50, sitemap: include, include_subdomains: false, search: "install guide" }
            results:
              - { url: "https://docs.example.com/install", lastmod: "2026-09-01", source: sitemap }
              - { url: "https://docs.example.com/guide", title: Guide, source: page }
            meta: { request_id: req_01J9, credits_used: 1, latency_ms: 840, count: 2 }
    AssistantOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/AssistantResponse" }
        text/markdown:
          schema: { type: string }
    WebpageOK:
      description: OK (text/markdown when format=markdown)
      headers: *billingHeaders
      content:
        application/json:
          schema: { $ref: "#/components/schemas/WebpageResponse" }
        text/markdown:
          schema: { type: string }

  schemas:
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code:
              type: string
              description: "400: invalid_request; prompt_too_long (a /v1/brave_ai prompt over 400 characters or 50 words); unsupported_country (country ru on /v1/chatgpt and /v1/gemini). 403: spend_cap_reached, key_limit_reached, account_restricted, forbidden. 409/422: idempotency_key_reused. 422: target_unavailable (the URL you asked for failed: its site answered 404, its domain doesn't resolve; resending won't help), no_pages. 429: rate_limited, daily_limit_reached. 503: upstream_error, upstream_blocked, upstream_timeout, unavailable (the API never sends 502 or 504)"
              examples: [unauthorized, invalid_request, prompt_too_long, unsupported_country, insufficient_credits, rate_limited, daily_limit_reached, spend_cap_reached, key_limit_reached, account_restricted, idempotency_key_reused, forbidden, not_found, upstream_error, upstream_blocked, upstream_timeout, unavailable, internal]
            message: { type: string }
            request_id: { type: string }

    ProtectedResourceMetadata:
      type: object
      description: RFC 9728 protected resource metadata
      required: [resource, authorization_servers]
      properties:
        resource: { type: string, format: uri, examples: ["https://api.serpkite.com/v1/mcp"] }
        authorization_servers: { type: array, items: { type: string, format: uri }, examples: [["https://app-api.serpkite.com"]] }
        scopes_supported: { type: array, items: { type: string } }
        bearer_methods_supported: { type: array, items: { type: string } }
        resource_name: { type: string }
        resource_documentation: { type: string, format: uri }

    SearchRequest:
      type: object
      required: [q]
      properties:
        q: { type: string, minLength: 1, maxLength: 2048 }
        country: { type: string, default: us, description: "Country code (ISO 3166-1 alpha-2, case-insensitive; uk is accepted as gb). When omitted and location ends in a country name, that country is used. Russia (ru) is supported across all search verticals, including patents" }
        language: { type: string, default: en, description: "Interface language: a language code with an optional region (e.g. en, ru, de, pt-br, zh-tw, es-419). Russian (ru) is supported across all search verticals; language does not change the selected country. On patents, a non-English code restricts publication language (ar, zh, da, nl, fi, fr, de, it, ja, ko, no, pt, ru, es, sv)" }
        location: { type: string, description: 'Free-text location, e.g. "Austin, Texas, United States". Google, Brave (search, news, images, videos), Yandex web search and Yandex Maps apply it; Bing, DuckDuckGo, Yahoo, Mojeek and Wikipedia have no such setting and are skipped (a 400 when you named one), never answered for the wrong place, as is a place an engine can''t find. uule works the same way' }
        uule: { type: string, description: Pre-encoded Google location (overrides ll and location; percent-encoded values are decoded) }
        ll: { type: string, description: 'Map point "@lat,lng,14z" (maps and places only; zoom optional, default 14z): the map is searched around that point at that zoom, wherever the request comes from. Overrides location' }
        num: { type: integer, default: 10, minimum: 1, maximum: 100, description: "1–100. Up to 10 returns one page (10 results, 1 credit; trim it yourself for fewer). Above 10 on search and news is the depth bundle (7 credits for 100; values between round up to whole pages). On images a page is a block of up to 100 images (1 credit) and num (default 100) is how many of them to return; `page` moves to the next block. Other verticals return one page as the engine serves it: up to 10 on Google (shopping cards come 40-55 to a page, and Brave and DuckDuckGo news and videos up to about 60), for 1 credit. Trim it yourself" }
        page: { type: integer, default: 1, minimum: 1, maximum: 10 }
        time: { type: string, enum: [hour, day, week, month, year], description: "Only results from the last hour/day/… (search, news, images, videos, shopping). A fallback engine without that window is skipped, never answered unfiltered" }
        tbs: { type: string, description: "Advanced: raw Google tbs filter (e.g. qdr:d, qdr:w2, cdr:1,cd_min:1/1/2026,cd_max:1/31/2026); overrides time" }
        device: { type: string, enum: [desktop, mobile], default: desktop }
        safe: { type: string, enum: [active, off], default: off }
        autocorrect: { type: boolean, default: true }
        format: { type: string, enum: [json, markdown, compact], default: json }
        fields: { type: string, description: 'Comma-separated projection, e.g. "results.title,results.link,knowledge_graph"' }
        include_content: { type: integer, minimum: 0, maximum: 5, default: 0, description: Also fetch the top N organic pages as Markdown (+1 credit each fetched page) }
        ads: { type: boolean, default: false, description: Include sponsored results }
        max_age: { type: integer, minimum: 0, description: Accept a cached result up to this many seconds old (50% of credits on a hit) }
        engine: { $ref: "#/components/schemas/EngineParam" }
        include_domains:
          $ref: "#/components/schemas/DomainList"
          description: "Only results from these domains (search, news, images, videos). Compiled into site: operators and enforced on the results. With engine=consensus, every provider gets the operators and only providers with a remaining result are billed"
        exclude_domains:
          $ref: "#/components/schemas/DomainList"
          description: "Drop results from these domains (search, news, images, videos)"
        boost_domains:
          $ref: "#/components/schemas/DomainList"
          description: Move results from these domains to the top, keeping the order within both groups (search, news)
        start_date: { type: string, format: date, description: "Only results published on or after this date, YYYY-MM-DD (search, news, images, videos). Can't be combined with time or tbs. A fallback engine without date ranges is skipped" }
        end_date: { type: string, format: date, description: "Only results published on or before this date, YYYY-MM-DD. Can't be combined with time or tbs" }
        include_images: { type: boolean, default: false, description: "Shopping only: `image_url` is a `data:` thumbnail (5-20 KB) on the cards where Google inlines one instead of an image URL, usually the first of a page. Off by default, because it adds up to a few hundred KB to a response" }
        highlights: { type: boolean, default: false, description: "Return up to 3 query-ranked passages (`highlights`) of each page read by include_content instead of the whole page (search only; needs include_content; no extra credits)" }
        include_answer: { type: boolean, default: false, description: "Add a cited AI `answer` written by Claude over this response's results (search and news; +2 credits, +4 when it read pages via `include_content`; refunded with a `meta.warnings` entry when the model fails)" }

    DomainList:
      description: >-
        Domains as an array or a comma-separated string, at most 20: a host (`example.com`, subdomains
        match), a host with a path prefix (`github.com/org`) or a TLD (`.gov`).
      oneOf:
        - type: string
          examples: ["github.com,en.wikipedia.org"]
        - type: array
          maxItems: 20
          items: { type: string }
          examples: [["github.com/serpkite", ".gov"]]

    Highlight:
      type: object
      description: A query-relevant passage of a page, verbatim
      required: [text, score]
      properties:
        text: { type: string }
        score: { type: number, description: Relevance to the query (BM25; higher is better, comparable within one response) }
        heading: { type: string, description: The section heading path the passage sits under }

    ReviewsRequest:
      type: object
      description: One of place_id, cid or fid is required
      properties:
        place_id: { type: string }
        cid: { type: string }
        fid: { type: string }
        country: { type: string }
        language: { type: string }
        sort:
          type: string
          enum: [most_relevant, newest, highest_rating, lowest_rating]
          default: most_relevant
          description: >-
            Only `most_relevant` is served: Google Maps shows other review orders only to signed-in visitors,
            so `newest`, `highest_rating` and `lowest_rating` return 400 (not charged).
        page_token:
          type: string
          description: >-
            `next_page_token` from the previous page, unchanged. Opaque and bound to the place and `sort`
            it was issued for (anything else is a 400). Paging reaches the first 10 reviews of a place at
            most, and usually the first 5, all Google Maps shows a logged-out visitor.
        num: { type: integer, default: 10, maximum: 50, description: "Reviews per page; a page holds at most 10 (the first 10 reviews of a place). A page can be shorter when Google stops loading early; `next_page_token` then resumes after it" }
        format: { type: string, enum: [json, markdown, compact] }
        fields: { type: string }
        max_age: { type: integer }

    PlaceRequest:
      type: object
      description: >-
        One of place_id, cid or fid (Google; place_id wins, then fid, then cid) or oid (Yandex Maps)
        is required
      properties:
        place_id: { type: string, description: 'Google place id ("ChIJ…"), e.g. `place_id` of a /v1/maps result' }
        cid: { type: string, description: Decimal customer id (`cid` of a result) }
        fid: { type: string, description: 'Feature id "0x…:0x…" (`fid` of a result)' }
        oid:
          type: string
          pattern: "^[0-9]{1,20}$"
          examples: ["1045821788"]
          description: >-
            Yandex Maps organisation id (`oid` of an `engine=yandex` maps result). Implies
            `engine=yandex`; not with place_id, cid or fid
        country: { type: string, default: us, description: "Country code (ISO 3166-1 alpha-2); Google's regional view of the listing" }
        language: { type: string, default: en, description: "Language of the address, categories, hours and description (e.g. en, ru, de)" }
        format: { type: string, enum: [json, markdown, compact], default: json }
        fields: { type: string }
        max_age: { type: integer, minimum: 0, description: Accept a cached result up to this many seconds old (50% of credits on a hit) }
        engine: { $ref: "#/components/schemas/EngineParam" }

    AssistantRequest:
      type: object
      required: [prompt]
      properties:
        prompt: { type: string, minLength: 1, maxLength: 4000, description: The message to the assistant }
        country: { type: string, description: "Ask from this country (ISO 3166-1 alpha-2): answers, prices and shops follow it" }
        language: { type: string, description: "Interface language (e.g. en, de); the answer follows the prompt's language" }
        location: { type: string, maxLength: 256, description: 'ai_mode and brave_ai only (400 on gemini and copilot): the place the answer is for, e.g. "Austin, Texas, United States", so local prompts ("best pizza near me") answer for it. country defaults to its country. Use the "City, Region, Country" form: brave_ai answers a place it can''t find with a 400 (free); AI Mode answers for our exit''s area when Google doesn''t know the name' }
        uule: { type: string, maxLength: 512, description: "ai_mode and brave_ai only: Google's encoded location, used like location" }
        track: { $ref: "#/components/schemas/TrackList" }
        include_html: { type: boolean, default: false, description: "Also return the answer page's HTML (`html`)" }
        format: { type: string, enum: [json, markdown, compact], default: json }
        fields: { type: string }
        max_age: { type: integer, minimum: 0, maximum: 2592000, description: "Accept a cached answer up to this many seconds old (half price); answers are cached for at most an hour" }
        timeout_ms: { type: integer, minimum: 5000, maximum: 90000, description: "Give up after this many milliseconds (default 90000): the request then fails with 503 `upstream_timeout` and costs nothing, so an answer that arrives after your client stopped waiting is not billed. Set it about a second under your client's timeout" }
    ChatGPTRequest:
      type: object
      required: [prompt]
      properties:
        prompt: { type: string, minLength: 1, maxLength: 4000, description: The message to ChatGPT }
        web_search: { type: boolean, default: true, description: "Make ChatGPT search the web; false lets it decide (it then searches for about two thirds of shopping and local prompts)" }
        country: { type: string, description: "Ask as a visitor in this country (ISO 3166-1 alpha-2). Without it the visitor is usually in the US or EU" }
        track: { $ref: "#/components/schemas/TrackList" }
        include_html: { type: boolean, default: false }
        format: { type: string, enum: [json, markdown, compact], default: json }
        fields: { type: string }
        max_age: { type: integer, minimum: 0, maximum: 2592000 }
        timeout_ms: { type: integer, minimum: 5000, maximum: 90000, description: "Give up after this many milliseconds (default 90000): the request then fails with 503 `upstream_timeout` and costs nothing, so an answer that arrives after your client stopped waiting is not billed. Set it about a second under your client's timeout" }
    TrackList:
      type: array
      maxItems: 20
      items: { type: string, maxLength: 100 }
      description: "Brands (\"Acme\") and domains (\"acme.com\", subdomains match) to check the answer for; each comes back in `mentions`"
    AISource:
      type: object
      required: [position, link, domain, cited]
      properties:
        position: { type: integer, description: "The number the answer cites it with ([n] in markdown)" }
        title: { type: string }
        link: { type: string }
        domain: { type: string }
        snippet: { type: string }
        date: { type: string }
        cited: { type: boolean, description: "Cited inline in the answer (false: only listed beside it)" }
    AIProduct:
      type: object
      required: [position, title]
      properties:
        position: { type: integer }
        title: { type: string }
        brand: { type: string }
        price: { type: string, description: As shown, e.g. "€69.90" }
        extracted_price: { type: number }
        currency: { type: string, description: ISO 4217 when the symbol is unambiguous }
        rating: { type: number }
        reviews: { type: integer }
        merchant: { type: string }
        link: { type: string }
        image: { type: string }
        description: { type: string }
        sponsored: { type: boolean, description: A paid placement (an ad card shown with the answer) }
    Mention:
      type: object
      required: [term, mentioned, cited, sources, text_position]
      properties:
        term: { type: string }
        mentioned: { type: boolean, description: "The answer text names it (a domain: names the domain)" }
        cited: { type: boolean, description: A cited source matches it }
        sources: { type: array, items: { type: integer }, description: Positions of the matching sources }
        products: { type: array, items: { type: integer }, description: Positions of the matching products }
        text_position: { type: number, description: "Where the text first names it, 0 (start) to 1 (end); -1 when it doesn't" }
    AssistantEcho:
      type: object
      description: The normalised request of an AI assistant endpoint (the path names the assistant, so there is no engine)
      required: [endpoint, prompt]
      properties:
        endpoint: { type: string, examples: [chatgpt, gemini] }
        prompt: { type: string }
        country: { type: string }
        language: { type: string, description: Not on chatgpt }
        location: { type: string, description: ai_mode and brave_ai only }
        uule: { type: string, description: ai_mode and brave_ai only }
        web_search: { type: boolean, description: chatgpt only }
        include_html: { type: boolean }
    AssistantResponse:
      type: object
      required: [request, text, markdown, sources, search_queries, products, meta]
      properties:
        request: { $ref: "#/components/schemas/AssistantEcho" }
        text: { type: string, description: The answer as plain text }
        markdown: { type: string, description: "The answer as Markdown, citations as [n](link) matching sources[].position" }
        html: { type: string, description: Only with include_html=true }
        model: { type: string, description: "The model the assistant reports, when it does (e.g. ChatGPT's guest model)" }
        sources: { type: array, items: { $ref: "#/components/schemas/AISource" } }
        search_queries: { type: array, items: { type: string }, description: The searches the assistant ran (fan-out) where it shows them }
        products: { type: array, items: { $ref: "#/components/schemas/AIProduct" } }
        places: { type: array, items: { $ref: "#/components/schemas/PlaceResult" }, description: Local businesses the answer showed }
        related_questions: { type: array, items: { type: string } }
        mentions: { type: array, items: { $ref: "#/components/schemas/Mention" }, description: With track only }
        meta: { $ref: "#/components/schemas/Meta" }
    AIOverview:
      type: object
      required: [text, markdown, sources]
      properties:
        text: { type: string }
        markdown: { type: string, description: "Citations as [n](link) matching sources[].position" }
        sources: { type: array, items: { $ref: "#/components/schemas/AISource" } }

    WebpageRequest:
      type: object
      required: [url]
      properties:
        url: { type: string, format: uri, description: An HTML page or a PDF }
        format: { type: string, enum: [json, markdown, compact], default: json }
        include_html: { type: boolean, default: false }
        include_links: { type: boolean, default: false, description: "Also return the page's outbound links (`links`)" }
        include_images: { type: boolean, default: false, description: "Also return the page's image URLs (`image_links`)" }
        country: { type: string, description: "Fetch the page as seen from this country (ISO 3166-1 alpha-2) for geo-dependent pages" }
        max_age: { type: integer }

    ExtractRequest:
      type: object
      required: [urls]
      properties:
        urls: { type: array, items: { type: string, format: uri }, minItems: 1, maxItems: 20, description: "HTML pages or PDFs (duplicates are dropped)" }
        format: { type: string, enum: [markdown, text, html], default: markdown }
        query: { type: string, maxLength: 4096, description: What highlights are ranked against }
        highlights: { type: integer, minimum: 0, maximum: 10, default: 0, description: "Query-ranked passages per page (BM25; needs query)" }
        max_tokens: { type: integer, minimum: 100, maximum: 100000, description: Trim each page's markdown or text to about this many tokens }
        include_links: { type: boolean, default: false }
        include_images: { type: boolean, default: false }
        max_age: { type: integer, minimum: 0, maximum: 2592000, description: Accept a cached page up to this many seconds old (0.5 credit) }
        country: { type: string, description: Fetch the pages as seen from this country (ISO 3166-1 alpha-2) }
        timeout: { type: integer, minimum: 1, maximum: 90, default: 50, description: "Seconds to wait for the pages; a page still loading is listed in `failed` (`upstream_timeout`, not charged). Default 75 with summary or output_schema" }
        summary: { type: boolean, default: false, description: "Add a 3-6 sentence AI summary of each page (+4 credits per page; focused on `query` when set)" }
        output_schema:
          type: object
          additionalProperties: true
          description: "A JSON Schema (at most 16 KB): each page's data is returned as JSON matching it in `output` (+4 credits per page)"
        prompt: { type: string, maxLength: 4096, description: "Guides output_schema extraction (what to pick, how to normalise); needs output_schema" }

    ExtractResult:
      type: object
      required: [url, cached]
      properties:
        url: { type: string, description: Final URL after redirects }
        status_code: { type: integer }
        title: { type: string }
        published_at: { type: string, description: "The page's published time as ISO 8601, when it has one" }
        metadata: { $ref: "#/components/schemas/PageMetadata" }
        cached: { type: boolean }
        markdown: { type: string, description: format=markdown }
        text: { type: string, description: format=text }
        html: { type: [string, "null"], description: "format=html (null for a PDF); at most 2 MiB per page" }
        links: { type: array, items: { $ref: "#/components/schemas/PageLink" }, description: include_links=true only }
        images: { type: array, items: { type: string }, description: include_images=true only }
        highlights: { type: array, items: { $ref: "#/components/schemas/Highlight" }, description: highlights > 0 only }
        summary: { type: [string, "null"], description: "summary=true only (null when it failed)" }
        summary_error: { type: string }
        output: { description: "output_schema only: the JSON value matching the schema (null when it failed)" }
        output_error: { type: string }

    ExtractFailure:
      type: object
      required: [url, error]
      properties:
        url: { type: string }
        error:
          type: object
          required: [code, message]
          properties:
            code: { type: string, examples: [invalid_request, upstream_error, upstream_timeout, empty_page] }
            message: { type: string }

    ExtractResponse:
      type: object
      required: [request, results, failed, meta]
      properties:
        request:
          type: object
          additionalProperties: true
          properties:
            endpoint: { type: string, const: extract }
            urls: { type: array, items: { type: string } }
            format: { type: string }
            query: { type: string }
        results: { type: array, items: { $ref: "#/components/schemas/ExtractResult" } }
        failed: { type: array, items: { $ref: "#/components/schemas/ExtractFailure" } }
        meta:
          type: object
          required: [request_id, credits_used, succeeded, failed]
          properties:
            request_id: { type: string }
            credits_used: { type: number }
            latency_ms: { type: integer }
            succeeded: { type: integer }
            failed: { type: integer }
            llm: { $ref: "#/components/schemas/LLMUsage" }

    AnswerRequest:
      type: object
      required: [q]
      properties:
        q: { type: string, minLength: 1, maxLength: 2048 }
        depth:
          type: string
          enum: [fast, standard]
          default: standard
          description: "`fast` answers from the result page (1 + 2 credits); `standard` also reads the top `num_sources` pages (1 + 1 per page + 4 credits)"
        num_sources: { type: integer, minimum: 1, maximum: 5, default: 3, description: Pages read (depth=standard only) }
        stream: { type: boolean, default: false, description: "Send Server-Sent Events (`results`, `delta`…, `done` | `error`) instead of one JSON body" }
        output_schema:
          type: object
          additionalProperties: true
          description: A JSON Schema (at most 16 KB). The answer becomes a JSON value in `output`. Not with stream
        country: { type: string, default: us }
        language: { type: string, default: en }
        location: { type: string }
        uule: { type: string }
        time: { type: string, enum: [hour, day, week, month, year] }
        tbs: { type: string }
        device: { type: string, enum: [desktop, mobile], default: desktop }
        safe: { type: string, enum: [active, off], default: off }
        autocorrect: { type: boolean, default: true }
        max_age: { type: integer, minimum: 0, description: Accept a cached search up to this many seconds old }
        engine: { $ref: "#/components/schemas/EngineParam" }
        include_domains: { $ref: "#/components/schemas/DomainList" }
        exclude_domains: { $ref: "#/components/schemas/DomainList" }
        boost_domains: { $ref: "#/components/schemas/DomainList" }
        start_date: { type: string, format: date }
        end_date: { type: string, format: date }

    AnswerSource:
      type: object
      description: A result the answer may cite, numbered as in the prompt (`[index]`)
      required: [index, title, link]
      properties:
        index: { type: integer }
        title: { type: string }
        link: { type: string }
        domain: { type: string }
        date: { type: string, description: "Publish date (ISO 8601 when known, else as shown)" }

    AnswerMeta:
      allOf:
        - $ref: "#/components/schemas/Meta"
        - type: object
          properties:
            credits:
              type: object
              description: "`credits_used` split into the search and the model part"
              properties:
                search: { type: number }
                answer: { type: number }

    AnswerResponse:
      type: object
      required: [request, answer, citations, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        answer: { type: [string, "null"], description: "Markdown with `[n]` citation markers. Null with output_schema, or when there was nothing to answer from" }
        output: { description: "output_schema only: the JSON value matching the schema" }
        citations: { type: array, items: { $ref: "#/components/schemas/Citation" }, description: "The sources the answer cites, in first-cited order" }
        results: { type: array, items: { $ref: "#/components/schemas/AnswerSource" } }
        meta: { $ref: "#/components/schemas/AnswerMeta" }

    AnswerStreamResults:
      type: object
      description: "`event: results`, sent first"
      required: [request, results]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/AnswerSource" } }

    AnswerStreamDelta:
      type: object
      description: "`event: delta`: the next piece of answer text"
      required: [text]
      properties:
        text: { type: string }

    AnswerStreamDone:
      type: object
      description: "`event: done`, sent last: the final answer (citation markers checked) and meta with the total credits"
      required: [answer, citations, meta]
      properties:
        answer: { type: string }
        citations: { type: array, items: { $ref: "#/components/schemas/Citation" } }
        meta: { $ref: "#/components/schemas/AnswerMeta" }

    ResearchRequest:
      type: object
      required: [input]
      properties:
        input: { type: string, minLength: 1, maxLength: 8000, description: "The research task in plain words (`q` is accepted as an alias)" }
        effort: { type: string, enum: [lite, standard, deep], default: standard, description: "lite = 30, standard = 75, deep = 200 credits" }
        output_schema:
          type: object
          additionalProperties: true
          description: A JSON Schema (at most 16 KB); the report is also returned as a JSON value in `result.output`
        country: { type: string }
        language: { type: string }
        location: { type: string, maxLength: 256, description: 'Place the searches are for, e.g. "Austin, Texas, United States" (as on /v1/search)' }
        include_domains: { type: array, items: { type: string }, maxItems: 20 }
        exclude_domains: { type: array, items: { type: string }, maxItems: 20 }
        webhook_url: { type: string, format: uri, description: "Receives the signed `research.completed` event. Defaults to the account webhook" }

    ResearchSource:
      type: object
      required: [index, title, link]
      properties:
        index: { type: integer }
        title: { type: string }
        link: { type: string }
        domain: { type: string }
        published_at: { type: string }
        query: { type: string, description: The query that found it }

    ResearchResult:
      type: object
      required: [input, effort, report, citations, sources, queries]
      properties:
        input: { type: string }
        effort: { type: string, enum: [lite, standard, deep] }
        report: { type: string, description: "Markdown report with `[n]` citation markers" }
        citations: { type: array, items: { $ref: "#/components/schemas/Citation" } }
        sources: { type: array, items: { $ref: "#/components/schemas/ResearchSource" } }
        queries: { type: array, items: { type: string }, description: Every search the research ran }
        stats:
          type: object
          properties:
            searches: { type: integer }
            sources: { type: integer }
            rounds: { type: integer }
        llm: { $ref: "#/components/schemas/LLMUsage" }
        output: { description: "output_schema only: the JSON value (null when it could not be produced)" }
        output_error: { type: string }

    ResearchTask:
      type: object
      required: [id, kind, status, created_at, credits_reserved, credits_used]
      properties:
        id: { type: string, format: uuid }
        kind: { type: string, const: research }
        status: { $ref: "#/components/schemas/TaskStatus" }
        created_at: { type: string, format: date-time }
        started_at: { type: [string, "null"], format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
        credits_reserved: { type: number }
        credits_used: { type: number }
        webhook_status: { type: [string, "null"], enum: [pending, delivered, failed, null] }
        progress:
          type: [object, "null"]
          additionalProperties: true
          properties:
            round: { type: integer }
            rounds: { type: integer }
            queries: { type: integer }
            sources: { type: integer }
            step: { type: string, enum: [searching, reviewing, writing] }
        result:
          description: Set once the report is written (a failed or canceled task may carry only `queries`)
          anyOf:
            - $ref: "#/components/schemas/ResearchResult"
            - type: object
              additionalProperties: true
            - type: "null"
        error: { $ref: "#/components/schemas/TaskError" }

    CrawlRequest:
      type: object
      required: [url]
      properties:
        url: { type: string, format: uri, description: "Start page (always read: path filters and robots.txt apply to the pages found from it)" }
        limit: { type: integer, minimum: 1, maximum: 1000, default: 25, description: Maximum pages read (and credits reserved) }
        max_depth: { type: integer, minimum: 0, maximum: 10, default: 2, description: "Link hops from url (sitemap pages count as 1 hop; 0 reads only url)" }
        include_paths: { type: array, items: { type: string }, maxItems: 20, description: Regular expressions matched against the URL path; follow only paths matching one }
        exclude_paths: { type: array, items: { type: string }, maxItems: 20, description: Regular expressions matched against the URL path; never follow paths matching one }
        include_subdomains: { type: boolean, default: false }
        sitemap:
          type: string
          enum: [include, only, skip]
          default: include
          description: "`include` also seeds the crawl with the site's sitemap URLs (after the start page's links), `only` reads the start page and sitemap URLs without following links, `skip` follows links only"
        query: { type: string, maxLength: 512, description: "Read the pages most relevant to these words first (best-first crawl)" }
        ignore_query_parameters: { type: boolean, default: false, description: Treat URLs that differ only in their query string as one page }
        format: { type: string, enum: [markdown, text], default: markdown }
        include_links: { type: boolean, default: false, description: Return each page's outbound links }
        max_tokens: { type: integer, minimum: 100, maximum: 100000, description: Trim each page to this many tokens }
        max_age: { type: integer, minimum: 0, maximum: 2592000, description: Accept cached pages up to this many seconds old (0.5 credit each) }
        webhook_url: { type: string, format: uri, description: "Receives the signed `crawl.completed` event. Defaults to the account webhook" }

    TaskStatus:
      type: string
      enum: [queued, running, completed, failed, canceled]

    TaskCreated:
      type: object
      required: [id, kind, status, created_at, poll_url, credits_reserved]
      properties:
        id: { type: string, format: uuid }
        kind: { type: string, enum: [crawl, research] }
        status: { $ref: "#/components/schemas/TaskStatus" }
        created_at: { type: string, format: date-time }
        poll_url: { type: string }
        credits_reserved: { type: number }
        webhook_url: { type: [string, "null"] }

    TaskCancelResponse:
      type: object
      required: [id, status]
      properties:
        id: { type: string, format: uuid }
        status: { type: string, enum: [canceled, canceling] }

    TaskError:
      type: [object, "null"]
      description: Set when the task failed or was canceled
      properties:
        code: { type: string, examples: [no_pages, canceled, timeout, internal] }
        message: { type: string }

    CrawlPage:
      type: object
      required: [url, depth]
      properties:
        url: { type: string }
        depth: { type: integer, description: Link hops from the start page }
        title: { type: string }
        markdown: { type: string }
        text: { type: string }
        published_at: { type: string }
        metadata: { $ref: "#/components/schemas/PageMetadata" }
        links: { type: array, items: { $ref: "#/components/schemas/PageLink" } }

    CrawlResult:
      type: object
      required: [url, pages, failed, stats]
      properties:
        url: { type: string }
        pages: { type: array, items: { $ref: "#/components/schemas/CrawlPage" } }
        failed: { type: array, items: { $ref: "#/components/schemas/ExtractFailure" } }
        stats:
          type: object
          properties:
            pages: { type: integer }
            failed: { type: integer }
            seconds: { type: integer }
            discovered: { type: integer, description: Unique URLs found that passed the filters }
            queued: { type: integer, description: Found but not read when the crawl ended }
            duplicates: { type: integer, description: Pages that redirected to a page already read (not charged) }
            sitemap_urls: { type: integer, description: URLs taken from sitemaps }
            robots: { type: string, enum: [found, missing, unreachable, none], description: "The start host's robots.txt" }
            robots_disallowed: { type: integer, description: Disallow rules in force on the start host }
            robots_blocked: { type: integer, description: URLs skipped because robots.txt disallows them }
            crawl_delay_ms: { type: integer, description: "The start host's Crawl-delay, honoured" }
            stopped: { type: string, enum: [done, limit, time_limit, size_limit, too_many_failures, canceled], description: Why the crawl ended }

    CrawlTask:
      type: object
      required: [id, kind, status, created_at, credits_reserved, credits_used]
      properties:
        id: { type: string, format: uuid }
        kind: { type: string, const: crawl }
        status: { $ref: "#/components/schemas/TaskStatus" }
        created_at: { type: string, format: date-time }
        started_at: { type: [string, "null"], format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
        credits_reserved: { type: number }
        credits_used: { type: number }
        webhook_status: { type: [string, "null"], enum: [pending, delivered, failed, null] }
        progress:
          type: [object, "null"]
          additionalProperties: true
          properties:
            pages_done: { type: integer }
            pages_failed: { type: integer }
            pages_queued: { type: integer }
            pages_discovered: { type: integer }
            limit: { type: integer }
        result:
          description: Set once the crawl ends (also on cancel, with the pages read so far)
          anyOf:
            - $ref: "#/components/schemas/CrawlResult"
            - type: "null"
        error: { $ref: "#/components/schemas/TaskError" }

    MapRequest:
      type: object
      required: [url]
      properties:
        url: { type: string, format: uri, description: The site (any page of it; sitemaps are read from its origin) }
        search: { type: string, maxLength: 512, description: "Keep only URLs relevant to these words, most relevant first. When the sitemap lists fewer than 50 URLs, up to 8 of the start page's links are read too, one level deeper" }
        limit: { type: integer, minimum: 1, maximum: 5000, default: 100 }
        include_subdomains: { type: boolean, default: false }
        include_paths: { type: array, items: { type: string }, maxItems: 20, description: "Regular expressions matched against the URL path; keep only URLs matching one" }
        exclude_paths: { type: array, items: { type: string }, maxItems: 20, description: Regular expressions matched against the URL path; drop URLs matching one }
        ignore_query_parameters: { type: boolean, default: false, description: "Treat URLs that differ only in their query string as one (the first one found is kept)" }
        sitemap:
          type: string
          enum: [include, only, skip]
          default: include
          description: "`include` sitemaps and the start page's links, `only` sitemaps, `skip` sitemaps (links only)"

    MapURL:
      type: object
      required: [url, source]
      properties:
        url: { type: string }
        title: { type: string }
        lastmod: { type: string, description: "The sitemap's lastmod, as written" }
        source: { type: string, enum: [sitemap, page] }

    MapResponse:
      type: object
      required: [request, results, meta]
      properties:
        request:
          type: object
          additionalProperties: true
          properties:
            endpoint: { type: string, const: map }
            url: { type: string }
            search: { type: string }
            limit: { type: integer }
            sitemap: { type: string }
            include_subdomains: { type: boolean }
            include_paths: { type: array, items: { type: string } }
            exclude_paths: { type: array, items: { type: string } }
            ignore_query_parameters: { type: boolean }
        results: { type: array, items: { $ref: "#/components/schemas/MapURL" } }
        meta:
          type: object
          required: [request_id, credits_used, count]
          properties:
            request_id: { type: string }
            credits_used: { type: number }
            latency_ms: { type: integer }
            count: { type: integer }

    Provider:
      type: string
      description: A search provider (docs/providers). Which verticals each serves depends on the deployment.
      enum: [google, brave, bing, yahoo, duckduckgo, mojeek, wikipedia, yandex]

    EngineParam:
      description: >-
        Which search providers may answer. `google` (the default) is Google only; Google requests
        are retried internally before failing. `auto` allows falling back to other enabled providers,
        in route order, when Google is blocked or times out. A single other provider (`brave`) or a list
        (`["google","brave"]`, or `google,brave` in a query string) restricts the request to those providers.
        `meta.engine` always names the provider that answered and credits follow that provider's price.
        A key with "Allow fallback to other search engines" on treats a request without `engine` as `auto`.
        `consensus` (`/v1/search` only; 400 elsewhere, and it can't be combined with other names) queries
        several independent search indexes in parallel (at most one Bing-backed provider, so Yahoo or
        DuckDuckGo never count as agreeing with Bing), merges the results by URL and ranks them by how many
        providers returned each one. Each result lists its `sources`; `meta.engine` is `consensus` and
        `meta.route` lists every provider attempt. Up to three providers answer: a provider that fails or
        comes back empty hands its turn to the next one in the route. It stops once `num` unique results
        are in hand or after a few seconds, and costs the sum of one page at each provider that returned
        results (providers that failed, came back empty or were never started are free).
        `yandex` serves `/v1/search` from Yandex web search (no `time` filter or `safe: active`: a request
        naming it gets a 400 with them) and `/v1/maps`, `/v1/places` and `/v1/place` from Yandex Maps, where
        the deployment enables it (otherwise a 503 `unavailable`, not charged); with `auto` it is the last
        fallback there.
      oneOf:
        - type: string
          default: google
          examples: [google, auto, consensus, brave, "google,brave"]
        - type: array
          items: { $ref: "#/components/schemas/Provider" }
          minItems: 1

    RouteStep:
      type: object
      description: One provider attempt behind this answer.
      required: [provider, outcome, ms]
      properties:
        provider: { type: string, examples: [google, brave] }
        outcome:
          type: string
          enum: [ok, partial, empty, soft_empty, blocked, timeout, error, unsupported, bad_param, bad_target, canceled]
        ms: { type: integer, description: Duration of the attempt in milliseconds }

    Meta:
      type: object
      required: [request_id, credits_used, cached]
      properties:
        request_id: { type: string }
        credits_used: { type: number }
        engine: { type: string, description: "The provider that produced the result (`consensus` for a merged engine=consensus answer)", examples: [google, brave, consensus, stub] }
        route:
          type: array
          description: Provider attempts in order (fresh results only; absent on cache hits). With engine=consensus, every provider started; ones stopped early are `canceled`, ones cut off by the deadline `timeout`
          items: { $ref: "#/components/schemas/RouteStep" }
        cached: { type: boolean }
        cached_at: { type: string, format: date-time }
        resolved_urls: { type: boolean }
        parse_quality:
          type: string
          enum: [ok, partial, empty]
          description: >-
            `partial` means some results were dropped or, on a `num` above 10, that pages are
            listed in `missing_pages`. A result whose link Google did not release in time is kept
            (see `unresolved_links`) and does not make the response `partial`.
        missing_pages:
          type: array
          items: { type: integer }
          description: >-
            Pages of a `num` above 10 that could not be retrieved, for example because Google
            refused them. Absent when every page was retrieved or Google ended the results, so a
            short result without this field is all Google returned. The pages are not billed, and
            positions after a missing middle page are shifted.
        similar_results_hidden:
          type: boolean
          description: >-
            Present and `true` when Google said it hid results very similar to those shown and
            ended the results early. Nothing was lost in collection, but Google's answer for this
            query can differ between requests, so a later request may return more. Such a result
            is not cached.
        unresolved_links:
          type: integer
          minimum: 1
          description: >-
            How many results carry `link_resolved: false` (their `link` is still a Google /goto
            redirect). Absent when every link is a destination. Such a response is not cached.
            Batch jobs and monitor runs wait for these links (up to 2 minutes), so they rarely carry
            any; a live request returns at once and follows held-back links in the background.
            Use /v1/resolve to poll their destinations. Once all links resolve, the completed
            response can be cached.
        latency_ms: { type: integer }
        llm: { $ref: "#/components/schemas/LLMUsage" }
        warnings:
          type: array
          items: { type: string }
          description: Non-fatal problems, e.g. an include_answer that failed (and was refunded)

    LLMUsage:
      type: object
      description: The model that wrote this response's AI part and the tokens it used
      properties:
        provider: { type: string, examples: [anthropic, openai] }
        model: { type: string, examples: [claude-haiku-5-5, gpt-6-luna] }
        input_tokens: { type: integer }
        output_tokens: { type: integer }

    Citation:
      type: object
      required: [index, title, link]
      properties:
        index: { type: integer, description: "The `[n]` marker used in the text (1-based source number)" }
        title: { type: string }
        link: { type: string }
        domain: { type: string }

    SearchAnswer:
      type: object
      description: "include_answer: a cited answer over this response's results"
      required: [text, citations]
      properties:
        text: { type: string, description: "Markdown with `[n]` citation markers (n = the numbered sources: answer box, knowledge panel, then results)" }
        citations: { type: array, items: { $ref: "#/components/schemas/Citation" } }

    RequestEcho:
      type: object
      description: The normalised request that produced this response (defaults filled in)
      required: [endpoint, engine]
      additionalProperties: true
      properties:
        endpoint: { type: string, examples: [search, news, webpage, chatgpt] }
        engine:
          description: The engine policy as asked (google, auto, one provider or a list)
          oneOf:
            - { type: string }
            - { type: array, items: { type: string } }
        q: { type: string }
        url: { type: string }
        country: { type: string }
        language: { type: string }
        location: { type: string }
        num: { type: integer }
        page: { type: integer }
        device: { type: string }
        autocorrect: { type: boolean }
        tbs: { type: string }
        start_date: { type: string, format: date }
        end_date: { type: string, format: date }
        safe: { type: string }
        place_id: { type: string }
        cid: { type: string }
        fid: { type: string }
        oid: { type: string }
        sort: { type: string }
        include_content: { type: integer }
        format: { type: string }
        include_domains: { type: array, items: { type: string } }
        exclude_domains: { type: array, items: { type: string } }
        boost_domains: { type: array, items: { type: string } }
        highlights: { type: boolean }
        include_answer: { type: boolean }
        prompt: { type: string, description: AI assistant endpoints }
        web_search: { type: boolean, description: /v1/chatgpt }
        include_html: { type: boolean }

    Sitelink:
      type: object
      required: [title, link]
      properties:
        title: { type: string }
        link: { type: string }
        snippet: { type: string }

    ResolveRequest:
      type: object
      additionalProperties: false
      required: [links]
      properties:
        links:
          type: array
          minItems: 1
          maxItems: 100
          description: '`link` values of results with `link_resolved: false`, as returned'
          items: { type: string, examples: ["https://www.google.com/goto?url=CAESgwEB6zsw"] }
    ResolvedLink:
      type: object
      required: [link, status]
      properties:
        link: { type: string, description: The link as sent }
        status:
          type: string
          enum: [resolved, pending, failed, unknown]
          description: >-
            `resolved`: `destination` is where it leads. `pending`: still waiting for Google; ask again
            after `retry_after`. `failed`: Google never released it. `unknown`: not a link SerpKite
            returned in the last 24 hours.
        destination: { type: string, description: The destination URL (`resolved` only) }
        domain: { type: string, description: Canonical host of `destination` without www. (`resolved` only) }
    ResolveResponse:
      type: object
      required: [results, meta]
      properties:
        results: { type: array, items: { $ref: "#/components/schemas/ResolvedLink" } }
        retry_after: { type: integer, description: Seconds to wait before asking again for the `pending` links (absent when none is pending) }
        meta:
          type: object
          required: [request_id, credits_used]
          properties:
            request_id: { type: string }
            credits_used: { type: number, description: Always 0 }

    OrganicResult:
      type: object
      required: [position, title, link, domain]
      properties:
        position: { type: integer }
        title: { type: string }
        link: { type: string, description: "Resolved destination URL, never a google.com/url redirect. Google's /goto redirect only with `link_resolved: false`" }
        domain: { type: string, description: Canonical host without www. }
        link_resolved:
          type: boolean
          description: >-
            Present and `false` only when `link` is still Google's `https://www.google.com/goto?url=…`
            redirect, because Google did not release the destination in time. The result keeps its
            position; `domain` is then the host Google displayed for it (empty when it displayed
            none). `POST /v1/resolve` returns the destination once Google releases it. Absent when
            `link` is the destination.
        displayed_link: { type: string }
        snippet: { type: string }
        date: { type: string }
        sitelinks: { type: array, items: { $ref: "#/components/schemas/Sitelink" } }
        attributes: { type: object, additionalProperties: { type: string } }
        rating: { type: number }
        rating_count: { type: integer }
        published_at: { type: string, description: "`date` as an ISO 8601 date or date-time when it parses (relative dates resolved against the fetch time)", examples: ["2026-09-30", "2026-10-03T09:00:00Z"] }
        content: { type: string, description: Page Markdown when include_content covered this result }
        highlights:
          type: array
          description: highlights=true only. Query-ranked passages of the fetched page, best first (instead of content)
          items: { $ref: "#/components/schemas/Highlight" }
        sources:
          type: array
          description: engine=consensus only. The providers that returned this result, in route order; results are ranked by how many there are
          items: { $ref: "#/components/schemas/Provider" }
          examples: [[google, brave, bing]]

    AnswerBox:
      type: object
      properties:
        title: { type: string }
        answer: { type: string }
        snippet: { type: string }
        snippet_highlighted: { type: array, items: { type: string } }
        link: { type: string }

    KnowledgeGraph:
      type: object
      properties:
        title: { type: string }
        type: { type: string }
        website: { type: string }
        image_url: { type: string }
        description: { type: string }
        description_source: { type: string }
        description_link: { type: string }
        attributes: { type: object, additionalProperties: { type: string } }

    PeopleAlsoAsk:
      type: object
      required: [question]
      properties:
        question: { type: string }
        snippet: { type: string }
        title: { type: string }
        link: { type: string }

    RelatedSearch:
      type: object
      required: [query]
      properties:
        query: { type: string }

    SearchResponse:
      type: object
      required: [request, results, related_searches, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/OrganicResult" } }
        answer_box: { $ref: "#/components/schemas/AnswerBox" }
        knowledge_graph: { $ref: "#/components/schemas/KnowledgeGraph" }
        ads: { type: array, items: { $ref: "#/components/schemas/OrganicResult" } }
        people_also_ask: { type: array, items: { $ref: "#/components/schemas/PeopleAlsoAsk" } }
        related_searches: { type: array, items: { $ref: "#/components/schemas/RelatedSearch" } }
        top_stories: { type: array, items: { $ref: "#/components/schemas/NewsResult" } }
        places: { type: array, items: { $ref: "#/components/schemas/PlaceResult" } }
        answer: { $ref: "#/components/schemas/SearchAnswer" }
        ai_overview: { $ref: "#/components/schemas/AIOverview", description: "Google's AI Overview when the page showed one" }
        meta: { $ref: "#/components/schemas/Meta" }

    ImageResult:
      type: object
      required: [position, title, image_url]
      properties:
        position: { type: integer }
        title: { type: string }
        image_url: { type: string }
        image_width: { type: integer }
        image_height: { type: integer }
        thumbnail_url: { type: string }
        source: { type: string }
        domain: { type: string }
        link: { type: string }
    ImagesResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/ImageResult" } }
        meta: { $ref: "#/components/schemas/Meta" }

    VideoResult:
      type: object
      required: [position, title, link]
      properties:
        position: { type: integer }
        title: { type: string }
        link: { type: string }
        domain: { type: string }
        snippet: { type: string }
        image_url: { type: string }
        duration: { type: string }
        source: { type: string }
        channel: { type: string }
        date: { type: string }
        published_at: { type: string, description: "`date` as ISO 8601 when it parses" }
        link_resolved:
          type: boolean
          description: >-
            Present and `false` only when `link` is still Google's `https://www.google.com/goto?url=…`
            redirect, because Google did not release the destination in time. The result keeps its
            position; `domain` is then the host Google displayed for it (empty when it displayed
            none). `POST /v1/resolve` returns the destination once Google releases it. Absent when
            `link` is the destination.
    VideosResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/VideoResult" } }
        meta: { $ref: "#/components/schemas/Meta" }

    NewsResult:
      type: object
      required: [position, title, link]
      properties:
        position: { type: integer }
        title: { type: string }
        link: { type: string }
        domain: { type: string }
        snippet: { type: string }
        date: { type: string }
        published_at: { type: string, description: "`date` as ISO 8601 when it parses" }
        source: { type: string }
        image_url: { type: string }
        link_resolved:
          type: boolean
          description: >-
            Present and `false` only when `link` is still Google's `https://www.google.com/goto?url=…`
            redirect, because Google did not release the destination in time. The result keeps its
            position; `domain` is then the host Google displayed for it (empty when it displayed
            none). `POST /v1/resolve` returns the destination once Google releases it. Absent when
            `link` is the destination.
    NewsResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/NewsResult" } }
        answer: { $ref: "#/components/schemas/SearchAnswer" }
        meta: { $ref: "#/components/schemas/Meta" }

    PlaceResult:
      type: object
      required: [position, title]
      properties:
        position: { type: integer }
        title: { type: string }
        address: { type: string }
        latitude: { type: number }
        longitude: { type: number }
        rating: { type: number }
        rating_count: { type: integer }
        price_level: { type: string }
        type: { type: string }
        types: { type: array, items: { type: string } }
        website: { type: string }
        phone_number: { type: string }
        international_phone_number: { type: string, examples: ["+44 20 7232 3010"] }
        opening_hours:
          type: object
          additionalProperties: { type: string }
          description: 'Hours as the provider displays them, keyed by English weekday (Monday … Sunday), in `language`, e.g. {"Monday": "7:30 am–6 pm", "Sunday": "Closed"}; Yandex Maps: 24-hour times ("08:00–22:00"), "Closed"/"выходной", "Open 24 hours"/"круглосуточно"'
        weekly_hours: { $ref: "#/components/schemas/WeeklyHours" }
        country: { type: string, description: "ISO 3166-1 alpha-2 country code of the place, upper case (RU, GB)" }
        timezone: { type: string, description: IANA time zone of the place (Europe/Moscow) }
        description: { type: string, description: "Google's short description of the place, or the owner's, when Google shows one; Yandex Maps' summary of the place when it has one" }
        photos:
          type: array
          description: Photos of the place (/v1/place; up to 10). The URLs are public and can be fetched server-side without cookies
          items: { $ref: "#/components/schemas/PlacePhoto" }
        google_maps_url: { type: string, description: The place on Google Maps }
        thumbnail_url: { type: string }
        place_id: { type: string }
        cid: { type: string }
        fid: { type: string }
        oid: { type: string, description: "Yandex Maps organisation id (engine=yandex), for /v1/place" }
        yandex_maps_url: { type: string, description: "The place on Yandex Maps (engine=yandex): https://yandex.ru/maps/org/<oid>/" }
    WeeklyHours:
      type: object
      description: |
        Opening hours per weekday, from the provider's listing, as local times (`timezone`) in 24-hour HH:MM.
        A day that is closed is an empty list; a day open 24 hours is `[{"open": "00:00", "close": "24:00"}]`;
        a day with a break has several intervals. `close` is "24:00" at midnight, and an interval that
        ends after midnight has `next_day: true` (e.g. 17:30–03:00). Days Google doesn't list are absent;
        Yandex Maps lists all seven or none.
      properties:
        monday: { $ref: "#/components/schemas/HoursIntervals" }
        tuesday: { $ref: "#/components/schemas/HoursIntervals" }
        wednesday: { $ref: "#/components/schemas/HoursIntervals" }
        thursday: { $ref: "#/components/schemas/HoursIntervals" }
        friday: { $ref: "#/components/schemas/HoursIntervals" }
        saturday: { $ref: "#/components/schemas/HoursIntervals" }
        sunday: { $ref: "#/components/schemas/HoursIntervals" }
    HoursIntervals:
      type: array
      items: { $ref: "#/components/schemas/HoursInterval" }
    HoursInterval:
      type: object
      required: [open, close]
      properties:
        open: { type: string, pattern: "^[0-2][0-9]:[0-5][0-9]$", examples: ["08:00"] }
        close: { type: string, pattern: "^[0-2][0-9]:[0-5][0-9]$", examples: ["22:00"] }
        next_day: { type: boolean, description: "The interval closes after midnight, on the next day" }
    PlacePhoto:
      type: object
      required: [url]
      properties:
        url: { type: string, description: "Image URL (at most 1600 px on the long side)" }
        width: { type: integer }
        height: { type: integer }
        source: { type: string, enum: [business, visitor], description: "Who uploaded it, when Google says (Google shows no contributor names to logged-out visitors)" }
    PlacesResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/PlaceResult" } }
        meta: { $ref: "#/components/schemas/Meta" }

    ReviewResult:
      type: object
      properties:
        rating: { type: number }
        date: { type: string }
        iso_date: { type: string }
        snippet: { type: string }
        likes: { type: integer }
        user:
          type: object
          properties:
            name: { type: string }
            thumbnail: { type: string }
            reviews: { type: integer }
        response: { type: object, properties: { snippet: { type: string }, date: { type: string } } }
    ReviewsResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/ReviewResult" } }
        next_page_token: { type: string, description: "Pass as `page_token` for the next page. Absent on the last page and at the 100-review depth limit" }
        meta: { $ref: "#/components/schemas/Meta" }

    ShoppingResult:
      type: object
      required: [position, title]
      properties:
        position: { type: integer }
        title: { type: string }
        source: { type: string }
        link: { type: string, description: "The merchant page when Google's card links to it; most cards don't, and then this is Google's product viewer or shopping page for the item" }
        price: { type: string }
        price_value: { type: number }
        currency: { type: string }
        delivery: { type: string }
        image_url: { type: string }
        rating: { type: number }
        rating_count: { type: integer }
        offers: { type: string }
        product_id: { type: string }
    ShoppingResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/ShoppingResult" } }
        meta: { $ref: "#/components/schemas/Meta" }

    ScholarResult:
      type: object
      required: [position, title, link]
      properties:
        position: { type: integer }
        title: { type: string }
        link: { type: string }
        domain: { type: string }
        publication_info: { type: string }
        snippet: { type: string }
        year: { type: integer }
        cited_by: { type: integer }
        pdf_url: { type: string }
        id: { type: string }
    ScholarResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/ScholarResult" } }
        meta: { $ref: "#/components/schemas/Meta" }

    PatentResult:
      type: object
      required: [position, title, link]
      properties:
        position: { type: integer }
        title: { type: string }
        snippet: { type: string }
        link: { type: string }
        publication_number: { type: string }
        priority_date: { type: string }
        filing_date: { type: string }
        grant_date: { type: string }
        publication_date: { type: string }
        inventor: { type: string }
        assignee: { type: string }
        language: { type: string }
        pdf_url: { type: string }
        thumbnail_url: { type: string }
    PatentsResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/PatentResult" } }
        meta: { $ref: "#/components/schemas/Meta" }

    Suggestion:
      type: object
      required: [value]
      properties:
        value: { type: string }
    AutocompleteResponse:
      type: object
      required: [request, results, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        results: { type: array, items: { $ref: "#/components/schemas/Suggestion" } }
        meta: { $ref: "#/components/schemas/Meta" }

    PageMetadata:
      type: object
      properties:
        title: { type: string }
        description: { type: string }
        language: { type: string }
        canonical: { type: string }
        site_name: { type: string }
        image: { type: string }
        published_time: { type: string }
        author: { type: string }
        content_type: { type: string, description: The page's media type, examples: [text/html, application/pdf] }
        pages: { type: integer, description: Page count of a PDF }
    PageLink:
      type: object
      required: [url]
      properties:
        url: { type: string, description: Absolute URL }
        text: { type: string, description: Anchor text }
    WebpageResponse:
      type: object
      required: [request, url, markdown, metadata, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        url: { type: string, description: Final URL after redirects }
        status_code: { type: integer }
        markdown: { type: string }
        text: { type: string }
        html: { type: string, description: Only with include_html=true }
        metadata: { $ref: "#/components/schemas/PageMetadata" }
        links: { type: array, items: { $ref: "#/components/schemas/PageLink" }, description: "include_links=true only. Outbound links in document order, deduplicated" }
        image_links: { type: array, items: { type: string }, description: include_images=true only. Image URLs in document order }
        meta: { $ref: "#/components/schemas/Meta" }

    CSEError:
      type: object
      description: Google's error body, used by /customsearch/v1 only
      required: [error]
      properties:
        error: { $ref: "#/components/schemas/CSEErrorBody" }
    CSEErrorBody:
      type: object
      required: [code, message, errors, status]
      properties:
        code: { type: integer, description: The HTTP status }
        message: { type: string }
        errors:
          type: array
          items: { $ref: "#/components/schemas/CSEErrorItem" }
        status: { type: string, examples: [INVALID_ARGUMENT, UNAUTHENTICATED, RESOURCE_EXHAUSTED, UNAVAILABLE] }
        details:
          type: array
          description: One google.rpc.ErrorInfo whose reason is the SerpKite error code
          items: { type: object, additionalProperties: true }
        request_id: { type: string }
    CSEErrorItem:
      type: object
      properties:
        message: { type: string }
        domain: { type: string, const: global }
        reason: { type: string, examples: [badRequest, keyInvalid, quotaExceeded, rateLimitExceeded, backendError] }
    CSEResponse:
      type: object
      required: [kind, searchInformation]
      properties:
        kind: { type: string, const: customsearch#search }
        url: { type: object }
        queries: { type: object, additionalProperties: true }
        context: { type: object }
        searchInformation:
          type: object
          properties:
            searchTime: { type: number }
            formattedSearchTime: { type: string }
            totalResults: { type: string }
            formattedTotalResults: { type: string }
        items:
          type: array
          description: Absent when there are no results, as in the API
          items:
            type: object
            properties:
              kind: { type: string, const: customsearch#result }
              title: { type: string }
              htmlTitle: { type: string }
              link: { type: string }
              displayLink: { type: string }
              snippet: { type: string }
              htmlSnippet: { type: string }
              formattedUrl: { type: string }
              htmlFormattedUrl: { type: string }
              pagemap: { type: object, additionalProperties: true }
              image: { type: object, additionalProperties: true }
              mime: { type: string }
              fileFormat: { type: string }
              link_resolved:
                type: boolean
                const: false
                description: Present when link is still Google's /goto redirect (as on /v1/search); displayLink is then the domain Google showed. POST /v1/resolve gives the destination

    RankRequest:
      type: object
      required: [q, domain]
      properties:
        q: { type: string }
        domain: { type: string, description: 'Domain to find, e.g. "example.com" (subdomains match)' }
        num: { type: integer, enum: [10, 20, 30, 50, 100], default: 100 }
        country: { type: string }
        language: { type: string }
        location: { type: string }
        device: { type: string, enum: [desktop, mobile] }
        max_age: { type: integer }
    RankResponse:
      type: object
      required: [request, domain, position, matches, checked, meta]
      properties:
        request: { $ref: "#/components/schemas/RequestEcho" }
        domain: { type: string }
        position: { type: [integer, "null"], description: Best organic position, null when not in the checked results }
        matches:
          type: array
          items:
            type: object
            required: [position, title, link]
            properties:
              position: { type: integer }
              title: { type: string }
              link: { type: string }
        checked: { type: integer, description: Organic results inspected }
        meta: { $ref: "#/components/schemas/Meta" }

    Status:
      type: object
      required: [status, window_minutes, endpoints, updated_at]
      properties:
        status: { type: string, enum: [operational, degraded] }
        window_minutes: { type: integer }
        updated_at: { type: string, format: date-time }
        endpoints:
          type: array
          items:
            type: object
            required: [endpoint, requests, success_rate, p50_ms, p95_ms]
            properties:
              endpoint: { type: string }
              requests: { type: integer }
              success_rate: { type: number, description: Share of requests without a 5xx (0-1) }
              p50_ms: { type: integer, description: Median latency of successful (non-error) responses; 0 when none succeeded }
              p95_ms: { type: integer, description: 95th-percentile latency of successful (non-error) responses; 0 when none succeeded }
    AIStatus:
      type: object
      required: [status, window_minutes, degraded_below, min_requests, pairs, updated_at]
      properties:
        status: { type: string, enum: [operational, degraded] }
        window_minutes: { type: integer }
        degraded_below: { type: number, description: Success rate under which a pair with min_requests or more is degraded }
        min_requests: { type: integer }
        updated_at: { type: string, format: date-time }
        pairs:
          type: array
          items:
            type: object
            required: [endpoint, country, requests, success_rate, failures, p50_ms, p95_ms, over_25s, degraded]
            properties:
              endpoint: { type: string, examples: [/v1/ai_mode] }
              country: { type: string, description: "The country the requests named (lowercase ISO code), or none for requests that named no country" }
              requests: { type: integer }
              success_rate: { type: number, description: "Share of requests answered 200 with an answer (0-1); 1 when there were none" }
              failures: { type: object, additionalProperties: { type: integer }, description: "Failed requests by error code, plus `empty`" }
              p50_ms: { type: integer, description: "Upper bound of the latency bucket holding the median answered request" }
              p95_ms: { type: integer }
              over_25s: { type: number, description: Share of requests that took more than 25 s }
              degraded: { type: boolean }

    BatchCreateRequest:
      type: object
      required: [endpoint, requests]
      properties:
        endpoint:
          type: string
          enum: [search, images, videos, news, maps, places, place, reviews, shopping, scholar, patents, autocomplete, webpage, chatgpt, gemini, copilot, ai_mode, brave_ai]
        requests:
          type: array
          minItems: 1
          maxItems: 100
          description: Request bodies for `endpoint` (same fields as the realtime endpoint)
          items: { type: object, additionalProperties: true }
        webhook_url: { type: string, format: uri, description: "POSTed each job's result, always signed with X-SerpKite-Signature (v1=hex HMAC-SHA256 of `<timestamp>.<body>` with the account webhook secret; see createBatches). Defaults to the account webhook" }
    BatchCreateResponse:
      type: object
      required: [batches]
      properties:
        batches:
          type: array
          items:
            oneOf:
              - $ref: "#/components/schemas/Batch"
              - $ref: "#/components/schemas/Error"

    Batch:
      type: object
      required: [id, status, endpoint, created_at, poll_url]
      properties:
        id: { type: string, format: uuid }
        status: { type: string, enum: [queued, running, done, failed] }
        endpoint: { type: string, examples: [/v1/search] }
        created_at: { type: string, format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
        credits_used: { type: number }
        poll_url: { type: string }
        webhook_url: { type: [string, "null"] }
        webhook_status: { type: [string, "null"], enum: [pending, delivered, failed, null] }
        error: { type: [object, "null"], properties: { code: { type: string }, message: { type: string } } }
        result: { type: [object, "null"], additionalProperties: true, description: "Present when done; kept 24h. The endpoint's response body, or {markdown, meta} for format=markdown jobs" }

    Account:
      type: object
      required: [balance, rate_limit_rps, plan, month]
      properties:
        balance: { type: number, description: "Negative after a refund of credits that were already spent; requests then get 402 insufficient_credits" }
        rate_limit_rps: { type: integer, description: "Requests per second allowed per key (on a free account, shared by all its keys)" }
        plan: { type: string, enum: [free, paid] }
        key: { type: object, properties: { id: { type: string }, name: { type: string }, credit_limit: { type: [number, "null"] }, credits_used_month: { type: number } } }
        monthly_spend_cap: { type: [number, "null"] }
        month:
          type: object
          required: [credits, requests]
          properties:
            credits: { type: number }
            requests: { type: integer }

    TaskCompletedEvent:
      type: object
      description: "Body of `crawl.completed` and `research.completed`"
      required: [event, id, kind, status, created_at, credits_used]
      properties:
        event: { type: string, enum: [crawl.completed, research.completed] }
        id: { type: string, format: uuid }
        kind: { type: string, enum: [crawl, research] }
        status: { $ref: "#/components/schemas/TaskStatus" }
        created_at: { type: string, format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
        credits_used: { type: number }
        poll_url: { type: string, description: Where the task (and its full result) can be fetched for 24 hours }
        result: { description: "The CrawlResult or ResearchResult (null when the task failed without one, or when it is larger than 4 MB: see result_omitted)" }
        result_omitted: { type: boolean, description: "Set when the result was too large for the webhook; GET poll_url for it" }
        error:
          type: object
          properties:
            code: { type: string }
            message: { type: string }

    MonitorSearch:
      type: object
      description: "The saved request a monitor reruns: a search (q and options), for webpage monitors url (and country), or for AI assistant monitors prompt (with country, language, location on ai_mode and brave_ai, web_search and track)"
      properties:
        q: { type: string }
        url: { type: string }
        prompt: { type: string, description: AI assistant monitors }
        web_search: { type: boolean, description: endpoint=chatgpt }
        track: { type: array, items: { type: string } }
        country: { type: string }
        language: { type: string }
        location: { type: string }
        time: { type: string, enum: [hour, day, week, month, year] }
        num: { type: integer }
        device: { type: string }
        safe: { type: string }
        include_domains: { type: array, items: { type: string } }
        exclude_domains: { type: array, items: { type: string } }
        engine: { type: array, items: { type: string } }

    MonitorCreateRequest:
      type: object
      description: "Search and news monitors need `q`; webpage monitors need `url` and take only `country` besides; AI assistant monitors need `prompt` and take `country`, `language` (not chatgpt), `location` (ai_mode, brave_ai), `web_search` (chatgpt) and `track`"
      properties:
        q: { type: string, minLength: 1, maxLength: 2048 }
        url: { type: string, format: uri, description: "endpoint=webpage: the page to watch for content changes" }
        prompt: { type: string, minLength: 1, maxLength: 4000, description: "AI assistant monitors: the prompt asked every run" }
        web_search: { type: boolean, description: endpoint=chatgpt }
        track: { $ref: "#/components/schemas/TrackList" }
        endpoint: { type: string, enum: [search, news, webpage, chatgpt, gemini, copilot, ai_mode, brave_ai], default: search }
        metadata: { type: object, additionalProperties: true, description: "Your own JSON object (at most 2 KB), echoed on the monitor and in its webhooks" }
        name: { type: string, maxLength: 200 }
        interval: { type: string, enum: [hourly, daily, weekly], default: daily }
        interval_seconds: { type: integer, minimum: 3600, maximum: 2592000, description: Overrides interval }
        webhook_url: { type: string, format: uri, description: "Receives signed `monitor.results` events. Without one, read new results from the run history" }
        active: { type: boolean, default: true, description: "false creates the monitor paused" }
        country: { type: string }
        language: { type: string }
        location: { type: string }
        time: { type: string, enum: [hour, day, week, month, year] }
        num: { type: integer, minimum: 1, maximum: 100 }
        device: { type: string, enum: [desktop, mobile] }
        safe: { type: string, enum: [active, off] }
        include_domains: { $ref: "#/components/schemas/DomainList" }
        exclude_domains: { $ref: "#/components/schemas/DomainList" }
        engine: { $ref: "#/components/schemas/EngineParam" }

    MonitorUpdateRequest:
      type: object
      description: Only the fields sent change. Search fields are merged into the saved search; a changed search (or endpoint) makes the next run report every result as new.
      properties:
        name: { type: string, maxLength: 200 }
        interval: { type: string, enum: [hourly, daily, weekly] }
        interval_seconds: { type: integer, minimum: 3600, maximum: 2592000 }
        webhook_url: { type: string, description: "A webhook URL, or an empty string to remove it" }
        active: { type: boolean, description: "true resumes a paused monitor (due now, failure streak cleared)" }
        metadata: { type: [object, "null"], additionalProperties: true, description: Replaces the metadata (null clears it) }
        endpoint: { type: string, enum: [search, news, webpage, chatgpt, gemini, copilot, ai_mode, brave_ai], description: "Switching between a search, a page and an AI prompt drops the other kinds' fields" }
        q: { type: string, minLength: 1, maxLength: 2048 }
        prompt: { type: string, minLength: 1, maxLength: 4000 }
        web_search: { type: boolean }
        track: { $ref: "#/components/schemas/TrackList" }
        url: { type: string, format: uri, description: endpoint=webpage only }
        country: { type: string }
        language: { type: string }
        location: { type: string }
        time: { type: string, enum: [hour, day, week, month, year] }
        num: { type: integer, minimum: 1, maximum: 100 }
        device: { type: string, enum: [desktop, mobile] }
        safe: { type: string, enum: [active, off] }
        include_domains: { $ref: "#/components/schemas/DomainList" }
        exclude_domains: { $ref: "#/components/schemas/DomainList" }
        engine: { $ref: "#/components/schemas/EngineParam" }

    Monitor:
      type: object
      required: [id, name, endpoint, request, interval_seconds, webhook_url, active, next_run_at, runs, consecutive_failures, credits_used, created_at]
      properties:
        id: { type: string, format: uuid }
        name: { type: string }
        endpoint: { type: string, enum: [search, news, webpage, chatgpt, gemini, copilot, ai_mode, brave_ai] }
        request: { $ref: "#/components/schemas/MonitorSearch" }
        metadata: { type: [object, "null"], additionalProperties: true }
        interval_seconds: { type: integer }
        webhook_url: { type: [string, "null"], description: Null when new results are only kept in the run history }
        active: { type: boolean }
        next_run_at: { type: string, format: date-time }
        last_run_at: { type: [string, "null"], format: date-time }
        last_status: { type: [string, "null"], enum: [ok, error, webhook_failed, paused, null] }
        last_error: { type: [string, "null"] }
        last_new_results: { type: integer, description: New results found by the last run }
        runs: { type: integer }
        consecutive_failures: { type: integer, description: Failed runs in a row; the monitor pauses itself at 10 }
        credits_used: { type: number, description: Total over all runs }
        created_at: { type: string, format: date-time }

    MonitorRun:
      type: object
      required: [id, status, new_results, credits_used, created_at]
      properties:
        id: { type: string, format: uuid }
        status: { type: string, enum: [ok, error, webhook_failed, paused] }
        error: { type: [string, "null"] }
        new_results: { type: integer }
        results:
          type: [array, "null"]
          description: The new results (OrganicResult-shaped for search, NewsResult for news, MonitorPageChange for webpage, one MonitorAnswer per run for AI assistants); null when there were none or after 24 hours
          items: { type: object, additionalProperties: true }
        credits_used: { type: number }
        webhook_status: { type: [string, "null"], enum: [delivered, failed, none, null], description: "none = the monitor has no webhook; null = nothing to send" }
        created_at: { type: string, format: date-time }

    MonitorPageChange:
      type: object
      description: What a webpage monitor reports when the page is new to it or its content changed
      required: [url, change, content_hash, markdown]
      properties:
        url: { type: string, description: Final URL after redirects }
        title: { type: string }
        change: { type: string, enum: [new, changed] }
        content_hash: { type: string, description: Fingerprint of the content (whitespace-insensitive) }
        markdown: { type: string, description: The page's Markdown (up to about 8,000 tokens) }
        published_at: { type: string }

    MonitorAnswer:
      type: object
      description: What an AI assistant monitor reports every run (one item per run)
      required: [text, markdown, sources, new_sources, search_queries]
      properties:
        text: { type: string }
        markdown: { type: string }
        model: { type: string }
        sources: { type: array, items: { $ref: "#/components/schemas/AISource" } }
        new_sources: { type: array, items: { type: string }, description: Links of the sources not seen in earlier runs }
        search_queries: { type: array, items: { type: string } }
        products: { type: array, items: { $ref: "#/components/schemas/AIProduct" } }
        mentions: { type: array, items: { $ref: "#/components/schemas/Mention" }, description: With track only }

    MonitorRunList:
      type: object
      required: [results, next_before]
      properties:
        results: { type: array, items: { $ref: "#/components/schemas/MonitorRun" } }
        next_before: { type: [string, "null"], format: uuid, description: Pass as `before` for the next page; null on the last page }

    MonitorList:
      type: object
      required: [results]
      properties:
        results: { type: array, items: { $ref: "#/components/schemas/Monitor" } }

    MonitorResultsEvent:
      type: object
      description: "Body of `monitor.results`"
      required: [event, monitor_id, run_id, name, endpoint, first_run, run_at, new_results, credits_used]
      properties:
        event: { type: string, const: monitor.results }
        monitor_id: { type: string, format: uuid }
        run_id: { type: string, format: uuid, description: Also the X-SerpKite-Delivery header; use it to deduplicate retries }
        name: { type: string }
        endpoint: { type: string, enum: [search, news, webpage, chatgpt, gemini, copilot, ai_mode, brave_ai] }
        q: { type: string, description: The saved query (empty for webpage monitors, absent for AI assistant monitors) }
        url: { type: string, description: webpage monitors only }
        prompt: { type: string, description: AI assistant monitors only (instead of q) }
        metadata: { type: [object, "null"], additionalProperties: true, description: The monitor's metadata }
        first_run: { type: boolean, description: The first run since the monitor was created or its search changed }
        run_at: { type: string, format: date-time }
        new_results:
          type: array
          description: Results not seen in earlier runs (OrganicResult-shaped for search, NewsResult for news, MonitorPageChange for webpage); for AI assistant monitors the run's answer (one MonitorAnswer, sent every run)
          items: { type: object, additionalProperties: true }
        credits_used: { type: number, description: This run's price }
