{
  "openapi": "3.1.0",
  "info": {
    "title": "che.sh",
    "version": "1.0.0",
    "summary": "Anonymous decision trees you can curl.",
    "description": "Front door to rvbbit decision trees. Nothing you send is kept. Curl always uses the latest Jev model. Full narrative docs: https://che.sh/llms.txt and https://che.sh/llms-full.txt. Compare-several-models is a browser UI feature and is not part of this document.",
    "contact": {
      "name": "Ryan Robitaille / Datarabbit",
      "url": "https://x.com/ryrobes"
    },
    "license": {
      "name": "Use the public HTTP API as documented. che.sh is free."
    }
  },
  "servers": [
    {
      "url": "https://che.sh"
    }
  ],
  "tags": [
    {
      "name": "decide",
      "description": "Run or inspect a tree"
    },
    {
      "name": "trees",
      "description": "Create, read, update, usage"
    },
    {
      "name": "shares",
      "description": "Read-only shared compares"
    },
    {
      "name": "meta",
      "description": "Status, docs, health"
    }
  ],
  "components": {
    "securitySchemes": {
      "EditKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Edit-Key",
        "description": "The edit_key returned once when you POST /api/trees."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "ok",
          "error",
          "message"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "string",
            "examples": [
              "no_such_tree",
              "rate",
              "empty",
              "napping"
            ]
          },
          "message": {
            "type": "string"
          }
        }
      },
      "PathStep": {
        "type": "object",
        "properties": {
          "node": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "route": {
            "type": "string"
          },
          "score": {
            "type": "number"
          },
          "p": {
            "type": "number",
            "description": "Probability of the route taken."
          },
          "threshold": {
            "type": "number",
            "description": "Present on yes/no steps."
          }
        }
      },
      "Decision": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "status": {
            "type": "string",
            "examples": [
              "complete"
            ]
          },
          "label": {
            "type": "string"
          },
          "confidence": {
            "type": "number"
          },
          "path": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PathStep"
            }
          },
          "model": {
            "type": "string",
            "examples": [
              "typesafe/jev-1.14"
            ]
          },
          "steps": {
            "type": "integer"
          },
          "ms": {
            "type": "integer"
          },
          "cost_usd": {
            "type": "number"
          },
          "cached": {
            "type": "boolean",
            "description": "Demo-tree fingerprint cache hit. The input is not stored."
          },
          "image": {
            "type": "object",
            "properties": {
              "w": {
                "type": "integer"
              },
              "h": {
                "type": "integer"
              },
              "bytes": {
                "type": "integer"
              }
            }
          },
          "variables": {
            "type": "object",
            "description": "Ephemeral per-run fields, never stored. Missing values are null."
          },
          "extractions": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Each extraction: node, model, route, values, missing, ms, cost_usd, shared."
          },
          "extract_cost_usd": {
            "type": "number",
            "description": "Extraction cost; cost_usd remains decision cost. Sum for total."
          },
          "known_answer": {
            "type": "object",
            "description": "Present when the tree's owner marked the right answer for this exact input on this exact tree. Only a fingerprint is stored, never the input.",
            "properties": {
              "leaf": {
                "type": "string"
              },
              "expected": {
                "type": "string"
              },
              "sample": {
                "type": "string"
              },
              "correct": {
                "type": "boolean"
              }
            }
          },
          "follow": {
            "type": "object",
            "description": "present when the answer named another tree",
            "properties": {
              "hops": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "trees": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "stopped": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "total_cost_usd": {
                "type": "number"
              },
              "total_ms": {
                "type": "integer"
              },
              "final": {
                "type": "object"
              }
            }
          },
          "page": {
            "type": "object",
            "description": "present for text/html input"
          }
        }
      },
      "TreeDoc": {
        "type": "object",
        "required": [
          "v",
          "root",
          "nodes"
        ],
        "description": "Editor document: ask, extract, answer. Extract fields feed later {placeholders}; text/HTML only, public, no key. See https://che.sh/llms-full.txt.",
        "properties": {
          "v": {
            "type": "integer",
            "const": 1
          },
          "root": {
            "type": "string",
            "description": "Id of the first question."
          },
          "nodes": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/AskNode"
                },
                {
                  "$ref": "#/components/schemas/ExtractNode"
                },
                {
                  "$ref": "#/components/schemas/AnswerNode"
                }
              ]
            }
          }
        }
      },
      "Tree": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "doc": {
            "$ref": "#/components/schemas/TreeDoc"
          },
          "n_nodes": {
            "type": "integer"
          },
          "depth": {
            "type": "integer"
          },
          "revision": {
            "type": "integer"
          },
          "created_at": {
            "type": "string"
          },
          "updated_at": {
            "type": "string"
          }
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "awake": {
            "type": "boolean"
          },
          "images": {
            "type": "boolean"
          },
          "max_input_chars": {
            "type": "integer"
          },
          "max_nodes": {
            "type": "integer"
          },
          "max_depth": {
            "type": "integer"
          },
          "max_branches": {
            "type": "integer"
          },
          "max_question_chars": {
            "type": "integer"
          },
          "max_answer_chars": {
            "type": "integer"
          },
          "demo_slugs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Way": {
        "type": "object",
        "required": [
          "label",
          "to"
        ],
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40
          },
          "hint": {
            "type": "string",
            "maxLength": 200
          },
          "to": {
            "type": "string"
          }
        }
      },
      "AskNode": {
        "type": "object",
        "required": [
          "kind",
          "text",
          "out"
        ],
        "properties": {
          "text": {
            "type": "string",
            "description": "Plain text; later ask/answer nodes and hints may use {field_name} placeholders."
          },
          "x": {
            "type": "integer"
          },
          "y": {
            "type": "integer"
          },
          "kind": {
            "const": "ask"
          },
          "out": {
            "type": "array",
            "minItems": 2,
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/Way"
            }
          },
          "threshold": {
            "type": "number",
            "minimum": 0.05,
            "maximum": 0.95,
            "default": 0.5
          }
        }
      },
      "AnswerNode": {
        "type": "object",
        "required": [
          "kind",
          "text"
        ],
        "properties": {
          "text": {
            "type": "string",
            "description": "Plain text; later ask/answer nodes and hints may use {field_name} placeholders."
          },
          "x": {
            "type": "integer"
          },
          "y": {
            "type": "integer"
          },
          "kind": {
            "const": "answer"
          }
        }
      },
      "ExtractField": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,23}$"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "number",
              "date",
              "list"
            ],
            "default": "text"
          },
          "instructions": {
            "type": "string",
            "maxLength": 200,
            "description": "What to find, in plain English; defaults to the name."
          },
          "optional": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "ExtractNode": {
        "type": "object",
        "required": [
          "kind",
          "fields",
          "out"
        ],
        "description": "Clairic reads fields from text/HTML; found/missing branches. At most four extract steps/tree. No key required. Low-confidence, null, guessed-only fields are missing. Values exist only for this run.",
        "properties": {
          "text": {
            "type": "string",
            "description": "Plain text; later ask/answer nodes and hints may use {field_name} placeholders."
          },
          "x": {
            "type": "integer"
          },
          "y": {
            "type": "integer"
          },
          "kind": {
            "const": "extract"
          },
          "fields": {
            "type": "array",
            "minItems": 1,
            "maxItems": 12,
            "items": {
              "$ref": "#/components/schemas/ExtractField"
            }
          },
          "out": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "description": "Exactly found and missing labels.",
            "items": {
              "$ref": "#/components/schemas/Way"
            }
          }
        }
      }
    },
    "parameters": {
      "Slug": {
        "name": "slug",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^[a-z0-9]{3,24}$"
        },
        "description": "Tree id. /hotdog is an alias of 5gs8g."
      },
      "ShareId": {
        "name": "sid",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^[a-z0-9]{8}$"
        }
      }
    }
  },
  "paths": {
    "/": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Home. HTML canvas in a browser; a curl briefing in a terminal.",
        "responses": {
          "200": {
            "description": "HTML page or plain-text briefing.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              },
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "meta"
        ],
        "summary": "POST the homepage: 400 plus a hint to POST to a tree.",
        "responses": {
          "400": {
            "description": "The briefing, plus a hint."
          }
        }
      }
    },
    "/{slug}": {
      "get": {
        "tags": [
          "decide"
        ],
        "summary": "Describe a tree (outline, JSON doc, or HTML canvas).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Slug"
          }
        ],
        "responses": {
          "200": {
            "description": "Plain-text outline, JSON tree, or HTML canvas depending on Accept / User-Agent.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Tree"
                }
              },
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "No such tree."
          }
        }
      },
      "post": {
        "tags": [
          "decide"
        ],
        "summary": "Run the tree on text or an image. Curl always uses Jev.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Slug"
          },
          {
            "name": "follow",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ]
            },
            "description": "1 (default): an answer naming a tree (→ 8fzct) runs that tree next, up to 3; 0: stop at this tree. Also header X-Che-Follow."
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Raw text, JSON {text|input|q}, a form field of those names, multipart image=@ plus optional text=, or a raw image with Content-Type image/jpeg|png|webp|gif. Text up to 4000 characters; images up to 2 MB. Or a web page as text/html (up to 2.4 MB), converted to markdown first.",
          "content": {
            "text/plain": {
              "schema": {
                "type": "string",
                "examples": [
                  "you charged me twice, fix it"
                ]
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string"
                  },
                  "input": {
                    "type": "string"
                  },
                  "q": {
                    "type": "string"
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "image": {
                    "type": "string",
                    "format": "binary"
                  },
                  "text": {
                    "type": "string",
                    "description": "Optional caption."
                  }
                }
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/webp": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/gif": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "text/html": {
              "schema": {
                "type": "string",
                "maxLength": 2400000,
                "description": "A saved web page; converted to markdown (see /api/page), then the tree reads up to 16,000 characters."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Decision. Plain text or JSON.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Decision"
                }
              }
            }
          },
          "400": {
            "description": "Empty input."
          },
          "404": {
            "description": "No such tree."
          },
          "413": {
            "description": "Text or image too large."
          },
          "415": {
            "description": "Unsupported image type."
          },
          "429": {
            "description": "Slow down, or a daily cap."
          },
          "502": {
            "description": "Decision service did not answer."
          },
          "503": {
            "description": "Napping, images off, or busy."
          }
        }
      }
    },
    "/api/status": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Awake flag, size limits, demo slugs.",
        "responses": {
          "200": {
            "description": "Current limits. Cache-Control: no-store.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          }
        }
      }
    },
    "/api/trees": {
      "post": {
        "tags": [
          "trees"
        ],
        "summary": "Claim a URL. Returns slug, edit_key, and url.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "doc"
                ],
                "properties": {
                  "doc": {
                    "$ref": "#/components/schemas/TreeDoc"
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 80
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created. Store edit_key; it is shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "slug": {
                      "type": "string"
                    },
                    "edit_key": {
                      "type": "string"
                    },
                    "revision": {
                      "type": "integer"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Body was not {doc, title}."
          },
          "422": {
            "description": "invalid_tree"
          },
          "429": {
            "description": "Slow down."
          },
          "503": {
            "description": "Too many new trees today (busy)."
          }
        }
      }
    },
    "/api/trees/{slug}": {
      "get": {
        "tags": [
          "trees"
        ],
        "summary": "Fetch a tree's doc.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Slug"
          }
        ],
        "responses": {
          "200": {
            "description": "The tree.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Tree"
                }
              }
            }
          },
          "404": {
            "description": "No such tree."
          },
          "429": {
            "description": "Slow down."
          }
        }
      },
      "put": {
        "tags": [
          "trees"
        ],
        "summary": "Update a tree you claimed.",
        "security": [
          {
            "EditKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Slug"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "doc"
                ],
                "properties": {
                  "doc": {
                    "$ref": "#/components/schemas/TreeDoc"
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 80
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "slug": {
                      "type": "string"
                    },
                    "revision": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Wrong or missing edit key."
          },
          "422": {
            "description": "invalid_tree"
          },
          "429": {
            "description": "Slow down."
          }
        }
      }
    },
    "/api/usage/{slug}": {
      "get": {
        "tags": [
          "trees"
        ],
        "summary": "Call counts for a tree you own. Counts and cost only; never inputs.",
        "security": [
          {
            "EditKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Slug"
          }
        ],
        "responses": {
          "200": {
            "description": "ok, slug, calls, cost_usd, last_used_at, and a days[] array."
          },
          "403": {
            "description": "Wrong or missing edit key."
          },
          "404": {
            "description": "No such tree."
          },
          "429": {
            "description": "Slow down."
          }
        }
      }
    },
    "/api/try": {
      "post": {
        "tags": [
          "decide"
        ],
        "summary": "Preview an unsaved doc (used by the canvas).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "doc": {
                    "$ref": "#/components/schemas/TreeDoc"
                  },
                  "input": {
                    "type": "string"
                  },
                  "image": {
                    "type": "string",
                    "description": "data:image/(jpeg|jpg|png|webp|gif);base64,..."
                  },
                  "slug": {
                    "type": "string",
                    "description": "If this is a current demo slug and the doc matches, the demo cache may answer."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A decision, always JSON.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Decision"
                }
              }
            }
          },
          "400": {
            "description": "Bad request."
          },
          "413": {
            "description": "Image too large."
          },
          "415": {
            "description": "Bad image."
          },
          "422": {
            "description": "invalid_tree"
          },
          "429": {
            "description": "Slow down."
          },
          "503": {
            "description": "Napping or images off."
          }
        }
      }
    },
    "/c/{sid}": {
      "get": {
        "tags": [
          "shares"
        ],
        "summary": "A shared compare. Never calls a model.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ShareId"
          }
        ],
        "responses": {
          "200": {
            "description": "Plain-text summary, JSON payload, or HTML canvas.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              },
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "No such share."
          }
        }
      }
    },
    "/api/share/{sid}": {
      "get": {
        "tags": [
          "shares"
        ],
        "summary": "JSON for a shared compare. Never calls a model.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ShareId"
          }
        ],
        "responses": {
          "200": {
            "description": "The share payload (doc, runs, majority, optional input if the sharer opted in). Photos are never included."
          },
          "404": {
            "description": "No such share."
          },
          "429": {
            "description": "Slow down."
          }
        }
      }
    },
    "/og/{slug}.png": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Open Graph preview image for a tree (1200×630 PNG).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Slug"
          }
        ],
        "responses": {
          "200": {
            "description": "PNG."
          },
          "404": {
            "description": "Falls back to the default preview image, or 404."
          }
        }
      }
    },
    "/og/c/{sid}.png": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Open Graph preview image for a shared compare (1200×630 PNG).",
        "parameters": [
          {
            "$ref": "#/components/parameters/ShareId"
          }
        ],
        "responses": {
          "200": {
            "description": "PNG."
          }
        }
      }
    },
    "/llms.txt": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Short LLM-oriented briefing (llmstxt.org format).",
        "responses": {
          "200": {
            "description": "Markdown.",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/llms-full.txt": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Full public API reference, with real curl examples.",
        "responses": {
          "200": {
            "description": "Markdown.",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/docs": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Same body as /llms-full.txt.",
        "responses": {
          "200": {
            "description": "Markdown.",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "This OpenAPI document.",
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 JSON.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/healthz": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Liveness. Returns the text 'ok'.",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "examples": [
                    "ok\n"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/robots.txt": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Robots file.",
        "responses": {
          "200": {
            "description": "text/plain"
          }
        }
      }
    },
    "/sitemap.xml": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Sitemap of the homepage and docs.",
        "responses": {
          "200": {
            "description": "application/xml"
          }
        }
      }
    },
    "/api/ocr": {
      "post": {
        "summary": "Read one page image with OCR (memory only; the image is discarded after reading)",
        "requestBody": {
          "required": true,
          "content": {
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 2621440
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 2621440
              }
            },
            "image/webp": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 2621440
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "text read",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "text": {
                      "type": "string"
                    },
                    "conf": {
                      "type": "number"
                    },
                    "lines": {
                      "type": "integer"
                    },
                    "low": {
                      "type": "integer"
                    },
                    "ms": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "ocr_too_big"
          },
          "415": {
            "description": "bad_image"
          },
          "429": {
            "description": "rate_ocr or ocr_cap"
          },
          "503": {
            "description": "ocr_busy, ocr_timeout or ocr_off"
          }
        }
      }
    },
    "/api/known/{slug}": {
      "post": {
        "summary": "Owner: mark (or unmark) the right answer for one exact input on the saved tree. Stores a fingerprint, never the input.",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-edit-key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "leaf"
                ],
                "properties": {
                  "input": {
                    "type": "string"
                  },
                  "image": {
                    "type": "string",
                    "description": "data URL"
                  },
                  "leaf": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "answer node id; null unmarks"
                  },
                  "doc": {
                    "$ref": "#/components/schemas/TreeDoc"
                  },
                  "sample": {
                    "type": "string",
                    "maxLength": 40
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "marked or unmarked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "marked": {
                      "type": "boolean"
                    },
                    "leaf": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "expected": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "not_an_answer or bad_request"
          },
          "403": {
            "description": "wrong_key"
          },
          "409": {
            "description": "save_first or known_full"
          },
          "429": {
            "description": "rate"
          }
        }
      }
    },
    "/api/scoreboard": {
      "get": {
        "summary": "Latest eval sweep of the decision models on the demo samples' known answers",
        "responses": {
          "200": {
            "description": "scoreboard",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "sweep": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "ran_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "runs": {
                      "type": "integer"
                    },
                    "spent_usd": {
                      "type": "number"
                    },
                    "models": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "samples": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/models": {
      "get": {
        "summary": "Decision model scores on known answers (HTML in browsers, plain text for curl, JSON with Accept: application/json)",
        "responses": {
          "200": {
            "description": "scoreboard"
          }
        }
      }
    },
    "/api/page": {
      "post": {
        "summary": "Convert page HTML to the markdown a tree reads (deterministic, memory only, never fetches)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "html"
                ],
                "properties": {
                  "html": {
                    "type": "string",
                    "maxLength": 2400000
                  },
                  "url": {
                    "type": "string",
                    "maxLength": 300
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 300
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "markdown",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "markdown": {
                      "type": "string"
                    },
                    "page": {
                      "type": "object",
                      "properties": {
                        "title": {
                          "type": "string"
                        },
                        "chars": {
                          "type": "integer"
                        },
                        "sections": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "integer"
                          }
                        },
                        "blocks": {
                          "type": "integer"
                        },
                        "blocks_total": {
                          "type": "integer"
                        },
                        "cut": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "empty or bad_request"
          },
          "413": {
            "description": "too big"
          },
          "429": {
            "description": "rate"
          }
        }
      }
    },
    "/api/run/{slug}": {
      "post": {
        "tags": [
          "decide"
        ],
        "summary": "JSON run of a saved tree (used by the extension)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Slug"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "input": {
                    "type": "string"
                  },
                  "files": {
                    "type": "boolean",
                    "description": "Documents or a converted page: input up to 16,000 characters under the per-IP file bucket."
                  },
                  "image": {
                    "type": "string",
                    "description": "data:image/(jpeg|png|webp|gif);base64,... up to 2 MB decoded"
                  },
                  "follow": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Decision",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Decision"
                }
              }
            }
          },
          "400": {
            "description": "Empty input."
          },
          "404": {
            "description": "No such tree."
          },
          "413": {
            "description": "Too large."
          },
          "429": {
            "description": "Slow down, or a daily cap."
          },
          "503": {
            "description": "Napping or busy."
          }
        }
      }
    },
    "/api/suggest": {
      "post": {
        "summary": "Score up to 10 saved trees against an input (one Jev call; runs nothing, stores nothing)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "input",
                  "trees"
                ],
                "properties": {
                  "input": {
                    "type": "string",
                    "description": "first 3,000 characters are read"
                  },
                  "trees": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1,
                    "maxItems": 10
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "scores",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "trees": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "p": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "cost_usd": {
                      "type": "number"
                    },
                    "model": {
                      "type": "string"
                    },
                    "ms": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "empty or bad_request"
          },
          "429": {
            "description": "rate"
          },
          "502": {
            "description": "model_failed"
          },
          "503": {
            "description": "napping, suggest_off or suggest_daily_cap"
          }
        }
      }
    },
    "/api/cards": {
      "get": {
        "summary": "Public cards for up to 20 trees",
        "parameters": [
          {
            "name": "ids",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "comma-separated tree ids"
          }
        ],
        "responses": {
          "200": {
            "description": "cards",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "cards": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/suggest/feedback": {
      "post": {
        "summary": "Record which suggested tree was clicked (numbers only)",
        "description": "Sent by the che.sh extension after it showed suggested trees: the kind of content, the suggested tree ids with their scores in rank order, and the id the visitor clicked (or null). No content, URL, domain or visitor id. Kept 90 days, used for the detection hit rate. 60/min per IP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "kind",
                  "trees"
                ],
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "page",
                      "text",
                      "image"
                    ]
                  },
                  "trees": {
                    "type": "array",
                    "maxItems": 10,
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "p": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 1
                        }
                      }
                    }
                  },
                  "picked": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "hinted": {
                    "type": "boolean",
                    "description": "the site's last-used check (a local hint) was among the candidates"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "{ok: true}"
          },
          "400": {
            "description": "bad_request or full"
          },
          "429": {
            "description": "rate"
          }
        }
      }
    }
  }
}
