openapi: 3.1.0

info:
  title: IRMU Crawl API
  version: "1.0.0"
  description: |
    The metered crawl endpoint, and the free one that collects a crawl too slow
    to have been waited for.

    A request is authenticated with an organization API key, minted from the
    dashboard. Keys carry only the `crawl` ability, and each one belongs to
    exactly one organization -- which is why the organization is not named in
    the path. Every crawl spends that organization's credits.

    ## Connect via MCP

    Every metered endpoint -- crawl and recipes, screenshot, ChatGPT, Google
    AI Overview and Booking -- is also a tool on an MCP server, for AI agents
    such as Claude Code, Cursor or VS Code. A crawl that is still running is collected with the `crawl_poll`
    tool. Each tool charges, refunds and answers the same way its endpoint
    does.

    Add the server and the client signs you in through your browser. You
    choose which of your organizations it bills:

    ```
    claude mcp add --transport http irmu https://app.irmu.com/mcp
    ```

    A client with no browser can use an organization API key instead:

    ```
    claude mcp add --transport http irmu https://app.irmu.com/mcp \
      --header "Authorization: Bearer <api key>"
    ```

    Setup for Claude, ChatGPT, Cursor, VS Code, Windsurf, Codex and Gemini CLI
    is at [/mcp](/mcp).

servers:
  - url: https://app.irmu.com/api
    description: Production

tags:
  - name: Crawl
    description: Fetching a page, charging for it, and collecting it if it was slow.
  - name: ChatGPT
    description: Putting a question to ChatGPT through the same crawler.
  - name: Screenshot
    description: Photographing a page instead of reading it, through the same crawler.
  - name: Booking
    description: Searching Booking.com and reading its property pages, through the same crawler.
  - name: Tripadvisor
    description: Searching Tripadvisor's hotels and reading its hotel pages, through the same crawler.
  - name: Airbnb
    description: Searching Airbnb and reading its listings, through the same crawler.
  - name: Google
    description: Reading the AI Overview Google shows for a query, through the same crawler.

