{
  "openapi": "3.1.0",
  "info": {
    "title": "Bob API",
    "version": "0.1.0",
    "summary": "Bob's routes in the Bike4Mind app that take a Bike4Mind API key: start a site read, a two-site comparison or a re-check, and read them back.",
    "description": "Bob is an app inside Bike4Mind: three checks on a marketing page - can a machine read it, is it secure, would a visitor act - every quote checked against the page.\n\nThis document describes Bob's three routes that a Bike4Mind API key with `bob:read` or `bob:run` reaches. The Bike4Mind app serves them at https://app.bike4mind.com. The site that publishes this file, bob.bike4mind.com, is static and has no API of its own.\n\nIn the Bike4Mind app, runs start at https://app.bike4mind.com/bob, after a Bike4Mind sign-in. Bike4Mind's read-only MCP server, https://bike4mind.com/api/mcp, needs no key and answers questions about Bike4Mind and its products, Bob among them. It cannot start a run.\n\n## Getting a key\nIn the Bike4Mind app, open API Keys from the profile menu and create a key with the `bob:run` scope. A `bob:run` key starts site reads, comparisons and re-checks, and reads them back. It can also rename, favorite, archive and delete the key owner's reports. A `bob:read` key only reads. By default, Bike4Mind's hosted app lets only accounts with a paid plan or bought credits make and use API keys.\n\n## Sending the key\nSend it as `Authorization: Bearer <key>`, `x-api-key: <key>` or `Authorization: ApiKey <key>`. The Bearer form is read as an API key only when the key begins `b4m_`.\n\n## Scopes\nEvery GET here takes a key holding `bob:read`, `bob:run` or `admin:*`. Every POST, PATCH and DELETE takes `bob:run` or `admin:*`. Each operation lists its scopes in `x-required-scopes`, and a key needs any one of them. A key refused for its scopes answers 403.\n\n## Methods\nbob-run takes GET, POST, PATCH and DELETE. bob-compare and bob-recheck take GET and POST. HEAD is answered wherever GET is. Any other method answers 405 before the key is checked, with `Allow` naming the methods the route takes: `GET, HEAD, POST, PATCH, DELETE` on bob-run, `GET, HEAD, POST` on bob-compare and bob-recheck.\n\n## Credits\nA run started with a key bills the key owner's Bike4Mind credits and publishes its report as them, by the same rules as a run started in the app, with one exception: it is never the free first run. The free run can only be a run started in the app, and only the account's first full run: any earlier run that started and did not fail uses it up, a run started with a key included. A key's quota read never says `freeRun`. `organizationId` picks the account billed: an organization id, null for the key owner's personal account, or absent for their own organization (personal if they have none). A comparison starts two runs. A re-check costs no credits. For what a run costs, read https://bob.bike4mind.com/llms.txt.\n\n## Starting and reading back\nA start answers 202 as soon as the run is queued. The caller mints every run and comparison id, as a UUID. Poll `GET /api/premium-bob/bob-run?id=<runId>&view=agent`, or `GET /api/premium-bob/bob-compare?id=<comparisonId>&view=agent`, until `status` is `ok` or `failed`.\n\nA start Bob turns away before starting anything answers 200 with `ok: false` and Bob's own words in `error`: the daily run cap, a credits refusal, or the same user's other starts still being taken. Nothing was started or charged.\n\n## Limits\nBob caps the runs one user starts in any 24 hours: `GET /api/premium-bob/bob-run?quota` says how many are left. Bike4Mind also limits each key's requests per minute and per day, and answers 429 with `Retry-After` past either. The GETs here do not count against a key's daily limit.\n\n## Errors Bike4Mind answers before Bob\nBike4Mind turns some requests away before they reach Bob's routes, and those answers are neither Bob's `Refusal` nor `HostError`. A query key with square brackets (`?x[0]=1`), on any `/api/premium-bob/` path, answers 400 with `{\"message\":null}`. A request sent with `Content-Type: application/json` whose body does not parse, on any method, answers 400 with the plain text `Invalid JSON`, and the answer's own `Content-Type` also says `application/json`. A body over 1 MB answers 413 with the plain text `Body exceeded 1mb limit`. Send flat query keys and a JSON body that parses."
  },
  "externalDocs": {
    "description": "What bob.bike4mind.com publishes for AI agents",
    "url": "https://bob.bike4mind.com/for-agents"
  },
  "servers": [
    {
      "url": "https://app.bike4mind.com",
      "description": "The Bike4Mind app, which serves Bob's routes"
    }
  ],
  "security": [
    { "bearerAuth": [] },
    { "apiKeyAuth": [] }
  ],
  "tags": [
    { "name": "Runs", "description": "One site read: start it, read it back, list your reports, and see how many runs are left today." },
    { "name": "Comparisons", "description": "Two site reads started together and read side by side." },
    { "name": "Re-checks", "description": "One Machine-read check run again against a run's site. Costs no credits." }
  ],
  "paths": {
    "/api/premium-bob/bob-run": {
      "get": {
        "operationId": "getBobRun",
        "tags": ["Runs"],
        "summary": "Read a run, list your reports, or see the runs left today",
        "description": "Reads on one route, picked by the query: the first of `list`, `reportCount`, `compare`, `quota` and `id` that is sent answers, and the ones after it are not read. `reportCount` and `compare` are the app's own reads and are not listed here: `reportCount` answers how many finished reports the key owner has, and `compare=<runId>` answers the runs that one can be compared with, as `anchor` and `candidates`, so `?quota&compare=<runId>` answers that and carries no `quota`. Only the key owner's own runs are ever read: a run that is not theirs, or was deleted, answers the same 404 as one that does not exist.",
        "x-required-scopes": ["bob:read", "bob:run", "admin:*"],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "description": "The run to read: the UUID the caller minted when it started the run. Required unless `list` or `quota` is sent.",
            "schema": { "type": "string", "format": "uuid" }
          },
          {
            "name": "view",
            "in": "query",
            "description": "With `id`: `agent` answers the run in the shape an agent reads (`AgentRun`). Any other value is ignored, as is none: the answer is then the run's stored record as the app reads it. It is never a 400.",
            "schema": { "type": "string" }
          },
          {
            "name": "list",
            "in": "query",
            "description": "`recent`: the owner's finished reports, newest first. `archived`: the reports they archived, newest archived first. A comparison is one row.",
            "schema": { "type": "string", "enum": ["recent", "archived"] }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "With `list`: at most this many single runs and at most this many comparisons. The server clamps it to the list's own cap, which is also the default. A value that is not a whole number above 0 is ignored and the answer is 200 with the cap applied, as if `limit` was not sent. It is never a 400.",
            "schema": { "type": "integer" }
          },
          {
            "name": "quota",
            "in": "query",
            "description": "Send it with any value, or none, to read the runs left under the daily cap.",
            "allowEmptyValue": true,
            "schema": { "type": "string" }
          },
          {
            "name": "organizationId",
            "in": "query",
            "description": "With `quota`: the account whose credits `lowCredits` and `scanOnly` read. Absent for the key owner's own organization, empty for their personal account.",
            "schema": { "type": "string" }
          },
          {
            "name": "screenshots",
            "in": "query",
            "description": "With `quota`: send it with any value, or none, when the run you will start uses a panel that takes screenshots. That includes the default panel, which a POST with no `packId` reads with. `scanOnly` then counts the screenshot reserve the start sets aside. Without it, `?quota` answers for a panel that takes none, so its `scanOnly` can be absent when the start of a default-panel run still answers `scanOnly: \"balance\"`.",
            "allowEmptyValue": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "The run, the list, or the quota.",
            "headers": {
              "Cache-Control": { "$ref": "#/components/headers/Cache-Control" }
            },
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    { "$ref": "#/components/schemas/RunAnswer" },
                    { "$ref": "#/components/schemas/ReportListAnswer" },
                    { "$ref": "#/components/schemas/QuotaAnswer" }
                  ]
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/ReadForbidden" },
          "404": { "$ref": "#/components/responses/RunNotFound" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" },
          "429": { "$ref": "#/components/responses/KeyRateLimited" }
        }
      },
      "post": {
        "operationId": "startBobRun",
        "tags": ["Runs"],
        "summary": "Start a site read",
        "description": "Starts one run and answers 202 once it is queued. The run reads in the background: poll `GET /api/premium-bob/bob-run?id=<runId>&view=agent` for it. It bills the key owner's credits. Bob reads public pages the way a visitor would: no form is submitted and nothing is signed in to.",
        "x-required-scopes": ["bob:run", "admin:*"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/StartRun" }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Queued. The report is not in this answer: read it back by `runId`.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RunStarted" }
              }
            }
          },
          "200": { "$ref": "#/components/responses/StartRefused" },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/RunForbidden" },
          "404": { "$ref": "#/components/responses/OrganizationNotFound" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" },
          "429": { "$ref": "#/components/responses/KeyRateLimited" },
          "503": { "$ref": "#/components/responses/NotStarted" }
        }
      },
      "patch": {
        "operationId": "updateBobRun",
        "tags": ["Runs"],
        "summary": "Rename, favorite or archive a report",
        "description": "Changes one of the key owner's reports: a run by its `runId`, or a comparison by its comparison id, which changes both of its sides. Send at least one of `favorite`, `label` and `archived`. Archiving hides the report from `list=recent` and puts it in `list=archived`. It deletes nothing, and its share links stay. Only the key owner's own reports are changed: one that is not theirs, or was deleted, answers 404.",
        "x-required-scopes": ["bob:run", "admin:*"],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "The run or comparison to change, by its UUID.",
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ReportChange" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Changed.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ReportChanged" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/RunForbidden" },
          "404": { "$ref": "#/components/responses/RunNotFound" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" },
          "429": { "$ref": "#/components/responses/KeyRateLimited" }
        }
      },
      "delete": {
        "operationId": "deleteBobRun",
        "tags": ["Runs"],
        "summary": "Delete a report",
        "description": "Deletes one of the key owner's reports: a run by its `runId`, or a comparison by its comparison id. Its published copies are taken down, so every share link to it stops resolving, and its stored screenshots are erased. The run itself is marked deleted rather than removed, so it still counts toward the daily cap. A report still reading answers 409: delete it once it is finished. If a published copy cannot be taken down the report is left as it was and the answer is 500: send the delete again. Only the key owner's own reports are deleted: one that is not theirs, or was already deleted, answers 404.",
        "x-required-scopes": ["bob:run", "admin:*"],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "The run or comparison to delete, by its UUID.",
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ReportDeleted" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/RunForbidden" },
          "404": { "$ref": "#/components/responses/RunNotFound" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" },
          "409": { "$ref": "#/components/responses/StillReading" },
          "429": { "$ref": "#/components/responses/KeyRateLimited" },
          "500": { "$ref": "#/components/responses/NotDeleted" }
        }
      }
    },
    "/api/premium-bob/bob-compare": {
      "get": {
        "operationId": "getBobComparison",
        "tags": ["Comparisons"],
        "summary": "Read a comparison",
        "description": "Both runs of one comparison, by the comparison's id. Only the key owner's own comparisons are read: any other answers 404.",
        "x-required-scopes": ["bob:read", "bob:run", "admin:*"],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "The comparison to read: the `comparisonId` the caller minted when it started the comparison.",
            "schema": { "type": "string", "format": "uuid" }
          },
          {
            "name": "view",
            "in": "query",
            "description": "`agent` answers the comparison in the shape an agent reads (`AgentComparison`). Without it, each side is the run's stored record as the app reads it.",
            "schema": { "type": "string", "enum": ["agent"] }
          }
        ],
        "responses": {
          "200": {
            "description": "The comparison.",
            "headers": {
              "Cache-Control": { "$ref": "#/components/headers/Cache-Control" }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ComparisonAnswer" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/ReadForbidden" },
          "404": { "$ref": "#/components/responses/ComparisonNotFound" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" },
          "429": { "$ref": "#/components/responses/KeyRateLimited" }
        }
      },
      "post": {
        "operationId": "startBobComparison",
        "tags": ["Comparisons"],
        "summary": "Start a two-site comparison",
        "description": "Starts two runs, one per site, with the same panel, and links them as one comparison. Both must fit under the daily cap or neither starts. Answers 202 once they are queued: poll `GET /api/premium-bob/bob-compare?id=<comparisonId>&view=agent`. If the queue refuses one side, that side is settled `failed` and the other still runs.",
        "x-required-scopes": ["bob:run", "admin:*"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/StartComparison" }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Queued.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ComparisonStarted" }
              }
            }
          },
          "200": { "$ref": "#/components/responses/StartRefused" },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/RunForbidden" },
          "404": { "$ref": "#/components/responses/OrganizationNotFound" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" },
          "429": { "$ref": "#/components/responses/KeyRateLimited" },
          "503": { "$ref": "#/components/responses/NotStarted" }
        }
      }
    },
    "/api/premium-bob/bob-recheck": {
      "get": {
        "operationId": "listBobRechecks",
        "tags": ["Re-checks"],
        "summary": "List a run's re-checks",
        "description": "Every re-check of one of the key owner's runs, oldest first.",
        "x-required-scopes": ["bob:read", "bob:run", "admin:*"],
        "parameters": [
          {
            "name": "runId",
            "in": "query",
            "required": true,
            "description": "The run whose re-checks to list.",
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": {
            "description": "The run's re-checks.",
            "headers": {
              "Cache-Control": { "$ref": "#/components/headers/Cache-Control" }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RechecksAnswer" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/ReadForbidden" },
          "404": { "$ref": "#/components/responses/RunNotFound" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" },
          "429": { "$ref": "#/components/responses/KeyRateLimited" }
        }
      },
      "post": {
        "operationId": "recheckBobFinding",
        "tags": ["Re-checks"],
        "summary": "Re-check one finding",
        "description": "Runs one Machine-read check again against the run's own site, adds the reading to the run's re-checks and answers it. The run's scan is never edited. Costs no credits. Only checks the scan measures from outside can be re-checked, and only on a run with a Machine read. A run takes a limited number of re-checks, and the same check pressed again soon after is refused: both answer 429 with `retryAfterMs`.",
        "x-required-scopes": ["bob:run", "admin:*"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/StartRecheck" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The new reading.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RecheckAnswer" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/RunForbidden" },
          "404": { "$ref": "#/components/responses/RunNotFound" },
          "409": {
            "description": "The check is not one this scan measures, or the run has no Machine read to re-check.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Refusal" }
              }
            }
          },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" },
          "429": {
            "description": "A re-check limit (Bob's own, with `retryAfterMs`: null when a retry will never pass) or the key's request limit (Bike4Mind's, with `Retry-After`).",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    { "$ref": "#/components/schemas/RetryRefusal" },
                    { "$ref": "#/components/schemas/HostError" }
                  ]
                }
              }
            }
          },
          "503": {
            "description": "Bob's own controls or load turned the scan away. It says nothing about the site, nothing was saved, and the run's re-check allowance is untouched. `Retry-After` is sent when a retry time is known.",
            "headers": {
              "Retry-After": { "$ref": "#/components/headers/Retry-After" }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RetryRefusal" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "`Authorization: Bearer <key>`, with a Bike4Mind API key that begins `b4m_`. `Authorization: ApiKey <key>` is accepted too."
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "`x-api-key: <key>`, with a Bike4Mind API key."
      }
    },
    "headers": {
      "Allow": {
        "description": "The methods the route takes, HEAD included wherever it takes GET.",
        "schema": { "type": "string" }
      },
      "Cache-Control": {
        "description": "The answer is the key owner's own: no browser cache or CDN may store it.",
        "schema": { "type": "string", "const": "private, no-store" }
      },
      "Retry-After": {
        "description": "Seconds to wait before trying again.",
        "schema": { "type": "integer" }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "A missing or malformed parameter or body field. `error` says which. Bike4Mind's own 400s for a bracketed query key or a JSON body that does not parse have other bodies: see Errors Bike4Mind answers before Bob.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Refusal" }
          }
        }
      },
      "Unauthorized": {
        "description": "No API key or session, or a key Bike4Mind does not accept.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/HostError" },
            "example": { "error": "Authentication required" }
          }
        }
      },
      "ReadForbidden": {
        "description": "The key holds none of `bob:read`, `bob:run` and `admin:*`: Bike4Mind's refusal, listing `required_scopes`, or Bob's own, with `code: \"missing_scope\"`. Or Bike4Mind refused the key or its owner for another reason.",
        "content": {
          "application/json": {
            "schema": {
              "anyOf": [
                { "$ref": "#/components/schemas/ScopeRefusal" },
                { "$ref": "#/components/schemas/HostError" }
              ]
            },
            "example": { "ok": false, "error": "API key is missing the bob:read scope", "code": "missing_scope" }
          }
        }
      },
      "RunForbidden": {
        "description": "The key holds neither `bob:run` nor `admin:*`: Bob's refusal, with `code: \"missing_scope\"`, or Bike4Mind's, listing `required_scopes`. Or the `organizationId` sent is not an account the key owner can bill, or Bike4Mind refused the key or its owner for another reason.",
        "content": {
          "application/json": {
            "schema": {
              "anyOf": [
                { "$ref": "#/components/schemas/ScopeRefusal" },
                { "$ref": "#/components/schemas/HostError" }
              ]
            },
            "example": { "ok": false, "error": "API key is missing the bob:run scope", "code": "missing_scope" }
          }
        }
      },
      "RunNotFound": {
        "description": "No such run for this key's owner: it does not exist, is someone else's, or was deleted.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Refusal" },
            "example": { "ok": false, "error": "Run not found." }
          }
        }
      },
      "ComparisonNotFound": {
        "description": "No such comparison for this key's owner.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Refusal" },
            "example": { "ok": false, "error": "Comparison not found." }
          }
        }
      },
      "OrganizationNotFound": {
        "description": "With an `admin:*` key, the `organizationId` sent names no organization. Any other key gets 403 for an organization it cannot bill.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/HostError" }
          }
        }
      },
      "StartRefused": {
        "description": "Bob turned the start away before starting anything, in its own words: the daily run cap, a credits refusal, or the same user's other starts still being taken. Nothing was started or charged.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/StartRefusal" }
          }
        }
      },
      "NotStarted": {
        "description": "The queue refused the work, so nothing will read: try again in a few minutes.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Refusal" }
          }
        }
      },
      "MethodNotAllowed": {
        "description": "The route does not take this method. Bike4Mind answers it before the key is checked, with `Allow` naming the methods the route takes.",
        "headers": {
          "Allow": { "$ref": "#/components/headers/Allow" }
        },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/HostError" }
          }
        }
      },
      "StillReading": {
        "description": "The report is still being read, and nothing was deleted.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Refusal" },
            "example": { "ok": false, "error": "This report is still being read. Delete it once it is finished." }
          }
        }
      },
      "NotDeleted": {
        "description": "A published copy of the report could not be taken down, so the report was left as it was. Send the delete again.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Refusal" },
            "example": { "ok": false, "error": "The report could not be deleted. Try again." }
          }
        }
      },
      "KeyRateLimited": {
        "description": "The key's per-minute or per-day request limit.",
        "headers": {
          "Retry-After": { "$ref": "#/components/headers/Retry-After" }
        },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/HostError" }
          }
        }
      }
    },
    "schemas": {
      "StartRun": {
        "type": "object",
        "required": ["url", "runId"],
        "properties": {
          "url": {
            "type": "string",
            "description": "The page to read: a public web address, with or without its scheme, such as `acme.io` or `https://acme.io/pricing`. At most 2048 characters once the scheme is removed. A private or reserved address is refused.",
            "examples": ["acme.io"]
          },
          "runId": {
            "type": "string",
            "format": "uuid",
            "description": "A new UUID the caller mints. It becomes the run's id."
          },
          "organizationId": {
            "type": ["string", "null"],
            "description": "The account billed: an organization id, null for the key owner's personal account, or absent for their own organization (personal if they have none)."
          },
          "packId": {
            "type": "string",
            "description": "The panel to read with: one of Bob's panel ids, or a custom panel's `cpanel-` id saved in the billed account. Absent or unknown reads with the default panel."
          },
          "packSource": {
            "type": "string",
            "enum": ["router", "user", "default"],
            "description": "How the panel was chosen. Only a claim: the run checks it against its own read of the page."
          }
        }
      },
      "StartComparison": {
        "type": "object",
        "required": ["comparisonId", "you", "them"],
        "properties": {
          "comparisonId": {
            "type": "string",
            "format": "uuid",
            "description": "A new UUID the caller mints. It becomes the comparison's id. The three ids must differ."
          },
          "you": { "$ref": "#/components/schemas/ComparisonSide" },
          "them": { "$ref": "#/components/schemas/ComparisonSide" },
          "organizationId": {
            "type": ["string", "null"],
            "description": "The account billed, as on a single run."
          },
          "packId": {
            "type": "string",
            "description": "The panel both sides read with: one of Bob's panel ids. A custom panel's `cpanel-` id is refused. Absent or unknown reads with the default panel."
          },
          "packSource": {
            "type": "string",
            "enum": ["router", "user", "default"],
            "description": "How the panel was chosen, as on a single run."
          }
        }
      },
      "ComparisonSide": {
        "type": "object",
        "required": ["url", "runId"],
        "properties": {
          "url": {
            "type": "string",
            "description": "This side's page, in the forms `url` takes on a single run. At most 2048 characters with the scheme counted, unlike a single run. The two sides must be different pages."
          },
          "runId": {
            "type": "string",
            "format": "uuid",
            "description": "A new UUID the caller mints for this side's run."
          }
        }
      },
      "StartRecheck": {
        "type": "object",
        "required": ["runId", "checkId"],
        "properties": {
          "runId": {
            "type": "string",
            "format": "uuid",
            "description": "One of the key owner's runs."
          },
          "checkId": {
            "type": "string",
            "description": "The Machine-read check to run again, by its id in the report, such as `t1.llms_txt`."
          }
        }
      },
      "RunStarted": {
        "type": "object",
        "required": ["ok", "runId"],
        "properties": {
          "ok": { "const": true },
          "runId": { "type": "string", "format": "uuid" },
          "scanOnly": {
            "type": "string",
            "enum": ["balance", "member_cap"],
            "description": "Set when the billed account could not pay for the reader panel, so the run reads the Machine read only, which is free: `balance` for too few credits, `member_cap` when the organization's credit limit for the member is reached."
          }
        }
      },
      "ComparisonStarted": {
        "type": "object",
        "required": ["ok", "comparisonId", "runIds"],
        "properties": {
          "ok": { "const": true },
          "comparisonId": { "type": "string", "format": "uuid" },
          "runIds": {
            "type": "object",
            "required": ["you", "them"],
            "properties": {
              "you": { "type": "string", "format": "uuid" },
              "them": { "type": "string", "format": "uuid" }
            }
          }
        }
      },
      "RunAnswer": {
        "type": "object",
        "required": ["ok", "run"],
        "properties": {
          "ok": { "const": true },
          "run": {
            "oneOf": [
              { "$ref": "#/components/schemas/AgentRun" },
              { "$ref": "#/components/schemas/RunRecord" }
            ]
          }
        }
      },
      "AgentRun": {
        "type": "object",
        "description": "One run, as an agent reads it (`view=agent`).",
        "required": ["runId", "url", "status", "progress", "createdAt", "settledAt", "error", "scanOnly", "reportMarkdown", "appPath", "publishedPath", "visibility"],
        "properties": {
          "runId": { "type": "string", "format": "uuid" },
          "url": { "type": "string", "description": "The site the run read." },
          "status": { "type": "string", "enum": ["reading", "ok", "failed"] },
          "progress": {
            "type": ["object", "null"],
            "description": "Readers finished of the panel's readers. Null when there are none to count, as on a run that reads the Machine read only.",
            "required": ["done", "total"],
            "properties": {
              "done": { "type": "integer" },
              "total": { "type": "integer" }
            }
          },
          "createdAt": { "type": "string", "format": "date-time" },
          "settledAt": { "type": ["string", "null"], "format": "date-time", "description": "When the run settled `ok` or `failed`, or a little after. Null while it reads." },
          "error": { "type": ["string", "null"], "description": "A failed run's reason, in the words the app shows." },
          "scanOnly": { "type": ["string", "null"], "enum": ["balance", "member_cap", null], "description": "As on the start's answer." },
          "reportMarkdown": { "type": ["string", "null"], "description": "Once the run settles `ok`: the whole report, as the Markdown the app's report screen downloads." },
          "appPath": { "type": "string", "description": "The report in the app, `/bob?run=<runId>`, a path on https://app.bike4mind.com." },
          "publishedPath": { "type": ["string", "null"], "description": "The published report's path, once the run has published one." },
          "visibility": { "type": ["string", "null"], "enum": ["private", "organization", null], "description": "Who can open the published report." }
        }
      },
      "RunRecord": {
        "type": "object",
        "description": "The run's stored record, as the app's report screen reads it. Only its top level is described here: the rest is the app's, and `view=agent` answers the shape an agent reads.",
        "required": ["_id", "url", "status"],
        "properties": {
          "_id": { "type": "string", "format": "uuid", "description": "The run's id." },
          "url": { "type": "string" },
          "status": { "type": "string", "enum": ["reading", "ok", "failed"] },
          "report": { "type": ["object", "null"], "description": "The report the app renders, once the run settles `ok`.", "additionalProperties": true }
        },
        "additionalProperties": true
      },
      "ReportChange": {
        "type": "object",
        "description": "At least one of the three.",
        "minProperties": 1,
        "properties": {
          "favorite": { "type": "boolean", "description": "Mark the report a favorite, or take the mark off." },
          "label": { "type": ["string", "null"], "description": "The report's name, at most 80 characters. `null` or a blank string clears it." },
          "archived": { "type": "boolean", "description": "`true` archives the report, `false` brings it back." }
        }
      },
      "ReportChanged": {
        "type": "object",
        "required": ["ok"],
        "properties": {
          "ok": { "const": true },
          "favorite": { "type": "boolean", "description": "Sent back when the request carried `favorite`." }
        }
      },
      "ReportDeleted": {
        "type": "object",
        "required": ["ok"],
        "properties": {
          "ok": { "const": true }
        }
      },
      "ReportListAnswer": {
        "type": "object",
        "required": ["ok", "runs"],
        "properties": {
          "ok": { "const": true },
          "runs": {
            "type": "array",
            "items": {
              "oneOf": [
                { "$ref": "#/components/schemas/ReportRow" },
                { "$ref": "#/components/schemas/ComparisonRow" }
              ]
            }
          }
        }
      },
      "ReportRow": {
        "type": "object",
        "description": "One single-site report.",
        "required": ["kind", "runId", "url", "createdAt", "favorite"],
        "properties": {
          "kind": { "const": "run" },
          "runId": { "type": "string", "format": "uuid" },
          "url": { "type": "string" },
          "createdAt": { "type": "string", "format": "date-time" },
          "favorite": { "type": "boolean" },
          "label": { "type": "string", "description": "The name the owner gave the report, when they gave one." },
          "archivedAt": { "type": "string", "format": "date-time" },
          "credits": { "type": "number", "description": "What the run cost in credits, once that is known." }
        },
        "additionalProperties": true
      },
      "ComparisonRow": {
        "type": "object",
        "description": "One comparison, as one row.",
        "required": ["kind", "comparisonId", "you", "them", "youRunId", "themRunId", "createdAt", "favorite"],
        "properties": {
          "kind": { "const": "comparison" },
          "comparisonId": { "type": "string", "format": "uuid" },
          "you": { "type": "string", "description": "The first side's site." },
          "them": { "type": "string", "description": "The second side's site." },
          "youRunId": { "type": "string", "format": "uuid" },
          "themRunId": { "type": "string", "format": "uuid" },
          "createdAt": { "type": "string", "format": "date-time" },
          "favorite": { "type": "boolean" },
          "label": { "type": "string" },
          "archivedAt": { "type": "string", "format": "date-time" },
          "credits": { "type": "number", "description": "What the two runs cost together, once that is known." }
        },
        "additionalProperties": true
      },
      "QuotaAnswer": {
        "type": "object",
        "required": ["ok", "quota"],
        "properties": {
          "ok": { "const": true },
          "quota": {
            "type": "object",
            "required": ["limit", "left", "nextSlotAt"],
            "properties": {
              "limit": { "type": "integer", "description": "Runs one user may start in any 24 hours." },
              "left": { "type": "integer", "description": "Runs left now." },
              "nextSlotAt": { "type": ["string", "null"], "format": "date-time", "description": "When the oldest counted run leaves the window and frees a slot. Null while no run counts." },
              "lowCredits": { "type": "boolean", "description": "The billed account's next run may skip its security scan for credits." },
              "compareLowCredits": { "type": "boolean", "description": "As `lowCredits`, for a comparison." },
              "scanOnly": { "type": "string", "enum": ["balance", "member_cap"], "description": "The next run will read the Machine read only, and why." },
              "freeRun": { "type": "boolean", "description": "The user's next run started in the app is free: their first. Never true on a key's quota read: a run started with a key is never the free one." }
            }
          }
        }
      },
      "ComparisonAnswer": {
        "type": "object",
        "required": ["ok", "comparison"],
        "properties": {
          "ok": { "const": true },
          "comparison": {
            "oneOf": [
              { "$ref": "#/components/schemas/AgentComparison" },
              { "$ref": "#/components/schemas/ComparisonRecord" }
            ]
          }
        }
      },
      "AgentComparison": {
        "type": "object",
        "description": "One comparison, as an agent reads it (`view=agent`).",
        "required": ["comparisonId", "status", "you", "them", "summaryMarkdown", "appPath"],
        "properties": {
          "comparisonId": { "type": "string", "format": "uuid" },
          "status": { "type": "string", "enum": ["reading", "ok", "failed"], "description": "`reading` while either side reads, `ok` once both settled and at least one is ok, `failed` if both failed." },
          "you": { "oneOf": [{ "$ref": "#/components/schemas/AgentRun" }, { "type": "null" }] },
          "them": { "oneOf": [{ "$ref": "#/components/schemas/AgentRun" }, { "type": "null" }] },
          "summaryMarkdown": { "type": ["string", "null"], "description": "Once no side is still reading: who passes what, each way, as Markdown. Null before that." },
          "appPath": { "type": "string", "description": "The comparison in the app, `/bob?compare=<comparisonId>`, a path on https://app.bike4mind.com." }
        }
      },
      "ComparisonRecord": {
        "type": "object",
        "required": ["id", "you", "them"],
        "properties": {
          "id": { "type": "string", "format": "uuid", "description": "The comparison's id." },
          "you": { "oneOf": [{ "$ref": "#/components/schemas/RunRecord" }, { "type": "null" }] },
          "them": { "oneOf": [{ "$ref": "#/components/schemas/RunRecord" }, { "type": "null" }] }
        }
      },
      "RechecksAnswer": {
        "type": "object",
        "required": ["ok", "rechecks"],
        "properties": {
          "ok": { "const": true },
          "rechecks": { "type": "array", "items": { "$ref": "#/components/schemas/Recheck" } }
        }
      },
      "RecheckAnswer": {
        "type": "object",
        "required": ["ok", "recheck"],
        "properties": {
          "ok": { "const": true },
          "recheck": { "$ref": "#/components/schemas/Recheck" }
        }
      },
      "Recheck": {
        "type": "object",
        "description": "One re-check of one check. It never replaces the scan's own reading.",
        "required": ["checkId", "at", "was", "state", "value", "evidence", "underlying", "soft404Host", "requests"],
        "properties": {
          "checkId": { "type": "string" },
          "at": { "type": "string", "format": "date-time", "description": "When the re-check ran." },
          "was": { "$ref": "#/components/schemas/CellState", "description": "The check's state on the run's scan." },
          "state": { "$ref": "#/components/schemas/CellState" },
          "value": { "type": "string" },
          "evidence": { "type": "string" },
          "underlying": { "type": ["string", "null"], "enum": ["pass", "warn", "fail", "na", null], "description": "The raw status behind `state`." },
          "soft404Host": { "type": ["boolean", "null"], "description": "Whether the site answered 200 for a path that cannot exist. Null when that path got no answer." },
          "requests": { "type": "integer", "description": "Requests the re-check spent, robots.txt included." }
        }
      },
      "CellState": {
        "type": "string",
        "enum": ["pass", "warn", "fail", "na", "notmeasured", "invalid"]
      },
      "Refusal": {
        "type": "object",
        "required": ["ok", "error"],
        "properties": {
          "ok": { "const": false },
          "error": { "type": "string", "description": "What was wrong, in Bob's words." }
        }
      },
      "StartRefusal": {
        "type": "object",
        "required": ["ok", "error"],
        "properties": {
          "ok": { "const": false },
          "error": { "type": "string", "description": "Why, in Bob's words." },
          "reason": {
            "type": "string",
            "enum": ["credits", "disputed", "member_cap", "member_cap_pending"],
            "description": "Set on a credits refusal: `credits` when adding credits would help, otherwise the refusal's own kind."
          }
        }
      },
      "RetryRefusal": {
        "type": "object",
        "required": ["ok", "error", "retryAfterMs"],
        "properties": {
          "ok": { "const": false },
          "error": { "type": "string" },
          "retryAfterMs": { "type": ["integer", "null"], "description": "Milliseconds until a retry could pass. Null when it never will, or no time is known." }
        }
      },
      "ScopeRefusal": {
        "type": "object",
        "description": "Bob's refusal of a key without the scope this method needs.",
        "required": ["ok", "error", "code"],
        "properties": {
          "ok": { "const": false },
          "error": { "type": "string" },
          "code": { "const": "missing_scope" }
        }
      },
      "HostError": {
        "type": "object",
        "description": "Bike4Mind's error body, from its sign-in, scope and rate-limit checks in front of Bob's routes.",
        "required": ["error"],
        "properties": {
          "error": { "type": "string" },
          "request_id": { "type": "string", "description": "Correlation id for this request." },
          "required_scopes": { "type": "array", "items": { "type": "string" }, "description": "On a scope refusal: the scopes the route accepts. Any one of them is enough." }
        },
        "additionalProperties": true
      }
    }
  }
}