paths:
  /crawl:
    get:
      tags: [Crawl]
      summary: Crawl a url
      operationId: crawl
      description: |
        Charges the calling organization for the crawl and tallies it against
        the url's host for the day, then returns what was requested and what it
        cost.

        The charge is decided before the fetch: see `credits_charged` below for
        the price of each combination of options.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: url
          in: query
          required: true
          description: The page to crawl. Must be `http` or `https` and must have a host.
          schema:
            type: string
            format: uri
            maxLength: 2048
          example: https://example.com/products?page=2
        - name: premium
          in: query
          required: false
          description: |
            Fetch through the premium proxy pool instead of the standard one.
            Costs more; use it for targets that refuse ordinary requests.

            Every crawl is proxied either way -- this chooses which pool, not
            whether there is one. `country` works on both.

            Sent as text in a query string, so the spellings a person would
            reach for all work: `true`, `false`, `1`, `0`, `yes`, `no`, `on`,
            `off`, in any case. Anything that is not a yes or a no is refused
            rather than quietly read as `false`.
          schema:
            type: string
            default: "false"
          example: "false"
        - name: js
          in: query
          required: false
          description: |
            Render javascript before reading the page. On by default, because it
            is what works on most of the web -- a caller who knows their target
            is static turns it off and pays less. Accepts the same spellings as
            `premium`.

            Off, the page comes back as the server delivered it: scripts are
            neither run nor even downloaded, along with anything they would have
            requested, which makes this the bluntest lever there is on how long a
            crawl takes. Only use it where what you came for is in the served
            html -- on a client-rendered site the page will be empty, and it is
            still charged for.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: images
          in: query
          required: false
          description: |
            Download the images on the page. **Off by default**, and the one
            option here that costs more when you turn it on: 2 credits on top of
            the fetch, whatever the fetch itself came to.

            Off, image requests are aborted before they leave the browser and
            everything else -- HTML, CSS, scripts, XHR -- still loads, so the page
            behaves normally apart from having no pictures. An `<img>` tag is in
            the html either way, so its `src` is still there to be read; what you
            do not get is the file behind it. On a test page the difference
            measured 422 KB against 166 KB.

            Turn them on when the bytes are what you came for. Stacks with
            `adblock`, which blocks a different set of requests.

            Accepts the same spellings as `premium`.
          schema:
            type: string
            default: "false"
          example: "false"
        - name: ai_query
          in: query
          required: false
          description: |
            A question to answer about the page once it has been retrieved.
            Costs 5 credits on top of the fetch. An empty value is the same as
            asking nothing and costs nothing extra.
          schema:
            type: string
            maxLength: 1000
          example: What is the price?
        - name: adblock
          in: query
          required: false
          description: |
            Drop ads and trackers before the page loads, using the EasyList
            filters. **On by default**, and free either way -- it changes nothing
            about the price.

            Ad and tracker payloads dominate a typical retail page, and blocking
            them cuts what has to be downloaded by around 80% while leaving the
            page's own assets untouched, so this is the right default for almost
            every target. What it also removes is anything an ad or analytics
            script would have written into the document -- a tracking pixel's
            payload, a `dataLayer` an ad tag populates. Send `adblock=false` if
            that is what you came for.

            Accepts the same spellings as `premium`.
          schema:
            type: string
            default: "true"
          example: "false"
        - name: wait_until
          in: query
          required: false
          description: |
            When the page counts as loaded. `networkidle2` by default -- it waits
            until no more than two connections are left open, which returns a
            finished page without hanging on a beacon or a poll that never stops.

            Use `networkidle0` to wait for complete silence, or
            `domcontentloaded` or `load` for a page that keeps several
            connections open (sockets, polls, analytics), where waiting for the
            network means waiting until the crawl times out.
          schema:
            type: string
            enum: [load, domcontentloaded, networkidle0, networkidle2]
            default: networkidle2
          example: networkidle2
        - name: cookies_banner
          in: query
          required: false
          description: |
            How cookie banners are answered, on every page and frame the crawl
            opens. `accept` by default: it opts in, the way a visitor does to see
            the page, which matters on sites whose consent wall holds back the
            content until it is answered.

            `reject` opts out where the banner allows it -- some sites show less
            to a visitor who does. `none` leaves banners alone, on the page as
            they came. Free either way.
          schema:
            type: string
            enum: [accept, reject, none]
            default: accept
          example: reject
        - name: viewport
          in: query
          required: false
          description: |
            The window size, written `WIDTHxHEIGHT`. Both sides must be positive.
            Defaults to `1920x1080`.

            Required to use `device_scale_factor`, `mobile`, `landscape` or
            `touch`, which describe a viewport and are meaningless without one.
          schema:
            type: string
            pattern: '^[1-9][0-9]{0,4}x[1-9][0-9]{0,4}$'
            default: 1920x1080
          example: 390x844
        - name: device_scale_factor
          in: query
          required: false
          description: |
            The device pixel ratio, as a retina screen reports it. `3` for a
            recent phone. Requires `viewport`.
          schema:
            type: number
            minimum: 0.1
            maximum: 5
          example: 3
        - name: mobile
          in: query
          required: false
          description: |
            Tell the page it is on a phone. Requires `viewport`, and accepts the
            same spellings as `premium`.

            This changes the window metrics only. A site that decides what to
            serve from the user agent will still send its desktop page, so pair
            it with `user_agent`. And a page with no `<meta name="viewport">` tag
            falls back to a 980px layout viewport whatever width you asked for --
            standard browser behaviour rather than the setting being ignored.
          schema:
            type: string
            default: "false"
          example: "true"
        - name: landscape
          in: query
          required: false
          description: |
            Report the screen as landscape. Requires `viewport`, and accepts the
            same spellings as `premium`.
          schema:
            type: string
            default: "false"
          example: "false"
        - name: touch
          in: query
          required: false
          description: |
            Report the screen as touch capable. Requires `viewport`, and accepts
            the same spellings as `premium`.
          schema:
            type: string
            default: "false"
          example: "true"
        - name: user_agent
          in: query
          required: false
          description: |
            The user agent to send, replacing the one the crawler would otherwise
            present.
          schema:
            type: string
            maxLength: 512
          example: Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as a two-letter ISO 3166-1
            alpha-2 code (`es`, `us`, `de`). Case does not matter. Free, and it
            works on either proxy pool, so it can be combined with `premium`.

            Omit it to take whatever exit the pool picks.

            A country name is not accepted -- `spain` is a `422`, `es` is not.
            The pool reads the code out of the credentials it is given, so a name
            would have to be mapped to a code, and that mapping is a list of wrong
            answers waiting to be picked.

            Required to use `city`, which narrows a country rather than standing
            on its own.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: es
        - name: city
          in: query
          required: false
          description: |
            The city inside that country to appear to be browsing from, as the
            pool spells it. Case does not matter. **Requires `country`** -- a city
            on its own is a `422`, because the pool reads it as the segment after
            a country and not as a location of its own.

            **A city doubles what the crawl costs**, surcharges included: exits in
            one city are a far smaller pool than exits in a country. So
            `country=de&city=berlin` on the cheapest fetch is 2 credits rather than
            1, and on a premium rendered fetch carrying a question it is 60 rather
            than 30. `credits_charged` is always the figure that was taken.

            Letters, digits, hyphens and underscores only. A multi-word city is
            written the way the pool writes it -- `new_york`, not `new york` -- and
            anything carrying a `.` or a `;` is refused: those are the separators
            the pool parses its own targeting with.

            The `city` field of the response echoes the city actually targeted, so
            it is what to check rather than what was sent.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: berlin
        - name: output
          in: query
          required: false
          description: |
            How a finished page comes back.

            - `html` (default) -- the page itself as `text/html`, with what it
              cost in headers.
            - `json` -- the JSON envelope every time, the page's html in
              `content`, so there is only one shape to parse.
            - `markdown` -- the page converted to markdown, as `text/markdown`
              with the same headers. Scripts, styles and the `<head>` are
              dropped, and relative links and images are made absolute. The whole
              page is converted, navigation and footer included. Costs the same as `html`.

            Only the finished page is affected: a crawl that is still running or
            failed answers with the JSON envelope whichever is chosen.

            `markdown` with an `ai_query` is refused with a `422` before anything
            is charged: the answer to a question is `data`, not a page.
          schema:
            type: string
            enum: [html, json, markdown]
            default: html
          example: markdown
        - name: main_content
          in: query
          required: false
          description: |
            With `output=markdown` only: convert just the page's main block
            instead of the whole page. Refused with a `422`, before anything is
            charged, when it is on with any other `output`. Free.

            The page's furniture is removed first -- navigation, the page's own
            header and footer, sidebars, dialogs and cookie or consent banners.
            The main block is then the page's `<main>` (or `role="main"`), else
            whatever its "skip to content" link points at, else its only
            `<article>`, else what is left of the `<body>`. An
            article's own `<header>` and `<footer>` are kept: that is usually
            where its title is.

            When what that finds has almost no text -- an empty app shell, or
            content that sat inside something removed -- the whole page is
            converted instead, so a page is never cut down to nothing. Accepts
            the same spellings as `premium`.
          schema:
            type: string
            default: "false"
          example: "true"
        - name: key
          in: query
          required: false
          description: |
            The API key, for callers that cannot set a header. Accepted on this
            route only -- a key in a url is copied into access logs, proxy logs
            and `Referer` headers, which is a fair trade for a
            machine-to-machine endpoint and a bad one for anything else.
            Ignored when an `Authorization` header is present.
          schema:
            type: string
      responses:
        "200":
          description: |
            The crawl finished, and the body is the page itself -- `text/html`,
            with what it cost in headers, because a caller who asked for a url
            wants the document rather than a document escaped inside a field.
            With `output=markdown` it is the page as `text/markdown` with the
            same headers; with `output=json` it is the JSON envelope, the page in
            `content`.

            A crawl that finished without producing a page -- which is what an
            `ai_query` does -- answers the JSON envelope instead, with the answer
            in `data`. Branch on the content type rather than on the status code.

            One more rule for the same branch: a result that carries both a page
            and a picture of one comes back as JSON, with the page in `content`,
            rather than as a bare document that would drop the picture in
            silence. Nothing produces that pair today -- it is stated so the rule
            does not have to be guessed at if something does.
          headers:
            X-Crawl-Job-Id:
              description: The id this crawl ran under.
              schema:
                type: string
            X-Credits-Charged:
              description: |
                What this crawl cost. Sent with the `text/html` and
                `text/markdown` bodies only -- the JSON envelope carries the same
                figure in `credits_charged`.
              schema:
                type: integer
            X-Credits-Remaining:
              description: The organization's balance afterwards.
              schema:
                type: integer
          content:
            text/html:
              schema:
                type: string
                description: The page, verbatim.
            text/markdown:
              schema:
                type: string
                description: The page as markdown, with `output=markdown`.
            application/json:
              schema:
                $ref: "#/components/schemas/CrawlResult"
        "202":
          description: |
            Paid for and running. The runner gives up on waiting long before it
            gives up on crawling, so a slow page comes back as a job id rather
            than a result -- collect it from `/crawl/{job}`, which is free.

            The credits are already spent and the crawl already tallied: a `202`
            is a crawl that is happening, not one that might.
            With `debuga=1`, a timeout also shows you where the crawl had got to:
            `debug` carries the url the browser was on, a viewport screenshot and the page source
            at that moment. Null when there is nothing to show yet -- a crawl
            still in the queue has not opened a tab. It costs nothing.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CrawlResult"
              example:
                url: https://example.com/products?page=2
                domain: example.com
                premium: false
                js: true
                images: false
                city: null
                ai_query: ""
                credits_charged: 5
                credits_remaining: 995
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: running
                content: null
                data: null
                position: 0
                error: null
                debug:
                  url: https://example.com/products?page=2
                  screenshot: /9j/4AAQSkZJRgABAQ...
                  html: <!doctype html>...
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization --
            a signed-in dashboard user reaches this endpoint as a user and is
            refused here, since a user has no credits to spend.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                unauthenticated:
                  value:
                    message: Unauthenticated.
                notAnOrganization:
                  value:
                    message: This endpoint is reached with an organization API key.
        "402":
          description: The organization's balance will not cover the crawl. Nothing is charged and nothing is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This organization does not have enough credits for that crawl.
        "422":
          description: |
            The request did not validate. This includes a `url` whose domain does not
            resolve, which is refused before anything is charged or crawled.

            Also the answer when the crawl ran and the url turned out unreachable
            in a way no crawl could fix -- see `error_code`. That one has the crawl
            result's shape, with `credits_charged` at `0` and `error` saying why.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: "#/components/schemas/ValidationError"
                  - $ref: "#/components/schemas/CrawlResult"
              examples:
                validation:
                  value:
                    message: The url field is required.
                    errors:
                      url:
                        - The url field is required.
                unreachable:
                  value:
                    url: https://example.com:81/
                    domain: example.com
                    premium: false
                    js: true
                    images: false
                    city: null
                    ai_query: ""
                    credits_charged: 0
                    credits_remaining: 1000
                    job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                    status: failed
                    content: null
                    data: null
                    position: null
                    error: Port 81 on example.com is not reachable through the proxy.
                    error_code: port_blocked
        "500":
          description: |
            The crawler did not deliver. The charge is handed back --
            `credits_charged` is `0` and the balance is whole -- and no crawl is
            counted against the domain, though the attempt is recorded so a
            customer whose target has started refusing us can see that we tried.

            Reported as ours rather than as the caller's: the request was valid
            and paid for, and the crawler is part of this service rather than a
            third party they chose.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CrawlResult"
              example:
                url: https://example.com/products?page=2
                domain: example.com
                premium: false
                js: true
                images: false
                city: null
                ai_query: ""
                credits_charged: 0
                credits_remaining: 1000
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: failed
                content: null
                data: null
                position: null
                error: Navigation timeout of 30000 ms exceeded
        "503":
          description: |
            The crawl could not be routed. Every crawl goes out through a proxy
            pool, and the one this crawl's tier uses is not available -- a fault at
            our end rather than anything wrong with the request.

            Nothing is charged and nothing is recorded. The crawl is refused
            rather than sent out directly, because connecting without the pool
            would put our own address in front of the target under your name.
            Retrying is reasonable; the same request will work once the pool is
            back.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

    post:
      tags: [Crawl]
      summary: Run a recipe
      operationId: crawlRecipe
      description: |
        Runs a **recipe** -- a list of blocks the crawler executes against a page
        in order. This is the same endpoint as the `GET` above and the same work
        billed to the same balance; what differs is who writes the recipe. A `GET`
        names a url and some options and we build the blocks; here you send the
        blocks, which is the only way to reach the rest of what the crawler does:
        filling a form, paging through results, extracting fields.

        **The body is the recipe. The options stay in the query string** -- the
        same `premium`, `country`, `js` and the rest the `GET` takes, with the same
        meanings. A field in the body that is not `blocks`, `name` or
        `expectedOutput` is a `422` rather than an option.

        **Your first block says where to start, and that is all it is used for.**
        We read `blocks[0].details.source` and build the start block ourselves from
        the query string, so `waitUntil`, `adblock`, `cookiesBanner`,
        `javascript`, `images`, `viewport`, `userAgent` and the proxy are ours to
        set whatever your first block says. Blocks after the first are run as you
        wrote them.

        **30 credits, flat.** Neither the number of blocks nor `premium`,
        `country` or `city` changes it -- what a recipe costs to run is a browser
        session, which dwarfs the difference between fetching its first page one
        way or another. Those options still decide where the crawl exits, and
        against a target that refuses us they may decide whether it is let in at
        all; they simply no longer move the bill.

        The key goes in the `Authorization` header, or in `?key=` as on the `GET`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: premium
          in: query
          required: false
          description: |
            Fetch through the premium proxy pool instead of the standard one. Use
            it for targets that refuse ordinary requests. Unlike on the `GET`, it
            does not change the price.
          schema:
            type: boolean
            default: false
          example: false
        - name: js
          in: query
          required: false
          description: |
            Render the page's javascript. On by default, and worth leaving on for
            anything a recipe clicks or types into -- a block that waits for a
            selector a script would have written will not find it. Does not change
            the price here.
          schema:
            type: boolean
            default: true
          example: true
        - name: images
          in: query
          required: false
          description: |
            Download the images the page references. Off by default. Turn them on
            for a recipe that screenshots, and leave them off otherwise: an `<img>`
            tag is in the html whether or not the file behind it was fetched.
          schema:
            type: boolean
            default: false
          example: false
        - name: adblock
          in: query
          required: false
          description: |
            Block ads and trackers. On by default. See the `GET` for what it
            removes and why it is worth leaving on.
          schema:
            type: boolean
            default: true
          example: true
        - name: wait_until
          in: query
          required: false
          description: |
            When the first page counts as loaded, passed to the browser as-is.
            Defaults to `networkidle2`, which tolerates up to two open
            connections. A page that holds more open never goes idle, so
            `domcontentloaded` is the one to reach for there.
          schema:
            type: string
            enum: [load, domcontentloaded, networkidle0, networkidle2]
            default: networkidle2
          example: networkidle2
        - name: cookies_banner
          in: query
          required: false
          description: |
            How cookie banners are answered on the pages the recipe opens:
            `accept` (the default), `reject`, or `none` to leave them alone. See
            the `GET` for when each is the one to use.
          schema:
            type: string
            enum: [accept, reject, none]
            default: accept
          example: reject
        - name: viewport
          in: query
          required: false
          description: |
            The window size, as `WIDTHxHEIGHT`. Defaults to the crawler's
            `1920x1080`. Required to use `device_scale_factor`, `mobile`,
            `landscape` or `touch`.
          schema:
            type: string
            pattern: '^[1-9][0-9]{0,4}x[1-9][0-9]{0,4}$'
          example: 390x844
        - name: device_scale_factor
          in: query
          required: false
          description: The device pixel ratio. Requires `viewport`.
          schema:
            type: number
            minimum: 0.1
            maximum: 5
          example: 3
        - name: mobile
          in: query
          required: false
          description: Report the browser as a mobile device. Requires `viewport`.
          schema:
            type: boolean
          example: true
        - name: landscape
          in: query
          required: false
          description: Report the viewport as landscape. Requires `viewport`.
          schema:
            type: boolean
          example: false
        - name: touch
          in: query
          required: false
          description: Report the device as touch-capable. Requires `viewport`.
          schema:
            type: boolean
          example: true
        - name: user_agent
          in: query
          required: false
          description: The `User-Agent` to send. Defaults to the crawler's own.
          schema:
            type: string
            maxLength: 512
          example: Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as an ISO 3166-1 alpha-2
            code. Applies to both pools. Does not change the price here.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: es
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Letters, digits, hyphens and underscores only.

            Unlike on the `GET`, a city does not double what the crawl costs: the
            price here is flat.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: berlin
        - name: output
          in: query
          required: false
          description: |
            How a finished page comes back.

            - `html` (default) -- the page itself as `text/html`, with what it
              cost in headers.
            - `json` -- the JSON envelope every time, the page's html in
              `content`, so there is only one shape to parse.
            - `markdown` -- the page converted to markdown, as `text/markdown`
              with the same headers. Scripts, styles and the `<head>` are
              dropped, and relative links and images are made absolute. The whole
              page is converted, navigation and footer included. Costs the same as `html`.

            Only the finished page is affected: a crawl that is still running or
            failed answers with the JSON envelope whichever is chosen.

            `markdown` is refused with a `422` before anything is charged unless
            the recipe is the start block alone -- anything longer answers with
            `data`, not a page.
          schema:
            type: string
            enum: [html, json, markdown]
            default: html
          example: markdown
        - name: main_content
          in: query
          required: false
          description: |
            With `output=markdown` only: convert just the page's main block
            instead of the whole page. Refused with a `422`, before anything is
            charged, when it is on with any other `output`. Free.

            The page's furniture is removed first -- navigation, the page's own
            header and footer, sidebars, dialogs and cookie or consent banners.
            The main block is then the page's `<main>` (or `role="main"`), else
            whatever its "skip to content" link points at, else its only
            `<article>`, else what is left of the `<body>`. An
            article's own `<header>` and `<footer>` are kept: that is usually
            where its title is.

            When what that finds has almost no text -- an empty app shell, or
            content that sat inside something removed -- the whole page is
            converted instead, so a page is never cut down to nothing. Accepts
            the same spellings as `premium`.
          schema:
            type: string
            default: "false"
          example: "true"
        - name: key
          in: query
          required: false
          description: |
            The API key, for callers that cannot set a header. Ignored when an
            `Authorization` header is present.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Recipe"
            example:
              name: Products, page 2
              expectedOutput: list
              blocks:
                - type: start
                  details:
                    type: url
                    source: https://example.com/products
                - id: rows
                  type: extract
                  details:
                    selector: .product .title
                    name: title
                    property: textContent
                - type: paginate
                  details:
                    selector: .pagination .next
                    startBlock: rows
      responses:
        "200":
          description: |
            The recipe finished. What comes back depends on what it was: a recipe
            of one block -- just your start block -- is a request for the page, so
            the body is the page itself as `text/html` with the cost in headers
            (`text/markdown` with `output=markdown`, the JSON envelope with
            `output=json`). Anything longer extracted something, so the body is
            the JSON envelope with the result in `data`.

            Branch on the content type rather than on the status code.

            One more rule for the same branch: a result that carries both a page
            and a picture of one comes back as JSON, with the page in `content`,
            rather than as a bare document that would drop the picture in
            silence. Nothing produces that pair today -- it is stated so the rule
            does not have to be guessed at if something does.
          headers:
            X-Crawl-Job-Id:
              description: The id this crawl ran under.
              schema:
                type: string
            X-Credits-Charged:
              description: |
                What this cost. Sent with the `text/html` and `text/markdown`
                bodies only -- the JSON envelope carries the same figure in
                `credits_charged`.
              schema:
                type: integer
            X-Credits-Remaining:
              description: The organization's balance afterwards.
              schema:
                type: integer
          content:
            text/html:
              schema:
                type: string
                description: The page, verbatim.
            text/markdown:
              schema:
                type: string
                description: The page as markdown, with `output=markdown`.
            application/json:
              schema:
                $ref: "#/components/schemas/RecipeResult"
              example:
                url: https://example.com/products
                domain: example.com
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                content: null
                data:
                  - title: A product
                  - title: Another product
                position: null
                error: null
        "202":
          description: |
            Paid for and running. A recipe that runs longer than the crawler waits
            comes back as a job id -- collect it from `/crawl/{job}`, which is
            free. The credits are already spent: a `202` is a crawl that is
            happening, not one that might.
            With `debuga=1`, a timeout also shows you where the crawl had got to:
            `debug` carries the url the browser was on, a viewport screenshot and the page source
            at that moment. Null when there is nothing to show yet -- a crawl
            still in the queue has not opened a tab. It costs nothing.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RecipeResult"
              example:
                url: https://example.com/products
                domain: example.com
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: running
                content: null
                data: null
                position: 0
                error: null
                debug:
                  url: https://example.com/products
                  screenshot: /9j/4AAQSkZJRgABAQ...
                  html: <!doctype html>...
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization -- a
            signed-in dashboard user is refused here, since a user has no credits
            to spend.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                unauthenticated:
                  value:
                    message: Unauthenticated.
                notAnOrganization:
                  value:
                    message: This endpoint is reached with an organization API key.
        "402":
          description: The organization's balance will not cover the recipe. Nothing is charged and nothing is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This organization does not have enough credits for that request.
        "422":
          description: |
            The recipe did not validate. As well as the usual shape errors, this is
            the answer for a block type the crawler does not run, a `start` block
            anywhere but first, a `paginate` block naming an id no block carries,
            a field in the body that belongs in the query string, and a start url
            whose domain does not resolve -- refused before anything is charged.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
              example:
                message: Only the first block may be a start block. The crawl begins once, at the url it names.
                errors:
                  blocks.2.type:
                    - Only the first block may be a start block. The crawl begins once, at the url it names.
        "500":
          description: |
            The crawler did not deliver. The charge is handed back --
            `credits_charged` is `0` and the balance is whole -- and no crawl is
            counted against the domain, though the attempt is recorded.

            Note what this does not cover: a recipe that ran to the end and
            extracted nothing, because every selector missed, is a success. You
            paid for the browser session and got it. Check `data` rather than the
            status code for whether the recipe did what you meant.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RecipeResult"
              example:
                url: https://example.com/products
                domain: example.com
                credits_charged: 0
                credits_remaining: 1000
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: failed
                content: null
                data: null
                position: null
                error: Navigation timeout of 30000 ms exceeded
        "503":
          description: |
            The crawl could not be routed: the proxy pool this tier uses is not
            available. Nothing is charged. Retrying is reasonable.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

  /crawl/{job}:
    get:
      tags: [Crawl]
      summary: Collect a crawl
      operationId: crawlPoll
      description: |
        Collects a crawl that was still running when `/crawl` gave up waiting and
        answered `202`.

        Free, and it can be called as often as you like: the crawl was paid for
        when it was queued, and asking whether your own crawl has finished is not
        itself a crawl. Nothing is charged, no tally moves, and no daily limit
        applies.

        Ownership is proved by the id rather than looked up. A job id is the
        organization's own id and a uuid joined by an underscore, and the runner
        is never told who submitted what -- so an id that does not begin with the
        calling organization's id is refused without anything being read. That
        refusal is a `404`, the same answer an id that never existed gets: that
        somebody else's crawl exists is not this caller's business.

        The key goes in the `Authorization` header. Unlike `/crawl`, `?key=` is
        not accepted here.
      security:
        - apiKeyHeader: []
      parameters:
        - name: job
          in: path
          required: true
          description: |
            The `job_id` from the `202`, verbatim.
          schema:
            type: string
          example: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
        - name: output
          in: query
          required: false
          description: |
            How a finished page comes back.

            - `html` (default) -- the page itself as `text/html`, with what it
              cost in headers.
            - `json` -- the JSON envelope every time, the page's html in
              `content`, so there is only one shape to parse.
            - `markdown` -- the page converted to markdown, as `text/markdown`
              with the same headers. Scripts, styles and the `<head>` are
              dropped, and relative links and images are made absolute. The whole
              page is converted, navigation and footer included. Costs the same as `html`.

            Only the finished page is affected: a crawl that is still running or
            failed answers with the JSON envelope whichever is chosen.

            Nothing about a crawl is remembered on our side, so pass it again
            here: a crawl started with `output=markdown` comes back as html unless
            this says otherwise. Links are made absolute against the page's
            canonical url when it declares one, and left as written when not.
          schema:
            type: string
            enum: [html, json, markdown]
            default: html
          example: markdown
        - name: main_content
          in: query
          required: false
          description: |
            With `output=markdown` only: convert just the page's main block
            instead of the whole page. Refused with a `422`, before anything is
            charged, when it is on with any other `output`. Free.

            The page's furniture is removed first -- navigation, the page's own
            header and footer, sidebars, dialogs and cookie or consent banners.
            The main block is then the page's `<main>` (or `role="main"`), else
            whatever its "skip to content" link points at, else its only
            `<article>`, else what is left of the `<body>`. An
            article's own `<header>` and `<footer>` are kept: that is usually
            where its title is.

            When what that finds has almost no text -- an empty app shell, or
            content that sat inside something removed -- the whole page is
            converted instead, so a page is never cut down to nothing. Accepts
            the same spellings as `premium`.
          schema:
            type: string
            default: "false"
          example: "true"
      responses:
        "200":
          description: |
            The crawl has finished. As with `/crawl`, a page comes back as
            `text/html` -- or `text/markdown`, or inside the JSON envelope,
            depending on `output` -- and anything else -- the answer to an
            `ai_query`, say -- as the JSON envelope. Branch on the content type.

            No credit headers here, and no `credits_charged`: collecting costs
            nothing, so there is nothing to report.
          headers:
            X-Crawl-Job-Id:
              description: The id this crawl ran under.
              schema:
                type: string
          content:
            text/html:
              schema:
                type: string
                description: The page, verbatim.
            text/markdown:
              schema:
                type: string
                description: The page as markdown, with `output=markdown`.
            application/json:
              schema:
                $ref: "#/components/schemas/CrawlOutcome"
              example:
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                content: null
                data:
                  - price: "49.99 EUR"
                    availability: in_stock
                position: null
                error: null
        "202":
          description: |
            Still going. `position` says where it sits in the runner's queue
            while it is `queued`, and is null once it is `running`.

            With `debuga=1`, a running crawl also carries `debug`: the url, a viewport screenshot
            and the page source as they stood when this was asked. Polling again
            takes a fresh look, so it is how to watch a slow crawl rather than
            wait blind on it. Collecting is free, and so is looking.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CrawlOutcome"
              example:
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: queued
                content: null
                data: null
                position: 2
                error: null
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "404":
          description: |
            No such crawl -- an id that never existed, or one belonging to
            another organization. The two are deliberately indistinguishable.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: No such crawl.
        "500":
          description: |
            The crawl failed after it had been accepted.

            Nothing is refunded. The charge was taken when the crawl was queued,
            and only a crawl that fails at `/crawl` itself -- before any work was
            done -- is handed back. `error` says what went wrong.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CrawlOutcome"
              example:
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: failed
                content: null
                data: null
                position: null
                error: Navigation timeout of 30000 ms exceeded

  /chatgpt:
    get:
      tags: [ChatGPT]
      summary: Ask ChatGPT
      operationId: chatgpt
      description: |
        Puts a question to ChatGPT and returns the answer as structured JSON.

        The crawler does the asking: it opens ChatGPT, types the prompt into the
        composer, waits for the streamed answer and converts it into nodes --
        paragraphs, headings, lists, tables, product lists, each keeping the
        citations ChatGPT showed. There is no API key of yours involved anywhere,
        and no model of ours: this drives the website.

        **30 credits, flat.** Unlike `/crawl`, nothing changes that -- `premium`,
        `country` and `city` still choose where the crawl exits, and for this
        target that may well decide whether it is let in at all, but they do not
        move the price. What this costs is a browser held open for up to two
        minutes rather than a page's worth of bytes.

        Always JSON, never `text/html`. There is nothing to branch on here.

        The key goes in the `Authorization` header, or in `?key=` as on `/crawl`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: prompt
          in: query
          required: true
          description: |
            The question, up to 1000 characters.

            The limit is not arbitrary. The prompt is typed one character at a
            time, so a thousand characters is already half a minute of typing
            before ChatGPT starts to think -- against a crawler that waits about
            two and a half minutes for the whole job.
          schema:
            type: string
            maxLength: 1000
          example: elon musk
        - name: premium
          in: query
          required: false
          description: |
            Ask through the premium proxy pool rather than the standard one. **On
            by default**, because the standard pool is the one ChatGPT turns away;
            send `false` to use the standard pool. Free either way, unlike on
            `/crawl` -- the price is flat.

            Sent as text in a query string, so the spellings a person would reach
            for all work: `true`, `false`, `1`, `0`, `yes`, `no`, `on`, `off`, in
            any case. Anything that is not a yes or a no is refused rather than
            quietly read as `false`.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be asking from, as a two-letter ISO 3166-1
            alpha-2 code. Free, and it changes what ChatGPT answers as much as it
            changes anything -- a question about prices asked from Germany is not
            the same question.

            Required to use `city`.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: de
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Free here, where on `/crawl` it doubles the price.

            Letters, digits, hyphens and underscores only; a multi-word city is
            written `new_york`.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: berlin
        - name: key
          in: query
          required: false
          description: |
            The API key, as an alternative to the `Authorization` header. Ignored
            when a header is present. A key in a url is copied into access logs,
            proxy logs and `Referer` headers, which is a fair trade for a
            machine-to-machine endpoint and a bad one for anything else.
          schema:
            type: string
      responses:
        "200":
          description: |
            ChatGPT answered. `conversation` holds the exchange: your prompt, then
            the answer as a list of nodes.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ChatGptResult"
              example:
                prompt: elon musk
                conversation:
                  - role: user
                    message: elon musk
                  - role: assistant
                    response:
                      - type: paragraph
                        text: Elon Musk is a businessman known for Tesla and SpaceX.
                        sources:
                          - attribution: Reuters
                            url: https://example.com/article
                      - type: heading
                        level: 2
                        text: Companies
                      - type: bullet_list
                        items:
                          - text: Tesla
                          - text: SpaceX
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                error: null
        "202":
          description: |
            Paid for and still going. A long prompt can outlast the crawler's
            patience for waiting, though not its patience for working.

            Collect it from `/crawl/{job}` -- the same endpoint a slow crawl is
            collected from, and free in the same way. One difference worth knowing:
            that endpoint answers the crawl envelope, so the answer arrives under
            `data.conversation` rather than lifted into `conversation` the way
            it is here.
            With `debuga=1`, a prompt that is still running also carries `debug`: the url, a
            viewport screenshot and the page source as they stood when the
            crawler stopped waiting, so a slow prompt shows the chat as it was
            rather than nothing at all. Null once it finishes -- the tab is gone
            by then. It costs nothing.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ChatGptResult"
              example:
                prompt: elon musk
                conversation: []
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: running
                position: null
                error: null
                debug:
                  url: https://chatgpt.com/
                  screenshot: /9j/4AAQSkZJRgABAQ...
                  html: <!doctype html>...
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no prompt, a prompt over the limit, a city with
            no country, or a flag that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            Nothing came back. Either the crawl failed outright, or ChatGPT did not
            answer within its timeout -- which reads as an empty `conversation` and
            an `error` saying so.

            **The credits are refunded either way**, so `credits_charged` is `0`.
            The attempt is still recorded against `chatgpt.com`, so a customer can
            see that we tried.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ChatGptResult"
              example:
                prompt: elon musk
                conversation: []
                credits_charged: 0
                credits_remaining: 1000
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                error: ChatGPT did not answer in time. Nothing was charged.

  /screenshot:
    get:
      tags: [Screenshot]
      summary: Screenshot a url
      operationId: screenshot
      description: |
        Takes a full-page screenshot of a url and returns it as base64 JPEG.

        The same request as `/crawl` -- the same url, the same fetch options, the
        same `ai_query` -- answered with a picture of the page instead of its
        html. The crawler loads the page exactly as it would for a crawl, then
        photographs the whole of it: not the viewport, the entire scroll height.

        **30 credits, flat.** Unlike `/crawl`, none of the options change that.
        `premium`, `js`, `country` and `city` still choose how the page is fetched
        and where the crawl exits, `images` and `ai_query` still cost nothing
        extra, and a city does not double the bill. What this costs is a browser
        laying out, scrolling and encoding a whole page rather than a page's worth
        of bytes.

        Two things to know before the first call. **`images` is on by default
        here**, against off on `/crawl`, because a page photographed without its
        pictures has empty boxes where they should be. And the response can be
        large: a long page runs to several megabytes and base64 adds about a third
        on top, so a tall target is worth a `viewport` and a thought about
        timeouts.

        Always JSON, never `text/html`. There is nothing to branch on here.

        The key goes in the `Authorization` header, or in `?key=` as on `/crawl`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: url
          in: query
          required: true
          description: The page to photograph. Must be `http` or `https` and must have a host.
          schema:
            type: string
            format: uri
            maxLength: 2048
          example: https://example.com/products?page=2
        - name: premium
          in: query
          required: false
          description: |
            Fetch through the premium proxy pool instead of the standard one.
            Free here, unlike on `/crawl` -- the price is flat -- and worth trying
            for targets that refuse ordinary requests.

            Every crawl is proxied either way -- this chooses which pool, not
            whether there is one. `country` works on both.

            Sent as text in a query string, so the spellings a person would
            reach for all work: `true`, `false`, `1`, `0`, `yes`, `no`, `on`,
            `off`, in any case. Anything that is not a yes or a no is refused
            rather than quietly read as `false`.
          schema:
            type: string
            default: "false"
          example: "false"
        - name: js
          in: query
          required: false
          description: |
            Render javascript before taking the picture. On by default, because
            it is what works on most of the web. Free here, unlike on `/crawl`.
            Accepts the same spellings as `premium`.

            Off, the page is photographed as the server delivered it: scripts are
            neither run nor even downloaded, along with anything they would have
            requested. That is faster, and on most of the modern web it is a
            picture of an unfinished page -- a client-rendered site photographs
            blank, and it is still charged for. Turn it off only for a target you
            know is served finished.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: images
          in: query
          required: false
          description: |
            Download the images on the page. **On by default here**, which is
            the opposite of `/crawl` and the only parameter the two endpoints
            disagree about: what comes back is a picture of the page, and a page
            photographed without its pictures has empty boxes where they should
            be. Free either way -- the 2-credit surcharge `/crawl` charges for
            these does not apply to a flat price.

            Turning them off is supported for the caller who wants exactly that:
            image requests are then aborted before they leave the browser while
            everything else -- HTML, CSS, scripts, XHR -- still loads, so the page
            lays out normally and photographs faster, with holes in it. On a test
            page the difference measured 422 KB against 166 KB.

            Stacks with `adblock`, which blocks a different set of requests.

            Accepts the same spellings as `premium`.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: ai_query
          in: query
          required: false
          description: |
            A question to answer about the page, put to a model once the page
            has loaded and before the picture is taken. Free here, where `/crawl`
            charges 5 credits for it -- the price is flat. An empty value is the
            same as asking nothing.

            The answer comes back under `data`, beside the image rather than
            instead of it.
          schema:
            type: string
            maxLength: 1000
          example: What is the price?
        - name: adblock
          in: query
          required: false
          description: |
            Drop ads and trackers before the page loads, using the EasyList
            filters. **On by default**, and free either way -- it changes nothing
            about the price.

            Ad and tracker payloads dominate a typical retail page, and blocking
            them cuts what has to be downloaded by around 80% while leaving the
            page's own assets untouched, so this is the right default for almost
            every target. What it also removes is anything an ad or analytics
            script would have written into the document -- a tracking pixel's
            payload, a `dataLayer` an ad tag populates. Send `adblock=false` if
            that is what you came for.

            Accepts the same spellings as `premium`.
          schema:
            type: string
            default: "true"
          example: "false"
        - name: wait_until
          in: query
          required: false
          description: |
            When the page counts as loaded. `networkidle2` by default -- it waits
            until no more than two connections are left open, which returns a
            finished page without hanging on a beacon or a poll that never stops.

            Use `networkidle0` to wait for complete silence, or
            `domcontentloaded` or `load` for a page that keeps several
            connections open (sockets, polls, analytics), where waiting for the
            network means waiting until the crawl times out.
          schema:
            type: string
            enum: [load, domcontentloaded, networkidle0, networkidle2]
            default: networkidle2
          example: networkidle2
        - name: cookies_banner
          in: query
          required: false
          description: |
            How cookie banners are answered, on every page and frame the crawl
            opens. `accept` by default: it opts in, the way a visitor does to see
            the page, which matters on sites whose consent wall holds back the
            content until it is answered.

            `reject` opts out where the banner allows it -- some sites show less
            to a visitor who does. `none` leaves banners alone, on the page as
            they came. Free either way.
          schema:
            type: string
            enum: [accept, reject, none]
            default: accept
          example: reject
        - name: viewport
          in: query
          required: false
          description: |
            The window size, written `WIDTHxHEIGHT`. Both sides must be positive.
            Defaults to `1920x1080`.

            Required to use `device_scale_factor`, `mobile`, `landscape` or
            `touch`, which describe a viewport and are meaningless without one.
          schema:
            type: string
            pattern: '^[1-9][0-9]{0,4}x[1-9][0-9]{0,4}$'
            default: 1920x1080
          example: 390x844
        - name: device_scale_factor
          in: query
          required: false
          description: |
            The device pixel ratio, as a retina screen reports it. `3` for a
            recent phone. Requires `viewport`.
          schema:
            type: number
            minimum: 0.1
            maximum: 5
          example: 3
        - name: mobile
          in: query
          required: false
          description: |
            Tell the page it is on a phone. Requires `viewport`, and accepts the
            same spellings as `premium`.

            This changes the window metrics only. A site that decides what to
            serve from the user agent will still send its desktop page, so pair
            it with `user_agent`. And a page with no `<meta name="viewport">` tag
            falls back to a 980px layout viewport whatever width you asked for --
            standard browser behaviour rather than the setting being ignored.
          schema:
            type: string
            default: "false"
          example: "true"
        - name: landscape
          in: query
          required: false
          description: |
            Report the screen as landscape. Requires `viewport`, and accepts the
            same spellings as `premium`.
          schema:
            type: string
            default: "false"
          example: "false"
        - name: touch
          in: query
          required: false
          description: |
            Report the screen as touch capable. Requires `viewport`, and accepts
            the same spellings as `premium`.
          schema:
            type: string
            default: "false"
          example: "true"
        - name: user_agent
          in: query
          required: false
          description: |
            The user agent to send, replacing the one the crawler would otherwise
            present.
          schema:
            type: string
            maxLength: 512
          example: Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as a two-letter ISO 3166-1
            alpha-2 code (`es`, `us`, `de`). Case does not matter. Free, and it
            works on either proxy pool, so it can be combined with `premium`.

            Omit it to take whatever exit the pool picks.

            A country name is not accepted -- `spain` is a `422`, `es` is not.
            The pool reads the code out of the credentials it is given, so a name
            would have to be mapped to a code, and that mapping is a list of wrong
            answers waiting to be picked.

            Required to use `city`, which narrows a country rather than standing
            on its own.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: es
        - name: city
          in: query
          required: false
          description: |
            The city inside that country to appear to be browsing from, as the
            pool spells it. Case does not matter. **Requires `country`** -- a city
            on its own is a `422`, because the pool reads it as the segment after
            a country and not as a location of its own.

            Free here, where on `/crawl` it doubles the price: this endpoint is
            flat. Worth knowing that it is the slowest option to serve -- exits in
            one city are a far smaller pool than exits in a country.

            Letters, digits, hyphens and underscores only. A multi-word city is
            written the way the pool writes it -- `new_york`, not `new york` -- and
            anything carrying a `.` or a `;` is refused: those are the separators
            the pool parses its own targeting with.

            Unlike `/crawl`, this endpoint does not echo the city back: there is
            no price for it to explain.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: berlin
        - name: key
          in: query
          required: false
          description: |
            The API key, for callers that cannot set a header. Accepted on the
            metered routes only -- a key in a url is copied into access logs,
            proxy logs and `Referer` headers, which is a fair trade for a
            machine-to-machine endpoint and a bad one for anything else.
            Ignored when an `Authorization` header is present.
          schema:
            type: string
      responses:
        "200":
          description: |
            The picture was taken. `screenshot` holds it: base64, JPEG, full page.

            Decode it as it stands -- there is no `data:` prefix and no padding to
            strip:

            ```
            curl -s -H "Authorization: Bearer $KEY" \
              "https://irmu.ddev.site/api/screenshot?url=https://example.com" \
              | jq -r .screenshot | base64 -d > shot.jpg
            ```
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ScreenshotResult"
              example:
                url: https://example.com/
                domain: example.com
                screenshot: /9j/4AAQSkZJRgABAQEAYABgAAD...
                ai_query: ""
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                data:
                  url: https://example.com/
                position: null
                error: null
        "202":
          description: |
            Paid for and still going. A tall page, or one that is slow to settle,
            can outlast the crawler's patience for waiting -- though not its
            patience for working.

            Collect it from `/crawl/{job}`, the same endpoint a slow crawl is
            collected from, and free in the same way. One difference worth
            knowing: that endpoint answers the crawl envelope, so the image
            arrives under `data.screenshots[0]` rather than lifted into
            `screenshot` the way it is here.

            With `debuga=1`, a running crawl also carries `debug`, and its picture is not the one
            you paid for: it is a viewport thumbnail off the live tab, showing
            where the crawl had got to. `screenshot` stays null until the
            full-page image exists. Null once it finishes, and free either way.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ScreenshotResult"
              example:
                url: https://example.com/
                domain: example.com
                screenshot: null
                ai_query: ""
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: running
                data: null
                position: 2
                error: null
                debug:
                  url: https://example.com/
                  screenshot: /9j/4AAQSkZJRgABAQ...
                  html: <!doctype html>...
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no url, a url that is not `http`/`https`, a city
            with no country, a `viewport` that is not `WIDTHxHEIGHT`, or a flag
            that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            No picture came back. Either the crawl failed outright, or it finished
            without producing an image -- which reads as a null `screenshot` and an
            `error` saying so.

            **The credits are refunded either way**, so `credits_charged` is `0`.
            The attempt is still recorded against the domain, so a customer can
            see that we tried.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ScreenshotResult"
              example:
                url: https://example.com/
                domain: example.com
                screenshot: null
                ai_query: ""
                credits_charged: 0
                credits_remaining: 1000
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                data:
                  url: https://example.com/
                position: null
                error: The crawler took no screenshot of that page. Nothing was charged.
        "503":
          description: |
            The crawl could not be routed through a proxy pool. Nothing is
            charged. The request was fine and will be fine again once the pool is
            configured.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

  /booking/search:
    get:
      tags: [Booking]
      summary: Search Booking.com
      operationId: bookingSearch
      description: |
        Searches Booking.com for places to stay and returns the properties on
        the first page of results, one row per property card.

        You name a destination and, optionally, a stay; the search url is built
        from them. Results are always read from the English site, because the
        recipe that reads them reads English labels.

        Every field of a row is text as Booking prints it -- `price` is
        `"€ 120"`, `reviewScore` is `"8.7"` -- and a field the card does not
        show is absent from its row.

        **30 credits, flat.** `premium`, `country` and `city` choose where the
        crawl exits, not what it costs. A search that finds nothing is still
        charged for: it is Booking's answer, and an empty `hotels` with `status`
        `done` is how it reads.

        The key goes in the `Authorization` header, or in `?key=`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: destination
          in: query
          required: true
          description: |
            Where to stay, as you would type it into Booking's search box -- a
            city, a region, a landmark. Up to 200 characters.
          schema:
            type: string
            maxLength: 200
          example: Rome
        - name: checkin
          in: query
          required: false
          description: |
            The first night, as `YYYY-MM-DD`, today or later. **Requires
            `checkout`.**

            Optional: without dates Booking still shows the page, it just prices
            nothing.
          schema:
            type: string
            format: date
          example: "2026-11-11"
        - name: checkout
          in: query
          required: false
          description: The day you leave, as `YYYY-MM-DD`, after `checkin`. **Requires `checkin`.**
          schema:
            type: string
            format: date
          example: "2026-11-12"
        - name: adults
          in: query
          required: false
          description: How many adults are staying.
          schema:
            type: integer
            minimum: 1
            maximum: 30
            default: 2
        - name: rooms
          in: query
          required: false
          description: How many rooms they need.
          schema:
            type: integer
            minimum: 1
            maximum: 30
            default: 1
        - name: currency
          in: query
          required: false
          description: |
            The currency to price in, as a three-letter ISO 4217 code. Left to
            Booking when absent, which usually means the currency of the country
            the crawl exits from.
          schema:
            type: string
            minLength: 3
            maxLength: 3
            pattern: '^[A-Za-z]{3}$'
          example: EUR
        - name: premium
          in: query
          required: false
          description: |
            Go through the premium proxy pool rather than the standard one. **On
            by default**, because the standard pool is the one Booking turns away;
            send `false` to use the standard pool. Free either way, unlike on
            `/crawl` -- the price is flat.

            `true`, `false`, `1`, `0`, `yes`, `no`, `on`, `off`, in any case.
            Anything else is refused rather than read as `false`.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as a two-letter ISO 3166-1
            alpha-2 code. Free. Booking prices and ranks by where you are, so this
            can change the answer.

            Required to use `city`.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: it
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Free here, where on `/crawl` it doubles the price.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: rome
        - name: key
          in: query
          required: false
          description: |
            The API key, as an alternative to the `Authorization` header. Ignored
            when a header is present.
          schema:
            type: string
      responses:
        "200":
          description: The properties the search found.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BookingSearchResult"
              example:
                url: https://www.booking.com/searchresults.en-gb.html?ss=Rome&checkin=2026-11-11&checkout=2026-11-12&group_adults=2&no_rooms=1&group_children=0
                destination: Rome
                checkin: "2026-11-11"
                checkout: "2026-11-12"
                adults: 2
                rooms: 1
                currency: null
                hotels:
                  - name: Hotel Artemide
                    url: https://www.booking.com/hotel/it/artemide.en-gb.html
                    image: https://cf.bstatic.com/xdata/images/hotel/square240/1.jpg
                    price: € 212
                    priceInfo: 1 night, 2 adults
                    taxes: +€ 12 taxes and charges
                    address: Termini, Rome
                    distance: 1.2 km from centre
                    reviewScore: "9.1"
                    reviewWord: Wonderful
                    reviewCount: 3,214 reviews
                    stars: 4 out of 5 Property rating
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: null
        "202":
          description: |
            Paid for and still going. Collect it from `/crawl/{job}`, free, as a
            slow crawl is collected. That endpoint answers the crawl envelope, so
            what is lifted into `hotels` here arrives under `data` there.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BookingSearchResult"
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no destination, one date without the other, dates in the past, or a flag that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            The crawl failed outright. A search that ran and found nothing is not
            this: it is a `200` with an empty `hotels`.

            **The credits are refunded**, so `credits_charged` is `0`. The attempt
            is still recorded against `www.booking.com`.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BookingSearchResult"
              example:
                url: https://www.booking.com/searchresults.en-gb.html?ss=Rome&group_adults=2&no_rooms=1&group_children=0
                destination: Rome
                checkin: null
                checkout: null
                adults: 2
                rooms: 1
                currency: null
                hotels: []
                credits_charged: 0
                credits_remaining: 1000
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: failed
                position: null
                debug: null
                error: Navigation timeout of 60000 ms exceeded
        "503":
          description: |
            The crawl could not be routed through a proxy pool. Nothing is
            charged.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

  /booking/hotel:
    get:
      tags: [Booking]
      summary: Read a Booking.com property
      operationId: bookingHotel
      description: |
        Reads one Booking.com property page into a single object, with the parts
        Booking prints as blobs resolved into values: `price` and each room's
        prices as `{ amount, currency, original, discount }`, `rating` as
        `{ score, word, count }`, `facilities` grouped as the page groups them.
        Beside those come the lists the page carries as text -- points of
        interest, review subscores, featured reviews, questions, sections.

        Room prices only exist for a stay, so send `checkin` and `checkout` to
        get them. The url's own query string is ignored: the stay goes in this
        endpoint's parameters, and the page is always read in English.

        **30 credits, flat.** A page that could not be read -- usually Booking's
        challenge page -- is not charged for.

        The key goes in the `Authorization` header, or in `?key=`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: url
          in: query
          required: true
          description: |
            A Booking.com property page, `https://www.booking.com/hotel/<country>/<name>.html`,
            in any language. Anything else is refused.
          schema:
            type: string
            format: uri
            maxLength: 2048
          example: https://www.booking.com/hotel/it/relais-la-maison-de-luxe-b-b.html
        - name: checkin
          in: query
          required: false
          description: |
            The first night, as `YYYY-MM-DD`, today or later. **Requires
            `checkout`.**

            Optional: without dates Booking still shows the page, it just prices
            nothing.
          schema:
            type: string
            format: date
          example: "2026-11-11"
        - name: checkout
          in: query
          required: false
          description: The day you leave, as `YYYY-MM-DD`, after `checkin`. **Requires `checkin`.**
          schema:
            type: string
            format: date
          example: "2026-11-12"
        - name: adults
          in: query
          required: false
          description: How many adults are staying.
          schema:
            type: integer
            minimum: 1
            maximum: 30
            default: 2
        - name: rooms
          in: query
          required: false
          description: How many rooms they need.
          schema:
            type: integer
            minimum: 1
            maximum: 30
            default: 1
        - name: currency
          in: query
          required: false
          description: |
            The currency to price in, as a three-letter ISO 4217 code. Left to
            Booking when absent, which usually means the currency of the country
            the crawl exits from.
          schema:
            type: string
            minLength: 3
            maxLength: 3
            pattern: '^[A-Za-z]{3}$'
          example: EUR
        - name: premium
          in: query
          required: false
          description: |
            Go through the premium proxy pool rather than the standard one. **On
            by default**, because the standard pool is the one Booking turns away;
            send `false` to use the standard pool. Free either way, unlike on
            `/crawl` -- the price is flat.

            `true`, `false`, `1`, `0`, `yes`, `no`, `on`, `off`, in any case.
            Anything else is refused rather than read as `false`.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as a two-letter ISO 3166-1
            alpha-2 code. Free. Booking prices and ranks by where you are, so this
            can change the answer.

            Required to use `city`.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: it
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Free here, where on `/crawl` it doubles the price.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: rome
        - name: key
          in: query
          required: false
          description: |
            The API key, as an alternative to the `Authorization` header. Ignored
            when a header is present.
          schema:
            type: string
      responses:
        "200":
          description: The property.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BookingHotelResult"
              example:
                url: https://www.booking.com/hotel/it/relais-la-maison-de-luxe-b-b.en-gb.html?checkin=2026-11-11&checkout=2026-11-12&group_adults=2&no_rooms=1&group_children=0
                checkin: "2026-11-11"
                checkout: "2026-11-12"
                adults: 2
                rooms: 1
                currency: null
                hotel:
                  name: Relais La Maison de Luxe B&B
                  address:
                    "@type": PostalAddress
                    streetAddress: Via Nazionale 10
                    addressLocality: Rome
                    addressCountry: IT
                  description: Set in Rome, 600 metres from Termini...
                  rating:
                    score: 8.7
                    word: Fabulous
                    count: 426
                  price:
                    amount: 112
                    currency: EUR
                    original: 140
                    discount: 28
                  rooms:
                    - name: Double Room
                      prices:
                        - amount: 112
                          currency: EUR
                          original: 140
                          discount: 28
                  facilities:
                    - group: Internet
                      items: [Free WiFi]
                  images:
                    - https://cf.bstatic.com/xdata/images/hotel/max1024x768/1.jpg
                  pointsOfInterest: [Termini 600 m]
                  reviewSubscores: [Staff 9.2]
                  reviews: ["Great location and very clean."]
                  questions: ["Is breakfast included?"]
                  sections: ["Property surroundings..."]
                  url: https://www.booking.com/hotel/it/relais-la-maison-de-luxe-b-b.en-gb.html?checkin=2026-11-11&checkout=2026-11-12&group_adults=2&no_rooms=1&group_children=0
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: null
        "202":
          description: |
            Paid for and still going. Collect it from `/crawl/{job}`, free, as a
            slow crawl is collected. That endpoint answers the crawl envelope, so
            what is lifted into `hotel` here arrives under `data` there.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BookingHotelResult"
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no url, a url that is not a Booking.com property page, one date without the other, dates in the past, or a flag that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            Nothing came back: the crawl failed outright, or every block ran and
            found nothing -- Booking's challenge page, or a layout the recipe no
            longer matches.

            **The credits are refunded either way**, so `credits_charged` is `0`.
            The attempt is still recorded against `www.booking.com`.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BookingHotelResult"
              example:
                url: https://www.booking.com/hotel/it/relais-la-maison-de-luxe-b-b.en-gb.html?group_adults=2&no_rooms=1&group_children=0
                checkin: null
                checkout: null
                adults: 2
                rooms: 1
                currency: null
                hotel: null
                credits_charged: 0
                credits_remaining: 1000
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: The crawler could not read that property page. Nothing was charged.
        "503":
          description: |
            The crawl could not be routed through a proxy pool. Nothing is
            charged.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

  /tripadvisor/search:
    get:
      tags: [Tripadvisor]
      summary: Search Tripadvisor hotels
      operationId: tripadvisorSearch
      description: |
        Searches Tripadvisor for hotels and returns the ones listed, one row per
        hotel card, with rating, subratings, ranking, price, amenities and the
        review the card quotes.

        Tripadvisor keeps a search on the page rather than in the url, so the
        crawler runs it the way a visitor would: it types the destination into
        the search, picks the dates, sets rooms and guests, ticks the filters,
        enters the price range and chooses the sort, in that order. Everything
        but `destination` is optional, and **a parameter you leave out leaves
        the page as it is** rather than applying a default of ours.

        A step that cannot be applied -- a filter this destination does not
        offer, say -- is skipped and the list is read anyway, so a list broader
        than you asked for means a step did not take.

        Hotels listed after the matches end -- around the destination, or
        missing a filter -- are kept, with `nearby: true`. Sponsored cards are
        kept too, once each, with `sponsored: true` and no `position`.

        **30 credits per page of results** asked for in `max_pages`, so 30 by
        default. `premium`, `country` and `city` choose where the crawl exits,
        not what it costs. A search that finds nothing is still charged for: it
        is Tripadvisor's answer, and an empty `hotels` with `status` `done` is
        how it reads.

        The key goes in the `Authorization` header, or in `?key=`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: destination
          in: query
          required: true
          description: |
            Where to stay, as you would type it into Tripadvisor's search. The
            first suggestion that starts with it is taken -- not "Nearby", and
            not a sponsored place.
          schema:
            type: string
            maxLength: 200
          example: Sabadell
        - name: checkin
          in: query
          required: false
          description: |
            The first night, as `YYYY-MM-DD`, today or later. **Requires
            `checkout`.**

            Optional: without dates Tripadvisor still lists the hotels, it just
            prices them for no stay in particular. With them, `price` is for the
            stay, and a hotel with no rate for it has none.
          schema:
            type: string
            format: date
          example: "2026-11-24"
        - name: checkout
          in: query
          required: false
          description: The day you leave, as `YYYY-MM-DD`, after `checkin`. **Requires `checkin`.**
          schema:
            type: string
            format: date
          example: "2026-11-28"
        - name: rooms
          in: query
          required: false
          description: How many rooms. Left as the page has it when absent.
          schema:
            type: integer
            minimum: 1
            maximum: 8
          example: 1
        - name: adults
          in: query
          required: false
          description: How many adults. Left as the page has it when absent.
          schema:
            type: integer
            minimum: 1
            maximum: 32
          example: 2
        - name: children
          in: query
          required: false
          description: How many children. Their ages are not set.
          schema:
            type: integer
            minimum: 0
            maximum: 20
          example: 0
        - name: filters
          in: query
          required: false
          description: |
            Filters to tick, named the way the page prints them -- `Pets
            Allowed`, `3 Star`, `Budget` -- or by the value on their checkbox,
            such as `amenity:9167`. Comma-separated, or repeated as `filters[]=`.
            Up to 20.

            Which filters a list offers depends on the destination, so one it
            does not offer is skipped rather than refused.
          schema:
            type: string
          example: Pets Allowed,3 Star
        - name: price_min
          in: query
          required: false
          description: |
            The lowest nightly price, in the currency the page shows (US dollars
            on the English site).
          schema:
            type: integer
            minimum: 0
          example: 50
        - name: price_max
          in: query
          required: false
          description: |
            The highest nightly price, at least `price_min`. One past the end of
            Tripadvisor's slider means no upper bound.
          schema:
            type: integer
            minimum: 1
          example: 150
        - name: sort
          in: query
          required: false
          description: |
            How the list is ordered: `best_value`, `traveler_ranked`, `price`
            (low to high) or `distance` (to the city center). Left as the page
            has it when absent.
          schema:
            type: string
            enum: [best_value, traveler_ranked, price, distance]
          example: traveler_ranked
        - name: max_pages
          in: query
          required: false
          description: |
            How many pages of results to read, through "Next page". **Each one
            is 30 credits**, charged for when the crawl starts whether or not the
            list turns out to have that many.
          schema:
            type: integer
            minimum: 1
            maximum: 5
            default: 1
          example: 2
        - name: premium
          in: query
          required: false
          description: |
            Go through the premium proxy pool rather than the standard one. **On
            by default**, because Tripadvisor sits behind DataDome, which turns
            the standard pool away; send `false` to use the standard pool. Free
            either way.

            `true`, `false`, `1`, `0`, `yes`, `no`, `on`, `off`, in any case.
            Anything else is refused rather than read as `false`.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as a two-letter ISO 3166-1
            alpha-2 code. Free.

            Required to use `city`.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: es
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Free here, where on `/crawl` it doubles the price.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: barcelona
        - name: key
          in: query
          required: false
          description: |
            The API key, as an alternative to the `Authorization` header. Ignored
            when a header is present.
          schema:
            type: string
      responses:
        "200":
          description: The hotels.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TripadvisorSearchResult"
              example:
                url: https://www.tripadvisor.com/Hotels-g227870-Sabadell_Catalonia-Hotels.html
                destination: Sabadell
                checkin: "2026-11-24"
                checkout: "2026-11-28"
                rooms: 1
                adults: 2
                children: null
                filters: [Pets Allowed, 3 Star]
                price_min: 50
                price_max: 150
                sort: traveler_ranked
                max_pages: 1
                hotels:
                  - position: 3
                    name: Catalonia Sabadell
                    url: https://www.tripadvisor.com/Hotel_Review-g227870-d284272-Reviews-Catalonia_Sabadell-Sabadell_Catalonia.html
                    id: "284272"
                    geoId: "227870"
                    rating: 3.7
                    reviewCount: 554
                    ratingWord: Average
                    subratings: { Location: 4.1, Cleanliness: 4, Service: 4.1, Value: 3.7 }
                    stars: 4
                    ranking: { text: "#3 Best Value of 20 places to stay in Sabadell", position: 3, total: 20 }
                    price: { amount: 112, currency: USD }
                    amenities: [Restaurant, Bar/Lounge, Free Wifi]
                    badges: [Breakfast included]
                    tags: [Fully refundable]
                    roomsLeft: 2
                    image: https://dynamic-media-cdn.tripadvisor.com/media/photo-o/1.jpg
                    review: { author: Alejandro M, text: "Very good infrastructure. Comfy room..." }
                    sponsored: false
                    nearby: false
                    page: 1
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: null
        "202":
          description: |
            Paid for and still going. Collect it from `/crawl/{job}`, free, as a
            slow crawl is collected. That endpoint answers the crawl envelope, so
            what is lifted into `hotels` here arrives under `data` there.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TripadvisorSearchResult"
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no destination, one date without the other, dates in the past, a `price_max` under the `price_min`, a sort that is not one of the four, too many pages, or a flag that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            The crawl failed outright. **The credits are refunded**, so
            `credits_charged` is `0`. The attempt is still recorded against
            `www.tripadvisor.com`.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TripadvisorSearchResult"
        "503":
          description: |
            The crawl could not be routed through a proxy pool. Nothing is
            charged.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

  /tripadvisor/hotel:
    get:
      tags: [Tripadvisor]
      summary: Read a Tripadvisor hotel
      operationId: tripadvisorHotel
      description: |
        Reads one Tripadvisor hotel page into a single object: address and
        coordinates, ranking, rating with its distribution and subratings, hotel
        class, amenities and the about tab's feature groups, photos, the offers
        and their prices, how to get there, what is nearby, the reviews on the
        first page and similar hotels.

        The page is always read on the English site, whichever of
        Tripadvisor's country sites the url came from, because some review
        fields are only filled from English labels. Its query string is
        dropped.

        **30 credits, flat.** A page that could not be read -- usually
        Tripadvisor's challenge page -- is not charged for.

        The key goes in the `Authorization` header, or in `?key=`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: url
          in: query
          required: true
          description: |
            A Tripadvisor hotel page,
            `https://www.tripadvisor.com/Hotel_Review-g<geo>-d<hotel>-Reviews-<name>.html`,
            on any of Tripadvisor's sites. Anything else is refused.
          schema:
            type: string
            format: uri
            maxLength: 2048
          example: https://www.tripadvisor.com/Hotel_Review-g227870-d33872104-Reviews-Holiday_Inn_Express_Suites_Barcelona_Sabadell_by_IHG-Sabadell_Catalonia.html
        - name: premium
          in: query
          required: false
          description: |
            Go through the premium proxy pool rather than the standard one. **On
            by default**, for the reason it is on `/tripadvisor/search`. Free
            either way.

            `true`, `false`, `1`, `0`, `yes`, `no`, `on`, `off`, in any case.
            Anything else is refused rather than read as `false`.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as a two-letter ISO 3166-1
            alpha-2 code. Free.

            Required to use `city`.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: es
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Free here, where on `/crawl` it doubles the price.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: barcelona
        - name: key
          in: query
          required: false
          description: |
            The API key, as an alternative to the `Authorization` header. Ignored
            when a header is present.
          schema:
            type: string
      responses:
        "200":
          description: The hotel.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TripadvisorHotelResult"
              example:
                url: https://www.tripadvisor.com/Hotel_Review-g227870-d33872104-Reviews-Holiday_Inn_Express_Suites_Barcelona_Sabadell_by_IHG-Sabadell_Catalonia.html
                hotel:
                  id: "33872104"
                  geoId: "227870"
                  name: Holiday Inn Express & Suites Barcelona Sabadell by IHG
                  address: { streetAddress: "Carrer de ...", addressLocality: Sabadell, addressCountry: ES }
                  geo: { latitude: 41.51, longitude: 2.10 }
                  ranking: { text: "#5 of 7 hotels in Sabadell", position: 5, total: 7 }
                  rating:
                    score: 4
                    word: Good
                    count: 5
                    subratings: { Rooms: 4.5, Service: 4.5, Value: 5, Location: 3 }
                  stars: 3.5
                  amenities: [Free internet, Outdoor pool]
                  price: { amount: 83, currency: USD }
                  offers:
                    - { provider: BookingCom, vendor: Booking.com, price: { amount: 83, currency: USD } }
                  reviews:
                    - id: "1074210662"
                      title: Great stay
                      rating: 5
                      text: "..."
                      published: Aug 2026
                  url: https://www.tripadvisor.com/Hotel_Review-g227870-d33872104-Reviews-Holiday_Inn_Express_Suites_Barcelona_Sabadell_by_IHG-Sabadell_Catalonia.html
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: null
        "202":
          description: |
            Paid for and still going. Collect it from `/crawl/{job}`, free, as a
            slow crawl is collected. That endpoint answers the crawl envelope, so
            what is lifted into `hotel` here arrives under `data` there.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TripadvisorHotelResult"
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no url, a url that is not a Tripadvisor hotel page, or a flag that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            Nothing came back: the crawl failed outright, or the hotel block
            found no hotel -- Tripadvisor's challenge page, or a layout the block
            no longer matches.

            **The credits are refunded either way**, so `credits_charged` is `0`.
            The attempt is still recorded against `www.tripadvisor.com`.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TripadvisorHotelResult"
              example:
                url: https://www.tripadvisor.com/Hotel_Review-g227870-d33872104-Reviews-Holiday_Inn_Express_Suites_Barcelona_Sabadell_by_IHG-Sabadell_Catalonia.html
                hotel: null
                credits_charged: 0
                credits_remaining: 1000
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: The crawler could not read that hotel page. Nothing was charged.
        "503":
          description: |
            The crawl could not be routed through a proxy pool. Nothing is
            charged.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

  /airbnb/search:
    get:
      tags: [Airbnb]
      summary: Search Airbnb
      operationId: airbnbSearch
      description: |
        Searches Airbnb for places to stay and returns the listings, one row per
        listing, with the price resolved into numbers, the rating, beds and
        bathrooms, badges and photos.

        The search is written into Airbnb's own url and read from the data the
        page is rendered from, so nothing depends on Airbnb's markup. Results
        are read page after page, 18 to a page, until `limit` listings are in.

        **30 credits per page of 18** that `limit` takes, so 30 by default and
        at most 150 for 90 listings -- charged when the crawl starts, whether
        or not the search turns out to have that many. `premium`, `country` and
        `city` choose where the crawl exits, not what it costs. A search that
        finds nothing is still charged for: it is Airbnb's answer, and an empty
        `listings` with `status` `done` is how it reads.

        The key goes in the `Authorization` header, or in `?key=`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: destination
          in: query
          required: true
          description: Where to stay, as you would type it into Airbnb's search box.
          schema:
            type: string
            maxLength: 200
          example: Jaipur
        - name: domain
          in: query
          required: false
          description: |
            The Airbnb site to search on, which sets the market --
            `www.airbnb.co.in`, `www.airbnb.es`. Only Airbnb's own sites are
            accepted.
          schema:
            type: string
            default: www.airbnb.com
          example: www.airbnb.co.in
        - name: checkin
          in: query
          required: false
          description: |
            The first night, as `YYYY-MM-DD`, today or later. **Requires
            `checkout`.**

            Optional: without dates Airbnb still shows the listings, it just
            prices no stay in particular.
          schema:
            type: string
            format: date
          example: "2026-11-20"
        - name: checkout
          in: query
          required: false
          description: The day you leave, as `YYYY-MM-DD`, after `checkin`. **Requires `checkin`.**
          schema:
            type: string
            format: date
          example: "2026-11-25"
        - name: locale
          in: query
          required: false
          description: |
            The language the page is shown in, the way Airbnb writes it: a
            language, or a language and region. Left to Airbnb when absent.
          schema:
            type: string
            pattern: '^[a-z]{2}(-[A-Za-z]{2,4})?$'
          example: en-IN
        - name: currency
          in: query
          required: false
          description: |
            The currency to price in, as a three-letter ISO 4217 code. Left to
            Airbnb when absent, which usually means the site's currency.
          schema:
            type: string
            minLength: 3
            maxLength: 3
            pattern: '^[A-Za-z]{3}$'
          example: INR
        - name: price_type
          in: query
          required: false
          description: |
            Which price leads each listing's `price.amount`: the stay's total
            (`trip`, Airbnb's own default) or a night's (`night`). Both are in
            `price` either way.
          schema:
            type: string
            enum: [trip, night]
          example: trip
        - name: free_cancellation
          in: query
          required: false
          description: Only listings with free cancellation. Accepts the same spellings as `premium`.
          schema:
            type: string
          example: "true"
        - name: instant_book
          in: query
          required: false
          description: Only listings that can be booked without the host approving.
          schema:
            type: string
          example: "false"
        - name: guest_favorite
          in: query
          required: false
          description: Only listings Airbnb marks as a guest favourite.
          schema:
            type: string
          example: "false"
        - name: self_check_in
          in: query
          required: false
          description: Only listings with self check-in.
          schema:
            type: string
          example: "false"
        - name: page
          in: query
          required: false
          description: |
            The results page to start from, counting from 0. Airbnb pages a
            search up to page 14.
          schema:
            type: integer
            minimum: 0
            maximum: 14
            default: 0
        - name: limit
          in: query
          required: false
          description: |
            How many listings to return, read on through as many pages as that
            takes. **Each page of 18 is 30 credits.**
          schema:
            type: integer
            minimum: 1
            maximum: 90
            default: 18
          example: 36
        - name: premium
          in: query
          required: false
          description: |
            Go through the premium proxy pool rather than the standard one. **On
            by default**; send `false` to use the standard pool. Free either way.

            `true`, `false`, `1`, `0`, `yes`, `no`, `on`, `off`, in any case.
            Anything else is refused rather than read as `false`.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as a two-letter ISO 3166-1
            alpha-2 code. Free. Airbnb prices by where you are, so this can change
            the answer.

            Required to use `city`.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: in
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Free here, where on `/crawl` it doubles the price.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: mumbai
        - name: key
          in: query
          required: false
          description: |
            The API key, as an alternative to the `Authorization` header. Ignored
            when a header is present.
          schema:
            type: string
      responses:
        "200":
          description: The listings.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AirbnbSearchResult"
              example:
                destination: Jaipur
                domain: www.airbnb.co.in
                locale: en-IN
                currency: INR
                checkin: "2026-11-20"
                checkout: "2026-11-25"
                price_type: null
                free_cancellation: null
                instant_book: null
                guest_favorite: null
                self_check_in: null
                page: 0
                limit: 18
                listings:
                  - id: "16208150"
                    url: https://www.airbnb.co.in/rooms/16208150?check_in=2026-11-20&check_out=2026-11-25
                    name: Bright Park-View Room Unique Rooftop Stay
                    title: Room in Jaipur
                    propertyType: Room
                    coordinates: { latitude: 26.8916, longitude: 75.8234 }
                    rating: 4.93
                    reviewCount: 107
                    price:
                      amount: 14800
                      currency: INR
                      type: trip
                      total: 14800
                      perNight: 2960
                      nights: 5
                      nightlyRate: 3700
                      originalTotal: 18500
                    beds: [1 single bed]
                    bathrooms: 1 bathroom
                    guestFavorite: true
                    freeCancellation: true
                    image: https://a0.muscache.com/im/pictures/1.jpg
                    position: 1
                    page: 0
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: null
        "202":
          description: |
            Paid for and still going. Collect it from `/crawl/{job}`, free, as a
            slow crawl is collected. That endpoint answers the crawl envelope, so
            what is lifted out here arrives under `data` there.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AirbnbSearchResult"
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no destination, a domain that is not an Airbnb site, one date without the other, dates in the past, a limit over 90, or a flag that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            The crawl failed outright. **The credits are refunded**, so
            `credits_charged` is `0`. The attempt is still recorded against the
            Airbnb site.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AirbnbSearchResult"
        "503":
          description: |
            The crawl could not be routed through a proxy pool. Nothing is
            charged.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

  /airbnb/listing:
    get:
      tags: [Airbnb]
      summary: Read an Airbnb listing
      operationId: airbnbListing
      description: |
        Reads one Airbnb listing into a single object: the description and
        highlights, location, capacity, the host and co-hosts, amenities grouped
        as Airbnb groups them, house rules, check-in and check-out, safety, the
        cancellation policy, ratings by category, the latest 24 reviews, a year
        of availability, the photos in the photo tour's order, and the price
        for the dates given.

        The listing is opened on the url's own Airbnb site, for the dates,
        guests, language and currency of this request; the url's query string
        is ignored. The price is only there with both dates.

        **30 credits, flat.** A listing that could not be read is not charged
        for.

        The key goes in the `Authorization` header, or in `?key=`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: url
          in: query
          required: true
          description: |
            An Airbnb listing, `https://www.airbnb.com/rooms/<id>`, on any of
            Airbnb's sites. Anything else is refused.
          schema:
            type: string
            format: uri
            maxLength: 2048
          example: https://www.airbnb.com/rooms/965075981702341405
        - name: adults
          in: query
          required: false
          description: How many adults are staying. Left to Airbnb when absent.
          schema:
            type: integer
            minimum: 1
            maximum: 16
          example: 2
        - name: checkin
          in: query
          required: false
          description: |
            The first night, as `YYYY-MM-DD`, today or later. **Requires
            `checkout`.**

            Optional: without dates Airbnb still shows the listings, it just
            prices no stay in particular.
          schema:
            type: string
            format: date
          example: "2026-11-20"
        - name: checkout
          in: query
          required: false
          description: The day you leave, as `YYYY-MM-DD`, after `checkin`. **Requires `checkin`.**
          schema:
            type: string
            format: date
          example: "2026-11-25"
        - name: locale
          in: query
          required: false
          description: |
            The language the page is shown in, the way Airbnb writes it: a
            language, or a language and region. Left to Airbnb when absent.
          schema:
            type: string
            pattern: '^[a-z]{2}(-[A-Za-z]{2,4})?$'
          example: en-IN
        - name: currency
          in: query
          required: false
          description: |
            The currency to price in, as a three-letter ISO 4217 code. Left to
            Airbnb when absent, which usually means the site's currency.
          schema:
            type: string
            minLength: 3
            maxLength: 3
            pattern: '^[A-Za-z]{3}$'
          example: INR
        - name: premium
          in: query
          required: false
          description: |
            Go through the premium proxy pool rather than the standard one. **On
            by default**; send `false` to use the standard pool. Free either way.

            `true`, `false`, `1`, `0`, `yes`, `no`, `on`, `off`, in any case.
            Anything else is refused rather than read as `false`.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be browsing from, as a two-letter ISO 3166-1
            alpha-2 code. Free. Airbnb prices by where you are, so this can change
            the answer.

            Required to use `city`.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: in
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Free here, where on `/crawl` it doubles the price.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: mumbai
        - name: key
          in: query
          required: false
          description: |
            The API key, as an alternative to the `Authorization` header. Ignored
            when a header is present.
          schema:
            type: string
      responses:
        "200":
          description: The listing.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AirbnbListingResult"
              example:
                url: https://www.airbnb.com/rooms/965075981702341405
                place_id: "965075981702341405"
                locale: en
                currency: INR
                checkin: "2026-11-20"
                checkout: "2026-11-25"
                adults: null
                listing:
                  id: "965075981702341405"
                  name: Rooftop studio near the old city
                  title: Room in Jaipur, India
                  location: { name: "Jaipur, Rajasthan, India", latitude: 26.91, longitude: 75.82, exact: false }
                  rating: 4.9
                  reviewCount: 212
                  host: { name: Aditi, superhost: true }
                  amenities: [Wifi, Kitchen, Air conditioning]
                  checkIn: Check in after 2:00 PM
                  cancellationPolicy: { until: 18 Nov, refund: full, terms: "..." }
                  price: { total: 14800, taxes: 1776, nights: 5, nightlyRate: 2960, perNight: 2960 }
                  available: true
                  reviews:
                    - rating: 5
                      text: Lovely stay.
                      date: October 2026
                  calendar:
                    - { date: "2026-11-20", available: true, checkin: true, checkout: false, minNights: 1, maxNights: 30 }
                  url: https://www.airbnb.com/
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: null
        "202":
          description: |
            Paid for and still going. Collect it from `/crawl/{job}`, free, as a
            slow crawl is collected. That endpoint answers the crawl envelope, so
            what is lifted out here arrives under `data` there.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AirbnbListingResult"
        "401":
          description: |
            No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: This endpoint is reached with an organization API key.
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no url, a url that is not an Airbnb listing, one date without the other, dates in the past, or a flag that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            Nothing came back: the crawl failed outright, or the listing block
            found no listing -- a challenge page, a listing taken down, or a
            layout the block no longer matches.

            **The credits are refunded either way**, so `credits_charged` is `0`.
            The attempt is still recorded against the Airbnb site.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AirbnbListingResult"
              example:
                url: https://www.airbnb.com/rooms/965075981702341405
                place_id: "965075981702341405"
                locale: null
                currency: null
                checkin: null
                checkout: null
                adults: null
                listing: null
                credits_charged: 0
                credits_remaining: 1000
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: The crawler could not read that listing. Nothing was charged.
        "503":
          description: |
            The crawl could not be routed through a proxy pool. Nothing is
            charged.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                message: The crawler cannot route this crawl right now. Nothing was charged.

  /google-ai-overview:
    get:
      tags: [Google]
      summary: Read Google's AI Overview
      operationId: googleAiOverview
      description: |
        Searches Google for a query and returns the AI Overview shown above the
        results: the answer as text, and the pages it cites.

        You name the query and which Google to ask -- `de` for google.de,
        `co.uk` for google.co.uk; the search url is built from them. The
        consent dialog a first visit is greeted with is pressed past, and the
        answer is expanded before it is read.

        **30 credits, flat.** `premium`, `country` and `city` choose where the
        crawl exits, not what it costs. A query Google shows no overview for is
        still charged for: it is Google's answer, and a null `ai_overview` with
        `status` `done` is how it reads. A crawl that fails is not charged for.

        The key goes in the `Authorization` header, or in `?key=`.
      security:
        - apiKeyHeader: []
        - apiKeyQuery: []
      parameters:
        - name: query
          in: query
          required: true
          description: The search, as you would type it into Google. Up to 500 characters.
          schema:
            type: string
            maxLength: 500
          example: cómo se monta en tren
        - name: domain
          in: query
          required: false
          description: |
            The extension of the Google to ask: `com`, `de`, `es`, `co.uk`,
            `com.br` and so on. The overview is written in that Google's
            language, so this is usually what decides it.

            Pair it with `country` to search from inside that market too.
          schema:
            type: string
            default: com
            pattern: '^(?:com|cat|(?:com?\.)?[A-Za-z]{2})$'
          example: es
        - name: premium
          in: query
          required: false
          description: |
            Search through the premium proxy pool rather than the standard one.
            **On by default**, because the standard pool is the one Google turns
            away; send `false` to use the standard pool. Free either way, unlike
            on `/crawl` -- the price is flat.

            Accepts `true`, `false`, `1`, `0`, `yes`, `no`, `on`, `off`, in any
            case. Anything else is refused.
          schema:
            type: string
            default: "true"
          example: "true"
        - name: country
          in: query
          required: false
          description: |
            The country to appear to be searching from, as a two-letter ISO
            3166-1 alpha-2 code. Free. Required to use `city`.
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: '^[A-Za-z]{2}$'
          example: es
        - name: city
          in: query
          required: false
          description: |
            The city inside that country, as the pool spells it. **Requires
            `country`.** Free here.

            Letters, digits, hyphens and underscores only; a multi-word city is
            written `new_york`.
          schema:
            type: string
            pattern: '^[A-Za-z][A-Za-z0-9_-]{0,63}$'
          example: madrid
        - name: key
          in: query
          required: false
          description: |
            The API key, as an alternative to the `Authorization` header. Ignored
            when a header is present.
          schema:
            type: string
      responses:
        "200":
          description: |
            Google's results page was read. `ai_overview` is null when it showed
            no overview for the query.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/GoogleAiOverviewResult"
              example:
                query: cómo se monta en tren
                domain: es
                url: https://www.google.es/search?q=c%C3%B3mo+se+monta+en+tren
                ai_overview: Montar en tren como pasajero es un proceso sencillo que se divide en varios pasos…
                sources:
                  - title: Remitly
                    url: https://www.remitly.com/blog/es/viajar/viajar-en-tren/
                credits_charged: 30
                credits_remaining: 970
                job_id: 0198a9b6-1f4c-7c3e-9a2b-5d8e6f0a1b23_0198a9b6-2a71-7f0d-8c44-9e1b3c5d7f02
                status: done
                position: null
                debug: null
                error: null
        "202":
          description: |
            Paid for and still going. Collect it from `/crawl/{job}`, where the
            answer arrives under `data.ai_overview` and `data.ai_overview_sources`
            rather than lifted out the way it is here.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/GoogleAiOverviewResult"
        "401":
          description: No key, an unknown key, or a caller that is not an organization.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "402":
          description: |
            Not enough credits, or the daily limit is reached. Nothing is charged
            and no attempt is recorded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: |
            A malformed request -- no query, a query over the limit, a domain that
            is not a Google domain's extension, a city with no country, or a flag
            that is not a yes or a no.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          description: |
            The crawl failed. **The credits are refunded**, so `credits_charged`
            is `0`.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/GoogleAiOverviewResult"
        "503":
          description: |
            The crawl could not be routed through a proxy pool. Nothing is
            charged.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

components:
  securitySchemes:
    apiKeyHeader:
      type: http
      scheme: bearer
      description: |
        `Authorization: Bearer <key>`. The usual way in.
    apiKeyQuery:
      type: apiKey
      in: query
      name: key
      description: |
        `?key=<key>`. Accepted on the crawl route only, and only when no
        `Authorization` header was sent.

  schemas:
    BookingSearchResult:
      type: object
      description: |
        What `/booking/search` answers. `hotels` is empty while the search is
        still running, when it failed and when it found nothing; `status` tells
        those apart.
      required:
        - destination
        - hotels
        - url
        - checkin
        - checkout
        - adults
        - rooms
        - currency
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - position
        - error
        - debug
      properties:
        url:
          type: string
          description: The Booking.com page that was read, as built from the request.
        checkin:
          type: [string, "null"]
          format: date
        checkout:
          type: [string, "null"]
          format: date
        adults:
          type: integer
        rooms:
          type: integer
        currency:
          type: [string, "null"]
        destination:
          type: string
        hotels:
          type: array
          description: |
            One row per property card, each field as text the way Booking prints
            it. A field the card does not show is absent.
          items:
            type: object
            properties:
              name: { type: string }
              url: { type: string }
              image: { type: string }
              price: { type: string }
              priceInfo: { type: string }
              taxes: { type: string }
              address: { type: string }
              distance: { type: string }
              reviewScore: { type: string }
              reviewWord: { type: string }
              reviewCount: { type: string }
              stars: { type: string }
        credits_charged:
          type: integer
          description: 30, or 0 when nothing came back.
        credits_remaining:
          type: integer
        job_id:
          type: string
          description: What this ran under. Collect a `202` from `/crawl/{job}` with it.
        status:
          type: string
          enum: [done, queued, running, failed]
        position:
          type: [integer, "null"]
          description: Where it sits in the crawler's queue while `queued`.
        error:
          type: [string, "null"]
          description: Why nothing came back. Null otherwise.
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    BookingHotelResult:
      type: object
      description: |
        What `/booking/hotel` answers. `hotel` is null while the page is still
        being read and when it could not be; `status` and `error` tell those
        apart.
      required:
        - hotel
        - url
        - checkin
        - checkout
        - adults
        - rooms
        - currency
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - position
        - error
        - debug
      properties:
        url:
          type: string
          description: The Booking.com page that was read, as built from the request.
        checkin:
          type: [string, "null"]
          format: date
        checkout:
          type: [string, "null"]
          format: date
        adults:
          type: integer
        rooms:
          type: integer
        currency:
          type: [string, "null"]
        hotel:
          oneOf:
            - type: object
              additionalProperties: true
              description: |
                The property. `name`, `address`, `description`, `rating`, `price`,
                `rooms`, `facilities` and `images` are resolved by the crawler;
                `pointsOfInterest`, `reviewSubscores`, `reviews`, `questions` and
                `sections` are lists of text. `price` is the cheapest of the room
                prices, and absent without a stay.
            - type: "null"
        credits_charged:
          type: integer
          description: 30, or 0 when nothing came back.
        credits_remaining:
          type: integer
        job_id:
          type: string
          description: What this ran under. Collect a `202` from `/crawl/{job}` with it.
        status:
          type: string
          enum: [done, queued, running, failed]
        position:
          type: [integer, "null"]
          description: Where it sits in the crawler's queue while `queued`.
        error:
          type: [string, "null"]
          description: Why nothing came back. Null otherwise.
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    TripadvisorSearchResult:
      type: object
      description: |
        What `/tripadvisor/search` answers. `hotels` is empty while the search
        is still running, when it failed and when it found nothing; `status`
        tells those apart. The search parameters are echoed back, null where
        they were not given.
      required:
        - url
        - destination
        - checkin
        - checkout
        - rooms
        - adults
        - children
        - filters
        - price_min
        - price_max
        - sort
        - max_pages
        - hotels
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - position
        - error
        - debug
      properties:
        url:
          type: string
          description: The Tripadvisor hotel list the search started from.
        destination:
          type: string
        checkin:
          type: [string, "null"]
          format: date
        checkout:
          type: [string, "null"]
          format: date
        rooms:
          type: [integer, "null"]
        adults:
          type: [integer, "null"]
        children:
          type: [integer, "null"]
        filters:
          type: array
          items: { type: string }
        price_min:
          type: [integer, "null"]
        price_max:
          type: [integer, "null"]
        sort:
          type: [string, "null"]
        max_pages:
          type: integer
        hotels:
          type: array
          description: |
            One row per hotel card. A field the card does not show is absent.
          items:
            type: object
            additionalProperties: true
            properties:
              position:
                type: integer
                description: The rank on the list. Absent on sponsored cards.
              name: { type: string }
              url: { type: string }
              id: { type: string }
              geoId: { type: string }
              rating: { type: number }
              reviewCount: { type: integer }
              ratingWord: { type: string }
              subratings: { type: object, additionalProperties: { type: number } }
              stars: { type: number }
              ranking:
                type: object
                properties:
                  text: { type: string }
                  position: { type: integer }
                  total: { type: integer }
              price:
                type: object
                description: The card's lowest price; for the stay when dates were given.
                properties:
                  amount: { type: number }
                  currency: { type: string }
              amenities: { type: array, items: { type: string } }
              badges: { type: array, items: { type: string } }
              tags: { type: array, items: { type: string } }
              roomsLeft: { type: integer }
              image: { type: string }
              review:
                type: object
                properties:
                  author: { type: string }
                  text: { type: string }
              sponsored: { type: boolean }
              nearby:
                type: boolean
                description: Listed after the matches end -- around the destination, or missing a filter.
              page: { type: integer }
        credits_charged:
          type: integer
          description: 30 per page asked for, or 0 when nothing came back.
        credits_remaining:
          type: integer
        job_id:
          type: string
          description: What this ran under. Collect a `202` from `/crawl/{job}` with it.
        status:
          type: string
          enum: [done, queued, running, failed]
        position:
          type: [integer, "null"]
          description: Where it sits in the crawler's queue while `queued`.
        error:
          type: [string, "null"]
          description: Why nothing came back. Null otherwise.
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    TripadvisorHotelResult:
      type: object
      description: |
        What `/tripadvisor/hotel` answers. `hotel` is null while the page is
        still being read and when it could not be; `status` and `error` tell
        those apart.
      required:
        - url
        - hotel
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - position
        - error
        - debug
      properties:
        url:
          type: string
          description: The Tripadvisor page that was read, on the English site.
        hotel:
          oneOf:
            - type: object
              additionalProperties: true
              description: |
                The hotel. `id`, `geoId`, `name`, `address`, `geo`,
                `breadcrumbs`, `ranking`, `rating` (with `distribution` and
                `subratings`), `stars`, `hotelClass`, `priceRange`,
                `description`, `amenities`, `features`, `photos`, `photoCount`,
                `offers`, `price` (the cheapest offer), `dealCount`, `stay`,
                `gettingThere`, `nearby`, `reviews` (the first page) and
                `similarHotels`, each absent when the page does not show it.
            - type: "null"
        credits_charged:
          type: integer
          description: 30, or 0 when nothing came back.
        credits_remaining:
          type: integer
        job_id:
          type: string
          description: What this ran under. Collect a `202` from `/crawl/{job}` with it.
        status:
          type: string
          enum: [done, queued, running, failed]
        position:
          type: [integer, "null"]
          description: Where it sits in the crawler's queue while `queued`.
        error:
          type: [string, "null"]
          description: Why nothing came back. Null otherwise.
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    AirbnbSearchResult:
      type: object
      description: |
        What `/airbnb/search` answers. `listings` is empty while the search is
        still running, when it failed and when it found nothing; `status`
        tells those apart. The search parameters are echoed back, null where
        they were not given.
      required:
        - destination
        - domain
        - locale
        - currency
        - checkin
        - checkout
        - price_type
        - free_cancellation
        - instant_book
        - guest_favorite
        - self_check_in
        - page
        - limit
        - listings
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - position
        - error
        - debug
      properties:
        destination: { type: string }
        domain:
          type: string
          description: The Airbnb site searched, and the host the crawl is tallied against.
        locale: { type: [string, "null"] }
        currency: { type: [string, "null"] }
        checkin: { type: [string, "null"], format: date }
        checkout: { type: [string, "null"], format: date }
        price_type: { type: [string, "null"] }
        free_cancellation: { type: [boolean, "null"] }
        instant_book: { type: [boolean, "null"] }
        guest_favorite: { type: [boolean, "null"] }
        self_check_in: { type: [boolean, "null"] }
        page: { type: integer }
        limit: { type: integer }
        listings:
          type: array
          description: |
            One row per listing. A field the listing does not have is absent.
            `superhost`, `guestFavorite` and `freeCancellation` are only set when
            the card says so, so their absence proves nothing.
          items:
            type: object
            additionalProperties: true
            properties:
              id: { type: string }
              url: { type: string }
              name: { type: string }
              title: { type: string }
              propertyType: { type: string }
              coordinates:
                type: object
                properties:
                  latitude: { type: number }
                  longitude: { type: number }
              rating: { type: number }
              reviewCount: { type: integer }
              isNew: { type: boolean }
              price:
                type: object
                description: |
                  `amount` is the total or a night's, as `price_type` asked;
                  `total` is the stay before taxes, after discounts.
                additionalProperties: true
              details: { type: array, items: { type: string } }
              beds: { type: array, items: { type: string } }
              bathrooms: { type: string }
              badges: { type: array, items: { type: object } }
              superhost: { type: boolean }
              guestFavorite: { type: boolean }
              freeCancellation: { type: boolean }
              image: { type: string }
              photos: { type: array, items: { type: string } }
              position:
                type: integer
                description: Counted from the first listing of the first page read.
              page: { type: integer }
        credits_charged:
          type: integer
          description: 30 per page of 18 the limit takes, or 0 when nothing came back.
        credits_remaining:
          type: integer
        job_id:
          type: string
          description: What this ran under. Collect a `202` from `/crawl/{job}` with it.
        status:
          type: string
          enum: [done, queued, running, failed]
        position:
          type: [integer, "null"]
          description: Where it sits in the crawler's queue while `queued`.
        error:
          type: [string, "null"]
          description: Why nothing came back. Null otherwise.
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    AirbnbListingResult:
      type: object
      description: |
        What `/airbnb/listing` answers. `listing` is null while the page is
        still being read and when it could not be; `status` and `error` tell
        those apart.
      required:
        - url
        - place_id
        - locale
        - currency
        - checkin
        - checkout
        - adults
        - listing
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - position
        - error
        - debug
      properties:
        url:
          type: string
          description: The listing, on the Airbnb site it was asked for.
        place_id: { type: string }
        locale: { type: [string, "null"] }
        currency: { type: [string, "null"] }
        checkin: { type: [string, "null"], format: date }
        checkout: { type: [string, "null"], format: date }
        adults: { type: [integer, "null"] }
        listing:
          oneOf:
            - type: object
              additionalProperties: true
              description: |
                The listing: `id`, `url`, `name`, `title`, `propertyType`,
                `spaceType`, `summary`, `overview`, `capacity`, `maxGuests`,
                `description`, `highlights`, `location`, `rating`,
                `reviewCount`, `ratings`, `ratingDistribution`, `reviewTags`,
                `guestFavorite`, `isNew`, `host`, `cohosts`, `amenities`,
                `unavailableAmenities`, `amenityGroups`, `houseRules`,
                `checkIn`, `checkOut`, `safety`, `cancellationPolicy`,
                `guestPolicy`, `price` (only with dates), `available`,
                `instantBook`, `image`, `photos`, `reviews` and `calendar`, each
                absent when the listing does not have it.
            - type: "null"
        credits_charged:
          type: integer
          description: 30, or 0 when nothing came back.
        credits_remaining:
          type: integer
        job_id:
          type: string
          description: What this ran under. Collect a `202` from `/crawl/{job}` with it.
        status:
          type: string
          enum: [done, queued, running, failed]
        position:
          type: [integer, "null"]
          description: Where it sits in the crawler's queue while `queued`.
        error:
          type: [string, "null"]
          description: Why nothing came back. Null otherwise.
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    ChatGptResult:
      type: object
      description: |
        What `/chatgpt` answers. `conversation` is empty while a prompt is still
        running and when it went unanswered; `status` and `error` are what tell
        those two apart.
      required:
        - prompt
        - conversation
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - debug
      properties:
        prompt:
          type: string
          description: The question, as it was asked.
        conversation:
          type: array
          description: |
            The exchange. The user turn carries `message`; the assistant turn
            carries `response`, a list of nodes.
          items:
            type: object
            properties:
              role:
                type: string
                enum: [user, assistant]
              message:
                type: string
                description: The prompt. Present on the user turn only.
              response:
                type: array
                description: |
                  The answer, node by node. `type` says which shape each one is:
                  `paragraph` and `heading` carry `text` (and `heading` a `level`),
                  `bullet_list` and `ordered_list` carry `items`, `table` carries
                  `headers` and `rows`, `product_list` carries `items`, and
                  `divider` carries nothing. Any node may carry `sources`, the
                  citations ChatGPT showed beside it.
                items:
                  type: object
                  additionalProperties: true
        credits_charged:
          type: integer
          description: |
            30 for a prompt that was answered or is still running, 0 for one that
            was not.
          example: 30
        credits_remaining:
          type: integer
        job_id:
          type: string
          description: |
            What this ran under. Collect a `202` from `/crawl/{job}` with it.
        status:
          type: string
          enum: [done, queued, running, failed]
        position:
          type: [integer, "null"]
          description: Where it sits in the crawler's queue while `queued`.
        error:
          type: [string, "null"]
          description: Why nothing came back. Null otherwise.
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    ScreenshotResult:
      type: object
      description: |
        What `/screenshot` answers. `screenshot` is null while a crawl is still
        running and when it finished without producing an image; `status` and
        `error` are what tell those two apart.

        Standalone rather than the crawl envelope, like `/chatgpt`'s: there is no
        `content` here, because a recipe that ends in a screenshot is never a
        document recipe and so never comes back as a page.
      required:
        - url
        - domain
        - screenshot
        - ai_query
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - data
        - position
        - error
        - debug
      properties:
        url:
          type: string
          format: uri
          description: The page that was photographed, as it was asked for.
          example: https://example.com/
        domain:
          type: string
          description: |
            The host the crawl was tallied against for the day, lowercased.
          example: example.com
        screenshot:
          type: [string, "null"]
          format: byte
          description: |
            The picture: a full-page JPEG, base64 encoded, with no `data:` prefix.
            Full page means the entire scroll height rather than the viewport, so
            a long page produces a tall image and a large field -- several
            megabytes is ordinary, and base64 adds about a third on top.

            Null when there is no picture, which is either a crawl still running
            or one that produced none. `status` says which, and `error` says why.
          example: /9j/4AAQSkZJRgABAQEAYABgAAD...
        ai_query:
          type: string
          description: |
            The question that was asked, echoed back. Empty when none was. Here to
            explain `data` rather than the bill: it costs nothing on this endpoint.
          example: ""
        credits_charged:
          type: integer
          description: |
            30 for a screenshot that was taken or is still being taken, 0 for one
            that produced nothing -- those are refunded. Flat: none of the options
            move it.
          example: 30
        credits_remaining:
          type: integer
          description: The organization's balance afterwards.
          example: 970
        job_id:
          type: string
          description: |
            What this ran under. Collect a `202` from `/crawl/{job}` with it.
          example: JOB_ID
        status:
          type: string
          enum: [queued, running, done, failed]
          description: |
            `queued` and `running` mean paid for and not finished -- poll it.
            `done` and `failed` are final.
          example: done
        data:
          type: [object, "null"]
          additionalProperties: true
          description: |
            Whatever else the crawl collected -- the answer to an `ai_query` when
            one was asked, and the page's own url and title. Null when it
            collected nothing.

            The image is **not** in here. It is lifted into `screenshot` and
            removed from this object rather than repeated, because sending several
            megabytes twice is not a rounding error.
          example:
            url: https://example.com/
        position:
          type: [integer, "null"]
          description: Where it sits in the crawler's queue while `queued`.
          example: null
        error:
          type: [string, "null"]
          description: Why no picture came back. Null otherwise.
          example: null
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.

            The picture in here is **not** the one you paid for. `screenshot`
            above is the deliverable, a full-page image; this is a viewport
            thumbnail off the live tab, and it never stands in for the other. A
            pending response carries this one and not that one.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    GoogleAiOverviewResult:
      type: object
      description: |
        What `/google-ai-overview` answers. `ai_overview` is null while it is
        still running and when Google showed none; `status` tells those apart.
      required:
        - query
        - domain
        - url
        - ai_overview
        - sources
        - credits_charged
        - credits_remaining
        - job_id
        - status
        - debug
      properties:
        query:
          type: string
          description: The search, as it was asked.
        domain:
          type: string
          description: The extension of the Google that was asked, lowercased.
        url:
          type: string
          description: The results page the crawl was run against.
        ai_overview:
          type: [string, "null"]
          description: The overview's answer as text, without its heading or Google's standing notice.
        sources:
          type: array
          description: The pages the overview cites. Empty when it cites none.
          items:
            type: object
            properties:
              title:
                type: [string, "null"]
              url:
                type: string
        credits_charged:
          type: integer
          example: 30
        credits_remaining:
          type: integer
        job_id:
          type: string
          description: What this ran under. Collect a `202` from `/crawl/{job}` with it.
        status:
          type: string
          enum: [done, queued, running, failed]
        position:
          type: [integer, "null"]
        error:
          type: [string, "null"]
        debug:
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    CrawlSnapshot:
      type: object
      description: |
        Where a crawl had got to, for one that is still running or failed. Only
        sent when the request carries `debuga=1`.

        The crawler stops waiting long before it stops working, and when it stops
        waiting it looks at the tab: the url the browser is on, a picture of what
        is on screen, and the page source as it stands. That is what this is --
        a diagnosis for a request that timed out, not a result. Nothing is
        charged for it.

        Null on anything that is not still running. A finished or failed crawl has
        no tab left to look at, and a crawl still in the queue has not opened one
        yet.

        Two things to know when reading one. The image is the **viewport**, not
        the whole page, so it is not the picture `/screenshot` sells -- it is a
        thumbnail at quality 60, meant to be looked at rather than kept. And
        either artefact may be missing: they are captured independently, because a
        navigation can destroy one without touching the other, so half a snapshot
        is ordinary. The missing half reads as null rather than going absent.

        A blank image beside a near-empty `html` is not a broken capture -- it
        means the crawl stalled *inside* a navigation, with the old document
        already replaced. That is itself the answer.
      required:
        - url
        - screenshot
        - html
      properties:
        url:
          type: [string, "null"]
          format: uri
          description: |
            The url the tab was on, which a redirect may have moved away from the
            one you asked for.
          example: https://shop.example/p/1
        screenshot:
          type: [string, "null"]
          format: byte
          description: |
            A base64 JPEG of the viewport, with no `data:` prefix -- decode it as
            it stands. Null when the capture raced a navigation and lost.
          example: /9j/4AAQSkZJRgABAQ...
        html:
          type: [string, "null"]
          description: |
            The page source at that moment, half-loaded and all. Null when the
            capture raced a navigation and lost.
          example: <!doctype html>...

    CrawlOutcome:
      type: object
      description: |
        How a crawl is getting on. Only one of `content`, `data`, `position` and
        `error` is ever meaningful and `status` is what says which, but all four
        are always present: the shape does not change between a finished crawl
        and a running one, so a caller can read a field without checking that it
        is there. `debug` follows the same rule: null unless the request carries
        `debuga=1` and the crawler had something to show.
      required: [job_id, status, content, data, position, error, debug]
      properties:
        job_id:
          type: string
          description: |
            The id this crawl runs under, and the one to pass to `/crawl/{job}`.
            The organization's id and a uuid, joined by an underscore.
          example: JOB_ID
        status:
          type: string
          enum: [queued, running, done, failed]
          description: |
            `queued` and `running` mean paid for and not finished -- poll it.
            `done` and `failed` are final.
          example: queued
        content:
          type: [string, "null"]
          description: |
            The page, when one is being described in JSON rather than served as a
            document. In practice always null: a finished crawl that has a page
            is sent as `text/html`, and one that has not has no page to carry.
          example: null
        data:
          type: [object, array, "null"]
          additionalProperties: true
          items:
            type: object
            additionalProperties: true
          description: |
            Whatever the crawl collected besides a page -- the answer to an
            `ai_query`, when one was asked. Null otherwise.

            An object or a list, depending on `expectedOutput`. `item`, the
            default, folds every block's output into one object; `list` keeps a
            row per record, which is what a recipe that paginates or extracts many
            rows wants. An `ai_query` fills a single entry either way, whose keys
            are the short snake_case field names the model chose for what it was
            asked to find.
          example: null
        position:
          type: [integer, "null"]
          description: |
            How many crawls were waiting when this one was accepted, itself
            included. Sent while `status` is `queued` or `running`, and null once
            the crawl is `done` or `failed`.

            It is a snapshot taken at submission, not a countdown: it is not
            recalculated as the queue drains, so read it as how busy the runner
            was rather than as how many are still ahead.
          example: 3
        error:
          type: [string, "null"]
          description: Why the crawl failed. Null unless `status` is `failed`.
          example: null
        error_code:
          type: [string, "null"]
          enum:
            - port_blocked
            - host_not_allowed
            - connection_refused
            - name_not_resolved
            - tls_error
            - navigation_timeout
            - proxy_error
            - null
          description: |
            Why the page could not be reached, when the crawler could tell. Null
            for every other outcome, and for a failure it could not put a name to.

            The first five mean the url itself could never have worked -- a port
            the proxy refuses (`example.com:81`), a host it will not connect to,
            one that hangs up, one that stopped resolving, a broken certificate.
            Those are answered with a 422. `navigation_timeout` and `proxy_error`
            can be our side as easily as the site's, and stay a 500.
          example: null
        debug:
          description: |
            Where the crawl had got to, when the crawler stopped waiting and
            looked. Only sent when the request carries `debuga=1` -- a screenshot
            and the page source run to a megabyte -- and null otherwise.
          oneOf:
            - $ref: "#/components/schemas/CrawlSnapshot"
            - type: "null"

    CrawlResult:
      description: |
        The JSON envelope from `/crawl`: what was asked for, what it cost, and
        how the crawl is getting on. The page itself is not in here -- a finished
        crawl that produced one is served as `text/html` instead.
      allOf:
        - $ref: "#/components/schemas/CrawlOutcome"
        - type: object
          required:
            - url
            - domain
            - premium
            - js
            - images
            - city
            - ai_query
            - credits_charged
            - credits_remaining
          properties:
            url:
              type: string
              format: uri
              description: The url as it was asked for.
              example: https://www.Example.COM/products?page=2
            domain:
              type: string
              description: |
                The host, lowercased. This is what the crawl is tallied against:
                one row per organization, domain and day, so repeat crawls of the
                same site on the same day increment a counter rather than pile up.
              example: www.example.com
            premium:
              type: boolean
              example: false
            js:
              type: boolean
              example: true
            images:
              type: boolean
              example: false
            city:
              type: [string, "null"]
              description: |
                The city the crawl was routed through, lowercased, or `null` when
                it was not routed through one -- which includes a `city` that was
                asked for and dropped because the crawl went out without a proxy
                to carry it. This is the field the doubled price follows, so it is
                what to check rather than what was sent. The country is not echoed:
                it is free.
              example: null
            ai_query:
              type: string
              description: The question asked about the page; empty when none was.
              example: ""
            credits_charged:
              type: integer
              description: |
                What this crawl cost. The fetch is priced by the two flags, and
                rendering multiplies rather than adds:

                | premium | js | credits |
                | ------- | -- | ------- |
                | false   | false | 1    |
                | false   | true  | 5    |
                | true    | false | 10   |
                | true    | true  | 25   |

                Two flags add to whichever of those applies, rather than
                multiplying it: `images` adds 2, and an `ai_query` adds 5.

                A `city` then doubles the total, surcharges and all.
              example: 5
            credits_remaining:
              type: integer
              description: The organization's balance after the charge.
              example: 995

    Recipe:
      type: object
      description: |
        A recipe: the blocks the crawler runs against a page, in order. This is
        the body of `POST /crawl`.

        Only these three fields are read. The fetch options go in the query
        string, and a field here that is not one of these is a `422` rather than
        an option -- see the endpoint's description.
      required:
        - blocks
      properties:
        name:
          type: [string, "null"]
          maxLength: 255
          description: |
            A label for the run, which appears in the crawler's logs and nowhere
            else. Defaults to `Crawl <url>`.
          example: Products, page 2
        expectedOutput:
          type: [string, "null"]
          enum: [item, list, null]
          default: item
          description: |
            How the blocks' output is assembled. `item` folds everything into a
            single object; `list` keeps one entry per row, which is what a recipe
            that paginates or extracts many rows wants.
          example: list
        blocks:
          type: array
          minItems: 1
          description: |
            The blocks, in the order they run. There is no maximum -- a long
            recipe costs the same 30 credits as a short one -- but the crawler
            stops waiting after a couple of minutes and answers `202`, so a long
            one is usually collected from `/crawl/{job}` rather than returned
            outright.

            **The first block must be a `start` block**, and it is the only one
            whose `details` are not used as written: we read `details.source` and
            build the rest ourselves. **No later block may be a `start` block** --
            a crawl begins once, at the url it names.
          items:
            $ref: "#/components/schemas/RecipeBlock"

    RecipeBlock:
      type: object
      description: One step of a recipe.
      required:
        - type
      properties:
        id:
          type: string
          maxLength: 64
          description: |
            Your name for the block. Optional, and usually absent -- the crawler
            is given ids of our own making whatever you send, so nothing you do
            depends on it.

            It is worth setting for exactly one reason: a `paginate` block names
            the block it rewinds to by id, and both ends of that reference have to
            carry one. A `paginate` naming an id no block carries is a `422`.
          example: rows
        type:
          type: string
          description: |
            What the block does.

            `ai`, `chatgpt` and a second `start` are deliberately not on this
            list. A question for a model is what the `GET`'s `ai_query` and
            `/chatgpt` are for, and a crawl starts once.
          enum:
            - start
            - input
            - click
            - screenshot
            - save-html
            - jsonschema
            - datalayer
            - paginate
            - extract
            - remove
            - extract-variable
            - add-field
            - scroll-to-element
            - wait
          example: extract
        details:
          type: object
          additionalProperties: true
          description: |
            The block's own settings, which differ by `type` and are passed to the
            crawler as written. The first block's `details` are the exception:
            only `source` is read from them.

            `start` takes `type: url` and `source`; `click`, `remove` and
            `scroll-to-element` take a `selector`; `input` takes a `selector` and
            `text`; `extract` takes a `selector`, a `name` and a `property`;
            `wait` takes `seconds`; `paginate` takes a `selector` to click and a
            `startBlock` to rewind to.
          example:
            selector: .product .title
            name: title
            property: textContent

    RecipeResult:
      description: |
        The JSON envelope from `POST /crawl`. The priced options the `GET` echoes
        back are absent here: the price is flat, so there is nothing for them to
        explain.
      allOf:
        - $ref: "#/components/schemas/CrawlOutcome"
        - type: object
          required:
            - url
            - domain
            - credits_charged
            - credits_remaining
          properties:
            url:
              type: string
              format: uri
              description: Where the crawl started -- the first block's `details.source`.
              example: https://example.com/products
            domain:
              type: string
              description: |
                That url's host, lowercased, and what the crawl is tallied
                against. Note that it is the host the recipe *started* at: a
                recipe that navigates elsewhere is still counted here.
              example: example.com
            credits_charged:
              type: integer
              description: |
                30 for a recipe that ran or is still running, 0 for one the
                crawler could not deliver at all. Flat: neither the number of
                blocks nor `premium`, `country` or `city` changes it.
              example: 30
            credits_remaining:
              type: integer
              description: The organization's balance after the charge.
              example: 970

    Error:
      type: object
      required: [message]
      properties:
        message:
          type: string

    ValidationError:
      type: object
      required: [message, errors]
      properties:
        message:
          type: string
        errors:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
