{
  "openapi": "3.1.0",
  "info": {
    "title": "FASST API",
    "version": "1.6.2",
    "description": "MS/MS spectral search (FASST) across GNPS spectral libraries and repository-scale indices.\n\nTwo API families:\n\n* **Compat** (`/search`, `/search/status/{id}`, `/search/result/{id}`, `/libraries`, ...):\n  byte-compatible with the production service (api.fasst.gnps2.org, used by MCP_FASST and GNPS2).\n* **v2** (`/api/v2/...`): sync-first search with an async handoff (`202` + job), batch search with\n  streamed JSONL or Parquet results, metadata filters, job status, stats.\n\nResults are kept **in memory only** (search results for 600 s, batches for 3600 s, under a total\nbyte cap; evicted results report `EXPIRED` / `410`).\n\nThe web UI (`/fastsearch/`) uses its own reserved lane, `POST /ui/api/search`, which is **not part\nof the public API** (it needs a session cookie, same-origin requests and the `X-FASST-UI: 1`\nheader, and is limited to a few searches per minute); scripts should use `/api/v2/search` or\n`/api/v2/batch`. `/admin/*` is internal (bearer token, direct peers only; `403` from outside) and\nnot listed here.\n\nHuman-written reference with more detail: `docs/api.md` in the repository.\n\nThe examples mirror the web UI's presets: caffeine (`CCMSLIB00013936481`, the most basic check), the GNPS library index `gnpslibrary` with the library\nspectrum `mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547` (exact, analog, or its 30 most intense peaks pasted),\nand a repository search of `mzspec:MSV000086206:peak/S_N1.mzML:scan:164` against `metabolomicspanrepo_index`.\n\n### For AI agents and scripts\n\nStart with **`GET /api/v2/limits`**: `you.label` says whether you are `public` or a `collaborator`, and\n`classes` lists every cap. Then follow the section for your class below.\n\nFor everyone:\n\n* **One spectrum:** `POST /api/v2/search` with a `usi` or a `spectrum` (`precursor_mz`,\n  `precursor_charge`, `peaks`), and `\"format\": \"jsonl\"`. Read rows until the `{\"end\": ...}` line:\n  `end.total_results` is the exact number of hits, `end.complete: false` means rows were cut\n  (`end.truncated_reason`). A `202` means the search became a job: poll `GET /api/v2/jobs/{id}` (at\n  most once a second), then read `GET /api/v2/jobs/{id}/result?format=jsonl`.\n* **`total_results` is always the exact number of hits.** `top_k` and the caps below only limit the\n  rows returned. The plain JSON response lists at most 100,000 hits; use JSONL for more.\n* **MassQL:** `POST /api/v2/massql/stream` streams every match as JSONL (with an `end` line);\n  `POST /api/v2/massql` is a job that stops at 100,000 matches.\n* **Be polite:** a descriptive `User-Agent`; on `429` or `503` wait `Retry-After` seconds and retry;\n  stay within your in-flight caps instead of opening more connections; a `422` with\n  `code: \"param_limit\"` means a parameter is above your class's cap (lower it, do not retry).\n* Do not call `/ui/api/*` (the web page's own lane) or `/admin/*`.\n\n#### If you are public (`you.label: \"public\"`)\n\n* **Searches:** 2 requests/s (burst 20); at most 8 exact and 2 analog searches in flight; analog\n  window at most 200 Da on each side; `pm_tolerance` at most 0.5 Da.\n* **Every hit of a search:** up to 1,000,000 per search with `\"format\": \"jsonl\"`.\n* **Many spectra:** `POST /api/v2/batch` with at most 1,000 spectra, best 1,000 hits per spectrum\n  (`total_hits` per spectrum is exact); one bulk job (batch, MassQL job or MassQL stream) in\n  flight at a time; 10 submissions per minute (burst 5). Send batches one after another. For every\n  hit of a spectrum with more than 1,000, run it as a single JSONL search.\n* **MassQL:** one stream at a time (at most 1 hour); a job returns at most 100,000 matches.\n* **No bulk exports** (`POST /api/v2/export` answers `403`). If you need more than these limits,\n  ask the FASST operators to add your machine as a collaborator, quoting `you.address` from\n  `GET /api/v2/limits`.\n\n#### If you are a collaborator (`you.label: \"collaborator\"`)\n\n* **Searches:** 20 requests/s (burst 200); no in-flight, analog-window or tolerance caps.\n* **Many spectra:** `POST /api/v2/batch` with up to 10,000 spectra (best 1,000 hits per spectrum);\n  600 submissions per minute (burst 200). Batches of 1,000 spectra with 2 to 4 in flight per\n  client give the best throughput.\n* **Every row, any size: bulk exports.** `POST /api/v2/export` with `kind` `search`, `batch`,\n  `massql` or `massql_batch` (up to 1,000 MassQL queries in one pass) writes every row, up to\n  100,000,000, as parts of 1,000,000 rows (`.jsonl.zst`, or Parquet with `\"format\": \"parquet\"`).\n  Poll `GET /api/v2/jobs/{id}`; `GET /api/v2/jobs/{id}/files` lists the parts (already while it\n  runs) with `rows`, `bytes`, `sha256` and a `url`; download each (`Range` supported), check its\n  sha256, then `DELETE /api/v2/jobs/{id}`. Parts are kept for 1 hour; 2 exports run at once and\n  more wait as `PENDING`.\n* **MassQL:** streams and jobs without the public in-flight cap; `massql_batch` exports for many\n  queries.\n* The Python client (`fasst_client` in the FASST repository: `get_all`, `export`, `batch`,\n  `massql_batch`) does all of the above, including retries, part checks and parallel downloads.\n\n### Access and limits\n\nEverything is open to everyone (**public**, class `anonymous`). **Collaborators** (class `whitelisted`) get higher limits and bulk exports (`POST /api/v2/export`). `GET /api/v2/limits` says which class you are in and lists every limit; docs/api.md \"Limits\" has the tables.\n\n| routes | public, per client IP | collaborator |\n|---|---|---|\n| `GET`/`POST /search`, `POST /api/v2/search` | 2 requests/s, burst 20 | 20 requests/s, burst 200 |\n| `POST /api/v2/batch`, `POST /api/v2/massql`, `/api/v2/massql/stream`, `POST /api/v2/export` | 10 requests/min, burst 5 | 600 requests/min, burst 200 |\n| `/search/status/*`, `/search/result/*`, `/api/v2/jobs/*`, `/api/v2/batch/*`, `/api/v2/massql/*` and every other route | 20 requests/s, burst 100 | 100 requests/s, burst 500 |\n| concurrent connections to the API routes | 8 | 32 |\n\nOver a rate, the answer is **`429 Too Many Requests`** with a `Retry-After` header (seconds) and\n`{\"detail\": ..., \"error\": \"rate limit exceeded\", \"code\": \"rate_limited\", \"retry_after\": N}`.\nHonor `Retry-After`, and poll job status about once a second at most.\n",
    "license": {"name": "See the repository", "url": "https://github.com/Wang-Bioinformatics-Lab/FASST_Indexing_Code"}
  },
  "servers": [
    {"url": "/", "description": "This server (same origin)"}
  ],
  "tags": [
    {"name": "v2", "description": "Sync-first search, jobs, libraries, spectra, stats."},
    {"name": "batch", "description": "Async batch search with streamed JSONL or Parquet results."},
    {"name": "massql", "description": "MassQL queries (MS2 conditions) on engine-ls libraries: async, one row per matching scan, streamed JSONL / Parquet / dataset counts."},
    {
      "name": "compat",
      "description": "Production-compatible API (api.fasst.gnps2.org): async submit → status → result, legacy blocking search."
    },
    {"name": "export", "description": "Bulk exports for whitelisted clients: a search, MassQL query or batch written to disk as .jsonl.zst or Parquet parts (up to 100M rows), downloaded through the job URL, kept 1 hour."},
    {"name": "service", "description": "Health, self test, queue, API index."}
  ],
  "paths": {
    "/": {
      "get": {
        "tags": ["service"],
        "operationId": "apiIndex",
        "summary": "API index",
        "description": "Browsers (`Accept: text/html`) are redirected (`302`) to the web UI `/fastsearch/`; other clients get this endpoint list.",
        "responses": {
          "200": {
            "description": "Endpoint list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": {"type": "string"},
                    "version": {"type": "string"},
                    "endpoints": {
                      "type": "array",
                      "items": {"type": "string"}
                    },
                    "ui": {"type": "string"},
                    "docs": {"type": "string"},
                    "openapi": {"type": "string"},
                    "build": {"$ref": "#/components/schemas/BuildInfo"}
                  }
                },
                "example": {
                  "name": "FASST API",
                  "version": "1.6.2",
                  "endpoints": ["/search", "/api/v2/search"],
                  "ui": "/fastsearch/",
                  "docs": "/docs",
                  "openapi": "/openapi.json",
                  "build": {
                    "version": "1.6.2",
                    "git_sha": "abc1234",
                    "build_time": "2026-09-28T18:40:12Z",
                    "display": "fasst 1.6.2 · abc1234 · built 2026-09-28 18:40 UTC"
                  }
                }
              }
            }
          },
          "302": {"description": "Redirect to `/fastsearch/` (browsers)."},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": ["service"],
        "operationId": "openapi",
        "summary": "This OpenAPI document",
        "description": "The machine-readable API reference (OpenAPI 3.1). The interactive page is `/docs`.",
        "responses": {
          "200": {
            "description": "OpenAPI document.",
            "content": {
              "application/json": {
                "schema": {"type": "object"}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/version": {
      "get": {
        "tags": ["service"],
        "operationId": "version",
        "summary": "Build version",
        "description": "The running binary's version, git commit and build time (also in `/api/v2/stats` and `/`, and in the web UI footer).",
        "responses": {
          "200": {
            "description": "Build identity.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/BuildInfo"},
                "example": {
                  "version": "1.6.2",
                  "git_sha": "abc1234",
                  "build_time": "2026-09-28T18:40:12Z",
                  "display": "fasst 1.6.2 · abc1234 · built 2026-09-28 18:40 UTC"
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/search": {
      "post": {
        "tags": ["compat"],
        "operationId": "compatSubmit",
        "summary": "Submit a search (async, production API)",
        "description": "With a JSON body: submits the search and answers immediately with a job id; poll `GET /search/status/{id}`, then fetch `GET /search/result/{id}`. Search failures (unknown library, bad spectrum, USI resolution, timeout) surface as `FAILURE` status, not as HTTP errors.\n\nWith an `application/x-www-form-urlencoded` body: the **legacy blocking** shim (same as `GET /search`): waits up to 90 s and answers the result JSON.\n\nRate limit: the search bucket (2/s, burst 20 per IP).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/FastQuery"},
              "examples": {
                "exact": {
                  "summary": "Exact search by USI",
                  "value": {
                    "library": "gnpslibrary",
                    "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                    "analog": "No"
                  }
                },
                "analog": {
                  "summary": "Analog search by USI",
                  "value": {
                    "library": "gnpslibrary",
                    "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                    "analog": "Yes",
                    "lower_delta": 130,
                    "upper_delta": 200
                  }
                },
                "peaks": {
                  "summary": "Peaks as a JSON string",
                  "value": {
                    "library": "gnpslibrary",
                    "query_spectrum": "{\"peaks\": [[456.1075, 105392], [469.8723, 87594], [515.9229, 78764], [538.0032, 220949], [539.2178, 272296], [554.1174, 76225], [556.0304, 214421], [582.1101, 102075], [599.3528, 764523], [600.3828, 114267], [696.3324, 121211], [724.0819, 88510], [830.4093, 102583], [839.4558, 72006], [847.4336, 196462], [851.3809, 246170], [852.3706, 276882], [866.2957, 111012], [868.3722, 78023], [909.4244, 244136], [919.3962, 85829], [932.3519, 136657], [936.552, 103130], [939.6179, 77289], [949.3702, 85420], [953.3966, 545281], [954.4916, 123937], [963.6868, 261578], [964.5247, 318164], [965.1921, 124405]], \"precursor_mz\": 981.54, \"precursor_charge\": 1}",
                    "analog": "No"
                  }
                }
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {"$ref": "#/components/schemas/FastQuery"},
              "example": {
                "library": "gnpslibrary",
                "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                "analog": "No"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON body: the job was accepted. Form body (legacy): the result JSON.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {"$ref": "#/components/schemas/CompatSubmitted"},
                    {"$ref": "#/components/schemas/SearchResult"}
                  ]
                },
                "examples": {
                  "submitted": {
                    "value": {
                      "id": "2dac008f-be4e-477c-998c-7d3634d61809",
                      "result_task": "0f61ce89644e4194ab790f05cd17e8c1",
                      "status": "PENDING"
                    }
                  },
                  "legacy_result": {
                    "value": {
                      "results": [
                        {
                          "Delta Mass": 0.0,
                          "GNPSLibraryAccession": "CCMSLIB00000001547",
                          "USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Charge": 1,
                          "Cosine": 1.0,
                          "Matching Peaks": 42,
                          "Unit Delta Mass": 0,
                          "Dataset": "GNPS Library",
                          "Status": "HasID",
                          "Adduct": "M+H",
                          "CompoundName": "3-Des-Microcystein_LR",
                          "Query Scan": 1,
                          "Index UnitPM": 981,
                          "Index IdxInUnitPM": 2609
                        }
                      ],
                      "timing": [
                        {"desc": "Search", "timing": 0.0051},
                        {"desc": "Postprocess", "timing": 2e-05}
                      ],
                      "grouped_by_unit_delta_mass": [
                        {"Frequency": 1, "Unit Delta Mass": 0}
                      ],
                      "grouped_by_dataset": [
                        {"Frequency": 1, "Dataset": "GNPS Library"}
                      ],
                      "grouped_by_dataset_unit_delta": [
                        {"Frequency": 1, "Dataset": "GNPS Library", "Unit Delta Mass": 0}
                      ],
                      "metadata_groupings": [
                        [
                          "GNPSLibraryAccession",
                          [
                            {
                              "Frequency": 1,
                              "GNPSLibraryAccession": "CCMSLIB00000001547",
                              "Best Cosine": 1.0,
                              "Best Delta Mass": 0.0,
                              "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                              "Best Charge": 1
                            }
                          ]
                        ],
                        [
                          "Adduct",
                          [
                            {
                              "Frequency": 1,
                              "Adduct": "M+H",
                              "Best Cosine": 1.0,
                              "Best Delta Mass": 0.0,
                              "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                              "Best Charge": 1
                            }
                          ]
                        ],
                        [
                          "CompoundName",
                          [
                            {
                              "Frequency": 1,
                              "CompoundName": "3-Des-Microcystein_LR",
                              "Best Cosine": 1.0,
                              "Best Delta Mass": 0.0,
                              "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                              "Best Charge": 1
                            }
                          ]
                        ]
                      ],
                      "log": "fasst 1.6.2 engine=ls library=gnpslibrary hits=1",
                      "temp_json_path": ""
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Invalid body or missing `library`.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Detail"},
                "example": {"detail": "field 'library' is required"}
              }
            }
          },
          "502": {
            "description": "Legacy form request: the search failed.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/CompatStatus"},
                "example": {"status": "FAILURE", "error": "library 'nope' not found"}
              }
            }
          },
          "503": {"$ref": "#/components/responses/QueueFull"},
          "504": {
            "description": "Legacy form request: not finished within 90 s.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {"const": "TIMEOUT"},
                    "task_id": {"type": "string"}
                  }
                },
                "example": {"status": "TIMEOUT", "task_id": "2dac008f-be4e-477c-998c-7d3634d61809"}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      },
      "get": {
        "tags": ["compat"],
        "operationId": "compatSearchBlocking",
        "summary": "Legacy blocking search",
        "description": "Old fasst.gnps2.org clients: parameters in the query string; waits up to 90 s for the result. Prefer `POST /api/v2/search`.\n\nRate limit: the search bucket (2/s, burst 20 per IP).",
        "parameters": [
          {
            "name": "library",
            "in": "query",
            "required": true,
            "description": "Library name.",
            "schema": {"type": "string"},
            "example": "gnpslibrary"
          },
          {
            "name": "usi",
            "in": "query",
            "required": false,
            "description": "Query USI.",
            "schema": {"type": "string"},
            "example": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547"
          },
          {
            "name": "query_spectrum",
            "in": "query",
            "required": false,
            "description": "Query spectrum as a JSON string (wins over `usi`).",
            "schema": {"type": "string"}
          },
          {
            "name": "analog",
            "in": "query",
            "required": false,
            "description": "Analog search.",
            "schema": {"type": "string", "enum": ["Yes", "No"], "default": "No"}
          },
          {
            "name": "lower_delta",
            "in": "query",
            "required": false,
            "description": "Analog window below (Da).",
            "schema": {"type": "number", "default": 130}
          },
          {
            "name": "upper_delta",
            "in": "query",
            "required": false,
            "description": "Analog window above (Da).",
            "schema": {"type": "number", "default": 200}
          },
          {
            "name": "pm_tolerance",
            "in": "query",
            "required": false,
            "description": "Precursor tolerance (Da).",
            "schema": {"type": "number", "default": 0.05}
          },
          {
            "name": "fragment_tolerance",
            "in": "query",
            "required": false,
            "description": "Fragment tolerance (Da).",
            "schema": {"type": "number", "default": 0.05}
          },
          {
            "name": "cosine_threshold",
            "in": "query",
            "required": false,
            "description": "Minimum cosine.",
            "schema": {"type": "number", "default": 0.7}
          }
        ],
        "responses": {
          "200": {
            "description": "The result JSON.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/SearchResult"},
                "example": {
                  "results": [
                    {
                      "Delta Mass": 0.0,
                      "GNPSLibraryAccession": "CCMSLIB00000001547",
                      "USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                      "Charge": 1,
                      "Cosine": 1.0,
                      "Matching Peaks": 42,
                      "Unit Delta Mass": 0,
                      "Dataset": "GNPS Library",
                      "Status": "HasID",
                      "Adduct": "M+H",
                      "CompoundName": "3-Des-Microcystein_LR",
                      "Query Scan": 1,
                      "Index UnitPM": 981,
                      "Index IdxInUnitPM": 2609
                    }
                  ],
                  "timing": [
                    {"desc": "Search", "timing": 0.0051},
                    {"desc": "Postprocess", "timing": 2e-05}
                  ],
                  "grouped_by_unit_delta_mass": [
                    {"Frequency": 1, "Unit Delta Mass": 0}
                  ],
                  "grouped_by_dataset": [
                    {"Frequency": 1, "Dataset": "GNPS Library"}
                  ],
                  "grouped_by_dataset_unit_delta": [
                    {"Frequency": 1, "Dataset": "GNPS Library", "Unit Delta Mass": 0}
                  ],
                  "metadata_groupings": [
                    [
                      "GNPSLibraryAccession",
                      [
                        {
                          "Frequency": 1,
                          "GNPSLibraryAccession": "CCMSLIB00000001547",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ],
                    [
                      "Adduct",
                      [
                        {
                          "Frequency": 1,
                          "Adduct": "M+H",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ],
                    [
                      "CompoundName",
                      [
                        {
                          "Frequency": 1,
                          "CompoundName": "3-Des-Microcystein_LR",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ]
                  ],
                  "log": "fasst 1.6.2 engine=ls library=gnpslibrary hits=1",
                  "temp_json_path": ""
                }
              }
            }
          },
          "422": {
            "description": "Missing `library` or a non-numeric parameter.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Detail"},
                "example": {"detail": "parameter 'library' is required"}
              }
            }
          },
          "502": {
            "description": "The search failed.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/CompatStatus"},
                "example": {"status": "FAILURE", "error": "library 'nope' not found"}
              }
            }
          },
          "503": {"$ref": "#/components/responses/QueueFull"},
          "504": {
            "description": "Not finished within 90 s.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {"const": "TIMEOUT"},
                    "task_id": {"type": "string"}
                  }
                },
                "example": {"status": "TIMEOUT", "task_id": "2dac008f-be4e-477c-998c-7d3634d61809"}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/search/status/{id}": {
      "get": {
        "tags": ["compat"],
        "operationId": "compatStatus",
        "summary": "Search status (production API)",
        "description": "Always `200`. `NOT_FOUND` for an invalid or unknown id, a result past its TTL or evicted by the byte cap, or a v2 batch id.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {"type": "string"},
            "description": "Task id from `POST /search`.",
            "example": "2dac008f-be4e-477c-998c-7d3634d61809"
          }
        ],
        "responses": {
          "200": {
            "description": "Status.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/CompatStatus"},
                "examples": {
                  "pending": {
                    "value": {"status": "PENDING", "message": "Task was accepted and is still pending"}
                  },
                  "running": {
                    "value": {"status": "RUNNING", "message": "Task is running"}
                  },
                  "completed": {
                    "value": {"status": "COMPLETED", "message": "Task completed successfully"}
                  },
                  "failure": {
                    "value": {"status": "FAILURE", "error": "library 'nope' not found"}
                  },
                  "not_found": {
                    "value": {"status": "NOT_FOUND", "error": "Task ID was not submitted by this API"}
                  }
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/search/result/{id}": {
      "get": {
        "tags": ["compat"],
        "operationId": "compatResult",
        "summary": "Search result (production API)",
        "description": "`200` with the result JSON when completed, else the status body (also `200`).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {"type": "string"},
            "description": "Task id from `POST /search`.",
            "example": "2dac008f-be4e-477c-998c-7d3634d61809"
          }
        ],
        "responses": {
          "200": {
            "description": "Result JSON, or the status body while not completed.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {"$ref": "#/components/schemas/SearchResult"},
                    {"$ref": "#/components/schemas/CompatStatus"}
                  ]
                },
                "examples": {
                  "completed": {
                    "value": {
                      "results": [
                        {
                          "Delta Mass": 0.0,
                          "GNPSLibraryAccession": "CCMSLIB00000001547",
                          "USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Charge": 1,
                          "Cosine": 1.0,
                          "Matching Peaks": 42,
                          "Unit Delta Mass": 0,
                          "Dataset": "GNPS Library",
                          "Status": "HasID",
                          "Adduct": "M+H",
                          "CompoundName": "3-Des-Microcystein_LR",
                          "Query Scan": 1,
                          "Index UnitPM": 981,
                          "Index IdxInUnitPM": 2609
                        }
                      ],
                      "timing": [
                        {"desc": "Search", "timing": 0.0051},
                        {"desc": "Postprocess", "timing": 2e-05}
                      ],
                      "grouped_by_unit_delta_mass": [
                        {"Frequency": 1, "Unit Delta Mass": 0}
                      ],
                      "grouped_by_dataset": [
                        {"Frequency": 1, "Dataset": "GNPS Library"}
                      ],
                      "grouped_by_dataset_unit_delta": [
                        {"Frequency": 1, "Dataset": "GNPS Library", "Unit Delta Mass": 0}
                      ],
                      "metadata_groupings": [
                        [
                          "GNPSLibraryAccession",
                          [
                            {
                              "Frequency": 1,
                              "GNPSLibraryAccession": "CCMSLIB00000001547",
                              "Best Cosine": 1.0,
                              "Best Delta Mass": 0.0,
                              "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                              "Best Charge": 1
                            }
                          ]
                        ],
                        [
                          "Adduct",
                          [
                            {
                              "Frequency": 1,
                              "Adduct": "M+H",
                              "Best Cosine": 1.0,
                              "Best Delta Mass": 0.0,
                              "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                              "Best Charge": 1
                            }
                          ]
                        ],
                        [
                          "CompoundName",
                          [
                            {
                              "Frequency": 1,
                              "CompoundName": "3-Des-Microcystein_LR",
                              "Best Cosine": 1.0,
                              "Best Delta Mass": 0.0,
                              "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                              "Best Charge": 1
                            }
                          ]
                        ]
                      ],
                      "log": "fasst 1.6.2 engine=ls library=gnpslibrary hits=1",
                      "temp_json_path": ""
                    }
                  },
                  "running": {
                    "value": {"status": "RUNNING", "message": "Task is running"}
                  },
                  "not_found": {
                    "value": {"status": "NOT_FOUND", "error": "Task ID was not submitted by this API"}
                  }
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/libraries": {
      "get": {
        "tags": ["compat"],
        "operationId": "libraries",
        "summary": "Loaded libraries",
        "responses": {
          "200": {
            "description": "Library names.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {"$ref": "#/components/schemas/LibraryOption"}
                },
                "example": [
                  {"label": "gnpslibrary", "value": "gnpslibrary"},
                  {"label": "metabolomicspanrepo_index", "value": "metabolomicspanrepo_index"}
                ]
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/library/files": {
      "get": {
        "tags": ["compat"],
        "operationId": "libraryFiles",
        "summary": "Files of a library",
        "parameters": [
          {
            "name": "library",
            "in": "query",
            "required": true,
            "description": "Library name.",
            "schema": {"type": "string"},
            "example": "gnpslibrary"
          }
        ],
        "responses": {
          "200": {
            "description": "Files.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {"$ref": "#/components/schemas/LibraryFile"}
                },
                "example": [
                  {
                    "filepath": "MSV000086206/peak/S_N1.mzML",
                    "dataset": "MSV000086206",
                    "mri": "mzspec:MSV000086206:peak/S_N1.mzML"
                  }
                ]
              }
            }
          },
          "404": {
            "description": "Unknown or missing library (`text/plain` body `File not found`).",
            "content": {
              "text/plain": {
                "schema": {"type": "string"},
                "example": "File not found"
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/health": {
      "get": {
        "tags": ["service"],
        "operationId": "health",
        "summary": "Health",
        "responses": {
          "200": {
            "description": "Up.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Status"},
                "example": {"status": "healthy", "message": "FASST API is running"}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/heartbeat": {
      "get": {
        "tags": ["service"],
        "operationId": "heartbeat",
        "summary": "Heartbeat",
        "responses": {
          "200": {
            "description": "Up.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Status"},
                "example": {"status": "up"}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/selftest": {
      "get": {
        "tags": ["service"],
        "operationId": "selftest",
        "summary": "Self test",
        "description": "Searches CCMSLIB00000001547 in `gnpslibrary` (needs that library loaded).",
        "responses": {
          "200": {
            "description": "The test search found hits.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {"type": "string"},
                    "message": {"type": "string"},
                    "num_results": {"type": "integer"}
                  }
                },
                "example": {"status": "up", "message": "Test search succeeded", "num_results": 1}
              }
            }
          },
          "500": {
            "description": "The test search failed or `gnpslibrary` is not loaded.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Status"},
                "example": {"status": "error", "message": "library 'gnpslibrary' not loaded"}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/queuestatus": {
      "get": {
        "tags": ["service"],
        "operationId": "queueStatus",
        "summary": "Queue status (production shape)",
        "responses": {
          "200": {
            "description": "Counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "active_tasks": {"type": "integer"},
                    "reserved_tasks": {"type": "integer"},
                    "queued_tasks": {"type": "integer"}
                  }
                },
                "example": {"active_tasks": 0, "reserved_tasks": 0, "queued_tasks": 0}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/search": {
      "post": {
        "tags": ["v2"],
        "operationId": "v2Search",
        "summary": "Search (sync first, async handoff)",
        "description": "Runs the search and waits up to the **sync budget** (`--sync-budget`, default 10 s): `200` with the result if it finished, else `202` with a job (the same search keeps running; poll `status_url`, fetch `result_url`). `\"async\": true` answers `202` immediately. A synchronous answer is not stored. The JSON result lists at most `--max-hits-json` hits (default 100 000; `truncated_reason: max_hits_json`, exact `total_results`); `format: jsonl` lists every kept hit, up to the client's hit cap (1 000 000).\n\nRate limit: the search bucket (2/s, burst 20 per IP).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/V2SearchRequest"},
              "examples": {
                "caffeine": {
                  "summary": "Caffeine: the most basic check (GNPS library, exact, USI)",
                  "value": {
                    "library": "gnpslibrary",
                    "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00013936481",
                    "analog": false
                  }
                },
                "exact": {
                  "summary": "GNPS library: exact (USI)",
                  "value": {
                    "library": "gnpslibrary",
                    "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                    "analog": false
                  }
                },
                "analog": {
                  "summary": "GNPS library: analog (±100 Da, the v2 default)",
                  "value": {
                    "library": "gnpslibrary",
                    "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                    "analog": true,
                    "lower_delta": 100,
                    "upper_delta": 100
                  }
                },
                "peaks": {
                  "summary": "Pasted peaks (30 peaks of CCMSLIB00000001547)",
                  "value": {
                    "library": "gnpslibrary",
                    "spectrum": {
                      "precursor_mz": 981.54,
                      "precursor_charge": 1,
                      "peaks": [
                        [456.1075, 105392], [469.8723, 87594], [515.9229, 78764], [538.0032, 220949], [539.2178, 272296],
                        [554.1174, 76225], [556.0304, 214421], [582.1101, 102075], [599.3528, 764523], [600.3828, 114267],
                        [696.3324, 121211], [724.0819, 88510], [830.4093, 102583], [839.4558, 72006], [847.4336, 196462],
                        [851.3809, 246170], [852.3706, 276882], [866.2957, 111012], [868.3722, 78023], [909.4244, 244136],
                        [919.3962, 85829], [932.3519, 136657], [936.552, 103130], [939.6179, 77289], [949.3702, 85420],
                        [953.3966, 545281], [954.4916, 123937], [963.6868, 261578], [964.5247, 318164], [965.1921, 124405]
                      ]
                    },
                    "analog": false
                  }
                },
                "repository": {
                  "summary": "Repository search (MassIVE USI, metabolomicspanrepo_index)",
                  "value": {
                    "library": "metabolomicspanrepo_index",
                    "usi": "mzspec:MSV000086206:peak/S_N1.mzML:scan:164",
                    "analog": false
                  }
                },
                "filters": {
                  "summary": "Metadata filters, extra columns, top_k",
                  "value": {
                    "library": "gnpslibrary",
                    "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                    "filters": {"polarity": "positive"},
                    "metadata_columns": ["polarity"],
                    "top_k": 10
                  }
                },
                "async": {
                  "summary": "Always hand off to a job (202)",
                  "value": {
                    "library": "gnpslibrary",
                    "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                    "async": true
                  }
                },
                "peak_histogram": {
                  "summary": "Analog search plus a histogram of every hit's fragment m/z and neutral losses",
                  "value": {
                    "library": "gnpslibrary",
                    "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                    "analog": true,
                    "peak_histogram": {"bin_width": 0.01, "max_mz": 2500, "neutral_loss": true}
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Finished within the sync budget.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/V2SearchResult"},
                "example": {
                  "results": [
                    {
                      "Delta Mass": 0.0,
                      "GNPSLibraryAccession": "CCMSLIB00000001547",
                      "USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                      "Charge": 1,
                      "Cosine": 1.0,
                      "Matching Peaks": 42,
                      "Unit Delta Mass": 0,
                      "Dataset": "GNPS Library",
                      "Status": "HasID",
                      "Adduct": "M+H",
                      "CompoundName": "3-Des-Microcystein_LR",
                      "Query Scan": 1,
                      "Index UnitPM": 981,
                      "Index IdxInUnitPM": 2609
                    }
                  ],
                  "timing": [
                    {"desc": "Search", "timing": 0.0051},
                    {"desc": "Postprocess", "timing": 2e-05}
                  ],
                  "grouped_by_unit_delta_mass": [
                    {"Frequency": 1, "Unit Delta Mass": 0}
                  ],
                  "grouped_by_dataset": [
                    {"Frequency": 1, "Dataset": "GNPS Library"}
                  ],
                  "grouped_by_dataset_unit_delta": [
                    {"Frequency": 1, "Dataset": "GNPS Library", "Unit Delta Mass": 0}
                  ],
                  "metadata_groupings": [
                    [
                      "GNPSLibraryAccession",
                      [
                        {
                          "Frequency": 1,
                          "GNPSLibraryAccession": "CCMSLIB00000001547",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ],
                    [
                      "Adduct",
                      [
                        {
                          "Frequency": 1,
                          "Adduct": "M+H",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ],
                    [
                      "CompoundName",
                      [
                        {
                          "Frequency": 1,
                          "CompoundName": "3-Des-Microcystein_LR",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ]
                  ],
                  "log": "fasst 1.6.2 engine=ls library=gnpslibrary hits=1",
                  "temp_json_path": "",
                  "library": "gnpslibrary",
                  "engine": "ls",
                  "took_ms": 13.47,
                  "generation": 1
                }
              }
            }
          },
          "202": {
            "description": "Handed off to a job (budget exceeded, or `async`).",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobAccepted"},
                "example": {
                  "id": "2dac008f-be4e-477c-998c-7d3634d61809",
                  "kind": "search",
                  "status": "RUNNING",
                  "status_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809",
                  "result_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809/result"
                }
              }
            },
            "headers": {
              "Location": {
                "description": "The job's status URL.",
                "schema": {"type": "string"}
              }
            }
          },
          "400": {
            "description": "The search failed (bad spectrum, USI resolution, invalid parameters, timeout, filters on an index without a metadata store).",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "example": {"error": "resolving USI mzspec:...: HTTP status client error (404 Not Found)"}
              }
            }
          },
          "404": {"$ref": "#/components/responses/LibraryNotFound"},
          "410": {
            "description": "The result was evicted before it could be returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {"type": "string"},
                    "status": {"const": "EXPIRED"},
                    "error": {"type": "string"}
                  }
                },
                "example": {"id": "2dac008f-be4e-477c-998c-7d3634d61809", "status": "EXPIRED", "error": "result evicted"}
              }
            }
          },
          "413": {"description": "Request body too large (4 MB for inline spectra)."},
          "422": {
            "description": "Invalid body, no query spectrum, or invalid `filters`.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "example": {"error": "either usi or query_spectrum is required"}
              }
            }
          },
          "503": {"$ref": "#/components/responses/QueueFull"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/jobs/{id}": {
      "get": {
        "tags": ["v2"],
        "operationId": "v2JobStatus",
        "summary": "Job status (search or batch)",
        "description": "Poll about once a second at most. Rate limit: the polling bucket (20/s, burst 100 per IP).",
        "parameters": [
          {"$ref": "#/components/parameters/JobId"}
        ],
        "responses": {
          "200": {
            "description": "Status.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "examples": {
                  "search": {
                    "value": {
                      "id": "2dac008f-be4e-477c-998c-7d3634d61809",
                      "kind": "search",
                      "status": "COMPLETED",
                      "age_seconds": 0.5,
                      "result_bytes": 1423,
                      "status_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809",
                      "result_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809/result"
                    }
                  },
                  "batch": {
                    "value": {
                      "id": "e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                      "kind": "batch",
                      "status": "COMPLETED",
                      "age_seconds": 1.0,
                      "result_bytes": 1565,
                      "status_url": "/api/v2/jobs/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                      "result_url": "/api/v2/batch/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1/result",
                      "library": "gnpslibrary",
                      "progress": {"total": 2, "completed": 2, "failed": 0, "hits": 3, "truncated": false}
                    }
                  }
                }
              }
            }
          },
          "404": {"$ref": "#/components/responses/JobNotFound"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      },
      "delete": {
        "tags": ["export"],
        "operationId": "v2JobDelete",
        "summary": "Cancel or delete a job (exports and MassQL jobs)",
        "description": "Export: a queued or running export is cancelled (`CANCELLED`, the engine stops); a finished one is deleted with its files (`DELETED`). MassQL job: cancelled, as `DELETE /api/v2/massql/{id}`. Search and batch jobs: `405`.",
        "parameters": [
          {"$ref": "#/components/parameters/JobId"}
        ],
        "responses": {
          "200": {"description": "The job's status (CANCELLED), or {\"status\": \"DELETED\"} for a finished export.", "content": {"application/json": {"schema": {"type": "object"}}}},
          "404": {"$ref": "#/components/responses/JobNotFound"},
          "405": {"description": "Search and batch jobs cannot be cancelled.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/jobs/{id}/files": {
      "get": {
        "tags": ["export"],
        "operationId": "v2ExportFiles",
        "summary": "An export's part files (its result_url)",
        "description": "The export's closed parts (each `name`, `rows`, `bytes`, `sha256` of the file, `url`), in order, with `rows`, `found`, `truncated`, `expires_in_secs` and `final`. `200` once `COMPLETED`: `final: true`, every part. `202` while `PENDING` / `RUNNING`: the job status plus the listing with `final: false`: the parts closed so far (more may come; `rows` / `found` are so far and `rows` includes the part being written, which is not listed). A listed part is a complete file with its final size and hash and never changes; parts can be downloaded as soon as they are listed (search exports write theirs only after the external sort, near the end). `400` with the job status and `final: true` when the export failed or was cancelled. Anyone with the job id may read it.",
        "parameters": [
          {"$ref": "#/components/parameters/JobId"}
        ],
        "responses": {
          "200": {"description": "All parts (`final: true`).", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ExportFiles"}, "example": {"id": "5b0e2f1c-8f6e-4a8e-9a55-2f3a3d1f0c11", "status": "COMPLETED", "final": true, "format": "jsonl", "rows": 1144423, "found": 1144423, "truncated": false, "expires_in_secs": 3580, "parts": [{"name": "part-00000.jsonl.zst", "rows": 1000000, "bytes": 48213377, "sha256": "3a76a5057e834d1e39f27d991a004446e115cdc92c01643bcffe66e907d97ef1", "url": "/api/v2/jobs/5b0e2f1c-8f6e-4a8e-9a55-2f3a3d1f0c11/files/part-00000.jsonl.zst"}]}}}},
          "202": {"description": "Still running: the job status plus the parts closed so far (`final: false`).", "content": {"application/json": {"schema": {"allOf": [{"$ref": "#/components/schemas/JobStatus"}, {"$ref": "#/components/schemas/ExportFiles"}]}, "example": {"id": "5b0e2f1c-8f6e-4a8e-9a55-2f3a3d1f0c11", "kind": "export", "status": "RUNNING", "status_url": "/api/v2/jobs/5b0e2f1c-8f6e-4a8e-9a55-2f3a3d1f0c11", "result_url": "/api/v2/jobs/5b0e2f1c-8f6e-4a8e-9a55-2f3a3d1f0c11/files", "final": false, "format": "jsonl", "rows": 1021377, "found": 1021377, "truncated": false, "expires_in_secs": null, "parts": [{"name": "part-00000.jsonl.zst", "rows": 1000000, "bytes": 48213377, "sha256": "3a76a5057e834d1e39f27d991a004446e115cdc92c01643bcffe66e907d97ef1", "url": "/api/v2/jobs/5b0e2f1c-8f6e-4a8e-9a55-2f3a3d1f0c11/files/part-00000.jsonl.zst"}]}}}},
          "400": {"description": "Failed or cancelled (the job status, `final: true`).", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/JobStatus"}}}},
          "404": {"$ref": "#/components/responses/JobNotFound"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/jobs/{id}/files/{name}": {
      "get": {
        "tags": ["export"],
        "operationId": "v2ExportDownload",
        "summary": "Download one export part (.jsonl.zst or .parquet, HTTP Range supported)",
        "description": "`application/zstd`: zstd-compressed JSON lines, one row per line (search: the v2 `results` records, best first; massql: the MassQL rows; batch: one row per hit with the query's fields first). A `format: parquet` export's parts (`part-NNNNN.parquet`) are `application/vnd.apache.parquet`, each a complete Parquet file of the same rows. `Range: bytes=a-b` / `a-` / `-n` answers `206` with `Content-Range`; an unsatisfiable range `416`. `ETag` is the part's sha256. A download in progress when the export expires completes. Parts are served as soon as they are listed, while the export still runs; a part not listed yet (still being written) is `404` with `final: false` (it may appear later); a failed or cancelled export's parts answer `400` with the job status.",
        "parameters": [
          {"$ref": "#/components/parameters/JobId"},
          {"name": "name", "in": "path", "required": true, "schema": {"type": "string"}, "description": "A part name from the files list, e.g. part-00000.jsonl.zst or part-00000.parquet."},
          {"name": "Range", "in": "header", "required": false, "schema": {"type": "string"}}
        ],
        "responses": {
          "200": {"description": "The part.", "content": {"application/zstd": {"schema": {"type": "string", "format": "binary"}}, "application/vnd.apache.parquet": {"schema": {"type": "string", "format": "binary"}}}},
          "206": {"description": "The requested byte range.", "content": {"application/zstd": {"schema": {"type": "string", "format": "binary"}}, "application/vnd.apache.parquet": {"schema": {"type": "string", "format": "binary"}}}},
          "400": {"description": "The export failed or was cancelled (the job status, `final: true`).", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/JobStatus"}}}},
          "404": {"description": "Unknown job, or a part not listed (yet: `final: false` while the export runs).", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "410": {"description": "The export's files were deleted.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "416": {"description": "Range not satisfiable."},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/jobs/{id}/result": {
      "get": {
        "tags": ["v2"],
        "operationId": "v2JobResult",
        "summary": "Job result",
        "description": "Search job: the result JSON, streamed from the stored hits (`?format=jsonl`: the `results` records one per line, then an `{\"end\": ...}` line, as `POST /api/v2/search` with `format: jsonl`). The job keeps up to the client's hit cap (1 000 000); JSON lists the best `--max-hits-json` (100 000) of them (`truncated_reason: max_hits_json`), JSONL all of them. Batch job: same as `GET /api/v2/batch/{id}/result?format=jsonl`.",
        "parameters": [
          {"$ref": "#/components/parameters/JobId"},
          {"name": "format", "in": "query", "required": false, "schema": {"type": "string", "enum": ["json", "jsonl"], "default": "json"}, "description": "Search jobs only."}
        ],
        "responses": {
          "200": {
            "description": "Search result (JSON), or batch rows (JSONL).",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/V2SearchResult"},
                "example": {
                  "results": [
                    {
                      "Delta Mass": 0.0,
                      "GNPSLibraryAccession": "CCMSLIB00000001547",
                      "USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                      "Charge": 1,
                      "Cosine": 1.0,
                      "Matching Peaks": 42,
                      "Unit Delta Mass": 0,
                      "Dataset": "GNPS Library",
                      "Status": "HasID",
                      "Adduct": "M+H",
                      "CompoundName": "3-Des-Microcystein_LR",
                      "Query Scan": 1,
                      "Index UnitPM": 981,
                      "Index IdxInUnitPM": 2609
                    }
                  ],
                  "timing": [
                    {"desc": "Search", "timing": 0.0051},
                    {"desc": "Postprocess", "timing": 2e-05}
                  ],
                  "grouped_by_unit_delta_mass": [
                    {"Frequency": 1, "Unit Delta Mass": 0}
                  ],
                  "grouped_by_dataset": [
                    {"Frequency": 1, "Dataset": "GNPS Library"}
                  ],
                  "grouped_by_dataset_unit_delta": [
                    {"Frequency": 1, "Dataset": "GNPS Library", "Unit Delta Mass": 0}
                  ],
                  "metadata_groupings": [
                    [
                      "GNPSLibraryAccession",
                      [
                        {
                          "Frequency": 1,
                          "GNPSLibraryAccession": "CCMSLIB00000001547",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ],
                    [
                      "Adduct",
                      [
                        {
                          "Frequency": 1,
                          "Adduct": "M+H",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ],
                    [
                      "CompoundName",
                      [
                        {
                          "Frequency": 1,
                          "CompoundName": "3-Des-Microcystein_LR",
                          "Best Cosine": 1.0,
                          "Best Delta Mass": 0.0,
                          "Best USI": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                          "Best Charge": 1
                        }
                      ]
                    ]
                  ],
                  "log": "fasst 1.6.2 engine=ls library=gnpslibrary hits=1",
                  "temp_json_path": "",
                  "library": "gnpslibrary",
                  "engine": "ls",
                  "took_ms": 13.47,
                  "generation": 1
                }
              },
              "application/x-ndjson": {
                "schema": {"type": "string"},
                "example": "{\"query_index\": 0, \"query_id\": \"q1\", \"query_scan\": 1, \"query_charge\": 1, \"query_precursor_mz\": 981.54, \"num_hits\": 1, \"total_hits\": 1, \"truncated\": false, \"hits\": [{\"library\": \"gnpslibrary\", \"library_file\": \"GNPS-LIBRARY.mgf\", \"library_scan\": 1, \"library_usi\": \"mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547\", \"charge\": 1, \"precursor_mz\": 981.54, \"delta_mass\": 0.0, \"cosine\": 1.0, \"matched_peaks\": 42, \"spectrum_id\": 2609, \"metadata\": {\"GNPSLibraryAccession\": \"CCMSLIB00000001547\", \"CompoundName\": \"3-Des-Microcystein_LR\", \"Adduct\": \"M+H\"}}]}\n"
              }
            }
          },
          "202": {
            "description": "Still pending or running: the status body.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "2dac008f-be4e-477c-998c-7d3634d61809",
                  "kind": "search",
                  "status": "RUNNING",
                  "age_seconds": 0.5,
                  "result_bytes": 0,
                  "status_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809",
                  "result_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809/result"
                }
              }
            }
          },
          "400": {
            "description": "The job failed: the status body with `error`.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "2dac008f-be4e-477c-998c-7d3634d61809",
                  "kind": "search",
                  "status": "FAILED",
                  "age_seconds": 0.5,
                  "result_bytes": 0,
                  "status_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809",
                  "result_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809/result",
                  "error": "library 'nope' not found"
                }
              }
            }
          },
          "404": {"$ref": "#/components/responses/JobNotFound"},
          "410": {
            "description": "The result expired (evicted by the byte cap).",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "2dac008f-be4e-477c-998c-7d3634d61809",
                  "kind": "search",
                  "status": "EXPIRED",
                  "age_seconds": 0.5,
                  "result_bytes": 0,
                  "status_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809",
                  "result_url": "/api/v2/jobs/2dac008f-be4e-477c-998c-7d3634d61809/result"
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/batch": {
      "post": {
        "tags": ["batch"],
        "operationId": "v2BatchSubmit",
        "summary": "Submit a batch search (async)",
        "description": "Two input forms, chosen by `Content-Type`:\n\n1. `application/json`: a `BatchRequest` (parameters + `spectra`).\n2. Any other content type (e.g. `chemical/x-mgf`, `text/plain`): the **raw body is an MGF file** (MS2 spectra with `PEPMASS > 0`; `SPECTRUMID` or `TITLE` becomes the query id) and the parameters come from the **query string**, e.g. `?library=gnpslibrary&analog=true&min_matched_peaks=6`.\n\nPer-query failures (USI resolution, bad peaks, timeout) do not fail the batch; they are rows with an `error`. Batches run with at most `--batch-workers` concurrent queries across all batches.\n\nRate limit: the batch bucket (10/min, burst 5 per IP); body up to `--max-batch-body` (64 MiB).",
        "parameters": [
          {
            "name": "library",
            "in": "query",
            "required": false,
            "description": "MGF uploads: library name (JSON bodies carry it in the body).",
            "schema": {"type": "string"},
            "example": "gnpslibrary"
          },
          {
            "name": "analog",
            "in": "query",
            "required": false,
            "description": "MGF uploads: analog search.",
            "schema": {"type": "string", "enum": ["true", "false", "Yes", "No", "1", "0"]}
          },
          {
            "name": "lower_delta",
            "in": "query",
            "required": false,
            "description": "MGF uploads.",
            "schema": {"type": "number"}
          },
          {
            "name": "upper_delta",
            "in": "query",
            "required": false,
            "description": "MGF uploads.",
            "schema": {"type": "number"}
          },
          {
            "name": "pm_tolerance",
            "in": "query",
            "required": false,
            "description": "MGF uploads.",
            "schema": {"type": "number"}
          },
          {
            "name": "fragment_tolerance",
            "in": "query",
            "required": false,
            "description": "MGF uploads.",
            "schema": {"type": "number"}
          },
          {
            "name": "cosine_threshold",
            "in": "query",
            "required": false,
            "description": "MGF uploads.",
            "schema": {"type": "number"}
          },
          {
            "name": "min_matched_peaks",
            "in": "query",
            "required": false,
            "description": "MGF uploads.",
            "schema": {"type": "integer"}
          },
          {
            "name": "top_k",
            "in": "query",
            "required": false,
            "description": "MGF uploads.",
            "schema": {"type": "integer"}
          },
          {
            "name": "score",
            "in": "query",
            "required": false,
            "description": "MGF uploads: similarity score (see `BatchRequest.score`).",
            "schema": {"type": "string", "enum": ["cosine", "entropy", "reverse_cosine"]}
          },
          {
            "name": "reverse",
            "in": "query",
            "required": false,
            "description": "MGF uploads: reverse cosine side (see `BatchRequest.reverse`).",
            "schema": {"type": "string", "enum": ["index", "query"]}
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/BatchRequest"},
              "example": {
                "library": "gnpslibrary",
                "analog": true,
                "min_matched_peaks": 6,
                "spectra": [
                  {"id": "q1", "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547"},
                  {
                    "id": "q2",
                    "peaks": [
                      [456.1075, 105392], [469.8723, 87594], [515.9229, 78764], [538.0032, 220949], [539.2178, 272296],
                      [554.1174, 76225], [556.0304, 214421], [582.1101, 102075], [599.3528, 764523], [600.3828, 114267],
                      [696.3324, 121211], [724.0819, 88510], [830.4093, 102583], [839.4558, 72006], [847.4336, 196462],
                      [851.3809, 246170], [852.3706, 276882], [866.2957, 111012], [868.3722, 78023], [909.4244, 244136],
                      [919.3962, 85829], [932.3519, 136657], [936.552, 103130], [939.6179, 77289], [949.3702, 85420],
                      [953.3966, 545281], [954.4916, 123937], [963.6868, 261578], [964.5247, 318164], [965.1921, 124405]
                    ],
                    "precursor_mz": 981.54,
                    "precursor_charge": 1
                  },
                  "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001548"
                ]
              }
            },
            "chemical/x-mgf": {
              "schema": {"type": "string"},
              "example": "BEGIN IONS\nTITLE=q1\nPEPMASS=981.54\nCHARGE=1+\n456.1075 105392\n469.8723 87594\n515.9229 78764\n538.0032 220949\n539.2178 272296\n554.1174 76225\n556.0304 214421\n582.1101 102075\n599.3528 764523\n600.3828 114267\n696.3324 121211\n724.0819 88510\n830.4093 102583\n839.4558 72006\n847.4336 196462\n851.3809 246170\n852.3706 276882\n866.2957 111012\n868.3722 78023\n909.4244 244136\n919.3962 85829\n932.3519 136657\n936.552 103130\n939.6179 77289\n949.3702 85420\n953.3966 545281\n954.4916 123937\n963.6868 261578\n964.5247 318164\n965.1921 124405\nEND IONS\n"
            },
            "text/plain": {
              "schema": {"type": "string"},
              "example": "BEGIN IONS\nTITLE=q1\nPEPMASS=981.54\nCHARGE=1+\n456.1075 105392\n469.8723 87594\n515.9229 78764\n538.0032 220949\n539.2178 272296\n554.1174 76225\n556.0304 214421\n582.1101 102075\n599.3528 764523\n600.3828 114267\n696.3324 121211\n724.0819 88510\n830.4093 102583\n839.4558 72006\n847.4336 196462\n851.3809 246170\n852.3706 276882\n866.2957 111012\n868.3722 78023\n909.4244 244136\n919.3962 85829\n932.3519 136657\n936.552 103130\n939.6179 77289\n949.3702 85420\n953.3966 545281\n954.4916 123937\n963.6868 261578\n964.5247 318164\n965.1921 124405\nEND IONS\n"
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobAccepted"},
                "example": {
                  "id": "e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "kind": "batch",
                  "status": "PENDING",
                  "status_url": "/api/v2/jobs/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "result_url": "/api/v2/batch/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1/result",
                  "total": 3,
                  "library": "gnpslibrary"
                }
              }
            },
            "headers": {
              "Location": {
                "description": "The job's status URL.",
                "schema": {"type": "string"}
              }
            }
          },
          "404": {"$ref": "#/components/responses/LibraryNotFound"},
          "413": {
            "description": "More than `--max-batch-spectra` spectra (default 10 000), or the body exceeds `--max-batch-body`.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "example": {"error": "10001 spectra exceed the batch limit of 10000"}
              }
            }
          },
          "422": {
            "description": "Invalid JSON/MGF, empty batch, bad item, invalid parameters or `filters`.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "example": {"error": "field 'spectra' (array) is required"}
              }
            }
          },
          "503": {"$ref": "#/components/responses/QueueFull"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/batch/{id}": {
      "get": {
        "tags": ["batch"],
        "operationId": "v2BatchStatus",
        "summary": "Batch status (batch jobs only; /api/v2/jobs/{id} serves every job)",
        "description": "The status of a batch job. Another kind of job (a search, a MassQL job) is `404` here, with its `kind`, `status_url` and `result_url`; the same holds for `/api/v2/batch/{id}/result`.",
        "parameters": [
          {"$ref": "#/components/parameters/BatchId"}
        ],
        "responses": {
          "200": {
            "description": "Status with `progress`.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "kind": "batch",
                  "status": "COMPLETED",
                  "age_seconds": 1.0,
                  "result_bytes": 1565,
                  "status_url": "/api/v2/jobs/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "result_url": "/api/v2/batch/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1/result",
                  "library": "gnpslibrary",
                  "progress": {"total": 2, "completed": 2, "failed": 0, "hits": 3, "truncated": false}
                }
              }
            }
          },
          "404": {"$ref": "#/components/responses/JobNotFound"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/batch/{id}/result": {
      "get": {
        "tags": ["batch"],
        "operationId": "v2BatchResult",
        "summary": "Batch results (JSONL stream or Parquet)",
        "description": "`format=jsonl` (default) **streams**: completed rows immediately, then new rows as queries finish, until the batch is done (one line per query, completion order; an evicted batch ends with `{\"error\":\"EXPIRED\"}`). `format=parquet`: one file, one row per hit, once the batch is done (`202` + status while running). Non-analog batches keep only hits within `pm_tolerance`.",
        "parameters": [
          {"$ref": "#/components/parameters/BatchId"},
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Result format.",
            "schema": {"type": "string", "enum": ["jsonl", "ndjson", "parquet"], "default": "jsonl"}
          }
        ],
        "responses": {
          "200": {
            "description": "Rows.",
            "content": {
              "application/x-ndjson": {
                "schema": {"type": "string", "description": "One `BatchResultLine` JSON object per line."},
                "example": "{\"query_index\": 0, \"query_id\": \"q1\", \"query_scan\": 1, \"query_charge\": 1, \"query_precursor_mz\": 981.54, \"num_hits\": 1, \"total_hits\": 1, \"truncated\": false, \"hits\": [{\"library\": \"gnpslibrary\", \"library_file\": \"GNPS-LIBRARY.mgf\", \"library_scan\": 1, \"library_usi\": \"mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547\", \"charge\": 1, \"precursor_mz\": 981.54, \"delta_mass\": 0.0, \"cosine\": 1.0, \"matched_peaks\": 42, \"spectrum_id\": 2609, \"metadata\": {\"GNPSLibraryAccession\": \"CCMSLIB00000001547\", \"CompoundName\": \"3-Des-Microcystein_LR\", \"Adduct\": \"M+H\"}}]}\n"
              },
              "application/vnd.apache.parquet": {
                "schema": {"type": "string", "contentEncoding": "binary"}
              }
            }
          },
          "202": {
            "description": "Parquet requested while the batch is running: the status body.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "kind": "batch",
                  "status": "RUNNING",
                  "age_seconds": 1.0,
                  "result_bytes": 1565,
                  "status_url": "/api/v2/jobs/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "result_url": "/api/v2/batch/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1/result",
                  "library": "gnpslibrary",
                  "progress": {"total": 2, "completed": 2, "failed": 0, "hits": 3, "truncated": false}
                }
              }
            }
          },
          "400": {
            "description": "Unknown format, or the batch failed.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "example": {"error": "unknown format 'csv' (jsonl|parquet)"}
              }
            }
          },
          "404": {
            "description": "Unknown batch id.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/NotFoundJob"},
                "example": {
                  "id": "e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "status": "NOT_FOUND",
                  "error": "unknown batch id"
                }
              }
            }
          },
          "410": {
            "description": "Expired.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "kind": "batch",
                  "status": "EXPIRED",
                  "age_seconds": 1.0,
                  "result_bytes": 1565,
                  "status_url": "/api/v2/jobs/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1",
                  "result_url": "/api/v2/batch/e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1/result",
                  "library": "gnpslibrary",
                  "progress": {"total": 2, "completed": 2, "failed": 0, "hits": 3, "truncated": false}
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/massql": {
      "post": {
        "tags": ["massql"],
        "operationId": "v2MassqlSubmit",
        "summary": "Submit a MassQL query (async)",
        "description": "Runs a [MassQL](https://mwang87.github.io/MassQueryLanguage_Documentation/) query on an **engine-ls** library and returns one row per matching scan (like a batch: stream JSONL, or fetch Parquet / dataset counts when done).\n\nSupported: `QUERY scaninfo(MS2DATA)`, `scannum(MS2DATA)` and `MS2DATA` (all return scan rows) with `MS2PROD`, `MS2NL`, `MS2PREC` (values, `OR` lists, `ANY`, the variable `X` in linear expressions), qualifiers `TOLERANCEMZ`, `TOLERANCEPPM`, `INTENSITYPERCENT`, `INTENSITYTICPERCENT`, `INTENSITYVALUE`, `INTENSITYMATCH` / `INTENSITYMATCHPERCENT` / `INTENSITYMATCHREFERENCE`, `EXCLUDED`, `MASSDEFECT`, `CARDINALITY`; `RTMIN` / `RTMAX` (minutes), `SCANMIN` / `SCANMAX`, `CHARGE`, `POLARITY`, `X=range(...)`, `X=massdefect(...)`, `FILTER MS2PROD`. `MS2NL` is disabled on the server for now (`422`; `--massql-neutral-loss` enables it). MS1 data and conditions, `INTENSITYVALUE` on indices built before FASST stored the absolute intensity scale, `MOBILITY` and the aggregate functions are refused with `422`.\n\n**Queries see the stored peaks**: the index's preprocessing (default: fragments within 17 Da of the precursor removed, top 6 peaks per 50 Da), so neutral losses under ~17 Da cannot match. Intensity qualifiers follow Python MassQL on the raw spectrum restricted to the stored peaks: relative to the raw base peak / raw TIC, and `INTENSITYVALUE` on the absolute scale (stored² × `kept_intensity_sum`); on older indices they are relative to the stored peaks.\n\nCost guards: the query needs a selective condition (a numeric `MS2PROD` or `MS2NL` without `EXCLUDED` whose windows total at most 10 Da, or `MS2PREC` windows of at most 2 Da in total), at most `max_matches` scans are kept (server cap `--massql-max-matches`, default 100000; the run stops there, flagged `truncated`), and a run stops after `--massql-timeout-secs` (default 900 s, counted from the start of the run; it then becomes `FAILED` with `progress.stop_reason: \"timeout\"` and its rows so far stay readable); `DELETE /api/v2/massql/{id}` cancels it. A run holds one batch slot.\n\nRate limit: the batch bucket (10/min, burst 5 per IP).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/MassqlRequest"},
              "examples": {
                "fragment": {
                  "summary": "Phosphocholine fragment",
                  "value": {"library": "metabolomicspanrepo_index", "query": "QUERY scaninfo(MS2DATA) WHERE MS2PROD=184.0739:TOLERANCEPPM=10:INTENSITYPERCENT=20"}
                },
                "loss": {
                  "summary": "Hexose loss from precursors in a window, positive mode, first 1000 scans",
                  "value": {
                    "library": "metabolomicspanrepo_index",
                    "query": "QUERY scaninfo(MS2DATA) WHERE MS2NL=162.0528:TOLERANCEMZ=0.01 AND MS2PREC=500:TOLERANCEMZ=0.5 AND POLARITY=Positive",
                    "max_matches": 1000,
                    "filters": {"datasets": ["MSV000086206"]}
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted; poll `status_url`, read `result_url`.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobAccepted"},
                "example": {
                  "id": "7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "kind": "massql",
                  "status": "PENDING",
                  "status_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "result_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11/result",
                  "library": "metabolomicspanrepo_index",
                  "query": "QUERY scaninfo(MS2DATA) WHERE MS2PROD=184.0739:TOLERANCEPPM=10:INTENSITYPERCENT=20",
                  "max_matches": 100000
                }
              }
            }
          },
          "404": {"$ref": "#/components/responses/LibraryNotFound"},
          "422": {
            "description": "Missing fields, MassQL syntax error, unsupported condition, not an engine-ls library, or no selective condition.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "examples": {
                  "ms1": {"value": {"error": "condition 1: MS1MZ is not supported on this index: FASST indices store MS2 spectra only (no MS1 scans; only the precursor isotope envelope is kept as metadata). Use MS2PREC, MS2PROD and MS2NL conditions"}},
                  "unselective": {"value": {"error": "the query has no selective condition (a numeric MS2PROD or MS2NL without EXCLUDED with windows of at most 10 Da in total, or MS2PREC windows of at most 2 Da), so it would read every spectrum of the index"}}
                }
              }
            }
          },
          "501": {
            "description": "This server has no MassQL executor.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "example": {"error": "MassQL is not available in this server"}
              }
            }
          },
          "503": {"$ref": "#/components/responses/QueueFull"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/massql/stream": {
      "post": {
        "tags": ["massql"],
        "operationId": "v2MassqlStream",
        "summary": "Stream every match of a MassQL query (JSON lines, no cap)",
        "description": "Runs a MassQL query like `POST /api/v2/massql` and streams **every** matching scan as JSON lines while the library is searched. Nothing is kept on the server, so there is no `--massql-max-matches` / result-size cap (`max_matches` is optional, unlimited by default).\n\nLines, in order:\n- rows (the job result's JSONL rows, in spectrum-id order);\n- `{\"progress\": {...}}` after 15 s without a line (keeps proxies from timing out);\n- last, always: `{\"end\": {\"complete\", \"matches\", \"stop_reason\", \"shards_done\", \"shards_total\", \"seconds\", \"stats\"}}`, plus a top-level `error` if the run failed.\n\nA stream with no `end` line was cut. `stop_reason` is one of: `max_matches`, `timeout` (`--massql-stream-timeout-secs`, default 3600), `client_stalled` (the client read nothing for `--massql-stream-stall-secs`, default 120), `error`. Disconnecting stops the search.\n\nAdmission works as for a MassQL job: one bulk slot per non-whitelisted client, a batch slot and a search worker while it runs.\n\nRate limit: the batch bucket. Errors (`404` / `422` / `429` / `503`) come before any row.",
        "requestBody": {
          "required": true,
          "content": {"application/json": {"schema": {"$ref": "#/components/schemas/MassqlRequest"}, "example": {"library": "metabolomicspanrepo_index", "query": "QUERY scaninfo(MS2DATA) WHERE MS2PROD=137.0597:TOLERANCEMZ=0.01"}}}
        },
        "responses": {
          "200": {"description": "JSON lines: rows, progress lines, then the end line.", "content": {"application/x-ndjson": {"schema": {"type": "string"}, "example": "{\"dataset\":\"MSV000086206\",\"file\":\"...\",\"scan\":1234,\"usi\":\"mzspec:MSV000086206:...:scan:1234\"}\n{\"end\":{\"complete\":true,\"matches\":1,\"stop_reason\":null,\"shards_done\":4,\"shards_total\":4,\"seconds\":0.7}}\n"}}},
          "404": {"$ref": "#/components/responses/LibraryNotFound"},
          "422": {"description": "As `POST /api/v2/massql`.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "503": {"$ref": "#/components/responses/QueueFull"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      },
      "get": {
        "tags": ["massql"],
        "operationId": "v2MassqlStreamGet",
        "summary": "Stream every match of a MassQL query (GET form, no filters)",
        "description": "The `POST` form's stream with the request in the query string (handy for `curl` and links); `filters` need the POST body.",
        "parameters": [
          {"name": "library", "in": "query", "required": true, "schema": {"type": "string"}},
          {"name": "query", "in": "query", "required": true, "schema": {"type": "string"}},
          {"name": "max_matches", "in": "query", "required": false, "schema": {"type": "integer", "minimum": 1}},
          {"name": "metadata_columns", "in": "query", "required": false, "description": "Comma-separated metadata columns (`metadata_columns` of the POST body).", "schema": {"type": "string"}}
        ],
        "responses": {
          "200": {"description": "JSON lines: rows, progress lines, then the end line.", "content": {"application/x-ndjson": {"schema": {"type": "string"}, "example": "{\"dataset\":\"MSV000086206\",\"file\":\"...\",\"scan\":1234,\"usi\":\"mzspec:MSV000086206:...:scan:1234\"}\n{\"end\":{\"complete\":true,\"matches\":1,\"stop_reason\":null,\"shards_done\":4,\"shards_total\":4,\"seconds\":0.7}}\n"}}},
          "404": {"$ref": "#/components/responses/LibraryNotFound"},
          "422": {"description": "As `POST /api/v2/massql`.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "503": {"$ref": "#/components/responses/QueueFull"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/massql/{id}": {
      "get": {
        "tags": ["massql"],
        "operationId": "v2MassqlStatus",
        "summary": "MassQL job status (MassQL jobs only; /api/v2/jobs/{id} serves every job)",
        "description": "`status`: `PENDING`, `RUNNING`, `COMPLETED`, `FAILED` (an engine error, or the run timed out after `--massql-timeout-secs`, default 900 s: `progress.stop_reason` is `timeout`), `CANCELLED` (`DELETE`), `EXPIRED`. Failed and cancelled runs keep the rows found before they stopped (at `result_url`). Another kind of job is `404` here, with its own URLs.",
        "parameters": [{"$ref": "#/components/parameters/JobId"}],
        "responses": {
          "200": {
            "description": "Status with `progress` (matches so far, datasets, shards done of total, `truncated`, `stop_reason`, and the execution `stats` when done).",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "kind": "massql",
                  "status": "COMPLETED",
                  "age_seconds": 0.4,
                  "result_bytes": 3120,
                  "status_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "result_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11/result",
                  "library": "metabolomicspanrepo_index",
                  "query": "QUERY scaninfo(MS2DATA) WHERE MS2PROD=184.0739:TOLERANCEPPM=10:INTENSITYPERCENT=20",
                  "max_matches": 100000,
                  "progress": {
                    "matches": 9,
                    "datasets": 1,
                    "shards_done": 1,
                    "shards_total": 1,
                    "finished": true,
                    "truncated": false,
                    "stop_reason": null,
                    "stats": {
                      "shards": 1, "shards_searched": 1, "candidates": 13, "verified": 13, "matches": 9, "postings": 13,
                      "full_scan": false, "truncated": false, "seconds": 0.0003,
                      "plan": ["condition 1 MS2PROD (184.0721, 184.0757) → shared bins"],
                      "warnings": []
                    }
                  }
                }
              }
            }
          },
          "404": {"$ref": "#/components/responses/JobNotFound"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      },
      "delete": {
        "tags": ["massql"],
        "operationId": "v2MassqlCancel",
        "summary": "Cancel a MassQL job",
        "description": "Stops a `PENDING` or `RUNNING` MassQL job: the engine checks between shards and every 256 record groups, so it stops within a fraction of a second, and the job's batch slot and worker are released. The status becomes `CANCELLED` (`progress.stop_reason` `cancelled`, `truncated` true); the rows found before the cancel stay readable at `result_url` (JSONL ends with `{\"error\": ...}`). A job that already finished is left as it is (`200`, its status). Idempotent.",
        "parameters": [{"$ref": "#/components/parameters/JobId"}],
        "responses": {
          "200": {
            "description": "The job's status: `CANCELLED`, or its final status if it had already finished.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "kind": "massql",
                  "status": "CANCELLED",
                  "age_seconds": 12.5,
                  "result_bytes": 65536,
                  "status_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "result_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11/result",
                  "error": "cancelled (DELETE); the rows found before are kept",
                  "library": "metabolomicspanrepo_index",
                  "query": "QUERY scaninfo(MS2DATA) WHERE MS2PROD=137.0597",
                  "max_matches": 100000,
                  "progress": {"matches": 240, "datasets": 31, "shards_done": 57, "shards_total": 1376, "finished": true, "truncated": true, "stop_reason": "cancelled"}
                }
              }
            }
          },
          "202": {
            "description": "The job is still stopping after 10 s (status body; poll it).",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/JobStatus"}}}
          },
          "404": {"$ref": "#/components/responses/JobNotFound"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/massql/{id}/result": {
      "get": {
        "tags": ["massql"],
        "operationId": "v2MassqlResult",
        "summary": "MassQL results (JSONL stream, Parquet, or dataset counts)",
        "description": "`format=jsonl` (default) **streams** one `MassqlRow` per matching scan, in spectrum-id order, as they are found, until the run is done (a failed, timed-out or cancelled run ends with `{\"error\": ...}`, an evicted one with `{\"error\":\"EXPIRED\"}`). Rows stay readable after the job is `FAILED` or `CANCELLED` (the rows found before it stopped; `410` only once `EXPIRED`). `format=parquet`: one file with the same columns (`matched` as a JSON string) once the run is done (`202` + status while running). `format=counts`: dataset-level counts (`MassqlCounts`), partial while running.",
        "parameters": [
          {"$ref": "#/components/parameters/JobId"},
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Result format.",
            "schema": {"type": "string", "enum": ["jsonl", "ndjson", "parquet", "counts"], "default": "jsonl"}
          }
        ],
        "responses": {
          "200": {
            "description": "Rows, or counts.",
            "content": {
              "application/x-ndjson": {
                "schema": {"type": "string", "description": "One `MassqlRow` JSON object per line."},
                "example": "{\"spectrum_id\": 10222, \"usi\": \"mzspec:MSV000086206:S_P2.mzML:scan:2625\", \"file\": \"MSV000086206/S_P2.mzML\", \"dataset\": \"MSV000086206\", \"scan\": 2625, \"rt\": 5.8738, \"precursor_mz\": 350.217629908123, \"charge\": 1, \"polarity\": \"positive\", \"matched\": [{\"condition\": 0, \"type\": \"MS2PROD\", \"value\": 184.0739, \"observed\": 184.07501220703125, \"mz\": 184.07501220703125, \"intensity_percent\": 35.4}]}\n"
              },
              "application/vnd.apache.parquet": {
                "schema": {"type": "string", "contentEncoding": "binary"}
              },
              "application/json": {
                "schema": {"$ref": "#/components/schemas/MassqlCounts"},
                "example": {
                  "id": "7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "library": "metabolomicspanrepo_index",
                  "finished": true,
                  "truncated": false,
                  "matches": 9,
                  "datasets": [{"dataset": "MSV000086206", "scans": 9, "files": 4}]
                }
              }
            }
          },
          "202": {
            "description": "Parquet requested while the run is going: the status body.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "kind": "massql",
                  "status": "RUNNING",
                  "age_seconds": 0.2,
                  "result_bytes": 0,
                  "status_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "result_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11/result",
                  "library": "metabolomicspanrepo_index",
                  "query": "QUERY scaninfo(MS2DATA) WHERE MS2PROD=184.0739:TOLERANCEPPM=10",
                  "max_matches": 100000,
                  "progress": {"matches": 0, "datasets": 0, "finished": false, "truncated": false}
                }
              }
            }
          },
          "400": {
            "description": "Unknown format, or the job failed.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "example": {"error": "unknown format 'csv' (jsonl|parquet|counts)"}
              }
            }
          },
          "404": {
            "description": "Unknown MassQL job id.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/NotFoundJob"},
                "example": {"id": "7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11", "status": "NOT_FOUND", "error": "unknown MassQL job id"}
              }
            }
          },
          "410": {
            "description": "Expired (evicted by the result byte cap).",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/JobStatus"},
                "example": {
                  "id": "7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "kind": "massql",
                  "status": "EXPIRED",
                  "age_seconds": 900.0,
                  "result_bytes": 0,
                  "status_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11",
                  "result_url": "/api/v2/massql/7d1c2f7e-4a8e-4c55-9d53-1c7b8f0a2e11/result"
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/libraries": {
      "get": {
        "tags": ["v2"],
        "operationId": "v2Libraries",
        "summary": "Loaded libraries with details",
        "responses": {
          "200": {
            "description": "Registry.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/V2Libraries"},
                "example": {
                  "generation": 1,
                  "loaded_unix": 1790620749,
                  "libraries": [
                    {
                      "name": "gnpslibrary",
                      "engine": "ls",
                      "engine_format_version": 3,
                      "version": "gnpslibrary@20260928T120000Z",
                      "num_spectra": 2986,
                      "num_files": 1,
                      "created_unix": 1790620725,
                      "preprocessing": {
                        "kind": "ls",
                        "filter_precursor": true,
                        "precursor_radius": 17.0,
                        "filter_window": true,
                        "window_size": 50.0,
                        "peaks_to_keep": 6,
                        "min_peaks": 1,
                        "min_mz": 0.0
                      },
                      "labels": {
                        "result_metadata_columns": "GNPSLibraryAccession,CompoundName,Adduct",
                        "libsync.built_at": "2026-09-28T12:00:00Z",
                        "libsync.imported_at_max": "2026-09-27T08:15:00Z"
                      }
                    }
                  ],
                  "errors": {}
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/spectrum/{library}/{id}": {
      "get": {
        "tags": ["v2"],
        "operationId": "v2Spectrum",
        "summary": "One indexed spectrum",
        "description": "The stored (preprocessed) spectrum and its metadata. `id` is the index-internal spectrum id (e.g. `spectrum_id` of a batch hit, or `Index IdxInUnitPM` of a result row).",
        "parameters": [
          {
            "name": "library",
            "in": "path",
            "required": true,
            "schema": {"type": "string"},
            "example": "gnpslibrary"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {"type": "integer", "minimum": 0},
            "example": 2609
          }
        ],
        "responses": {
          "200": {
            "description": "Spectrum.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/StoredSpectrum"},
                "example": {
                  "spectrum_id": 2609,
                  "filename": "GNPS-LIBRARY.mgf",
                  "scan": 1,
                  "charge": 1,
                  "precursor_mz": 981.54,
                  "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547",
                  "peaks": [[539.2178, 0.47], [599.3528, 1.0], [953.3966, 0.84]],
                  "metadata": {
                    "GNPSLibraryAccession": "CCMSLIB00000001547",
                    "CompoundName": "3-Des-Microcystein_LR",
                    "Adduct": "M+H"
                  }
                }
              }
            }
          },
          "400": {"description": "`id` is not an integer."},
          "404": {
            "description": "Unknown library or spectrum.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Error"},
                "example": {"error": "library 'nope' not found"}
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/export": {
      "post": {
        "tags": ["export"],
        "operationId": "v2ExportSubmit",
        "summary": "Bulk export to disk (whitelisted clients)",
        "description": "**Collaborators only** (class `whitelisted`; `403` `not_whitelisted` otherwise; see `GET /api/v2/limits`). Writes all the rows of a search, a MassQL query or a batch to disk as `.jsonl.zst` parts (or, with `\"format\": \"parquet\"`, `.parquet` parts) of `--export-part-rows` (1,000,000) rows, at most `--export-max-rows` (100,000,000) rows, and returns `202` with the job URLs. Poll `status_url` (`export`: `phase` queued/searching/sorting/writing/done, `rows`, `found`, `parts`); when `COMPLETED`, `result_url` lists the parts and each downloads from `/api/v2/jobs/{id}/files/{name}` (Range supported; anyone holding the job id can download). Files are deleted 1 hour (`--export-ttl-secs`) after the job finishes; `DELETE /api/v2/jobs/{id}` cancels or deletes earlier.\n\nBody: `kind` plus the fields of the matching endpoint:\n- `search`: a `POST /api/v2/search` body (exact or analog; `top_k` caps the rows; no `peak_histogram`). Rows are the v2 `results` records, best score first; every hit is sorted on disk, so there is no 1M hit cap.\n- `massql`: a `POST /api/v2/massql` body. Rows are the MassQL rows in spectrum-id order; `max_matches` optional.\n- `batch`: a JSON `POST /api/v2/batch` body. One row per hit (the query's `query_index`, `query_id`, `query_scan`, `query_charge`, `query_precursor_mz`, then the batch JSONL's hit fields), queries in order, up to `--export-batch-max-hits` (100,000) hits per query.\n- `massql_batch`: `library`, `queries` (array of MassQL strings, at most `--massql-batch-max-queries`, 1,000), `filters` (every query), `max_matches_per_query` (optional). Every match of every query from ONE pass over the index (one export slot for the batch). Rows are the MassQL rows with `query_index` (0-based) as the first field, shard by shard and within a shard by query (not grouped by query); per query exactly the rows of a `massql` export of it. Every query is checked first: any bad one is a `422` `invalid_queries` with `errors` = `[{index, error}]`, and nothing runs. Status: `export.queries` (`total`, `done`, `failed`, `max_matches_per_query`), `export.per_query` (`[{index, matches, truncated}]`, once finished), `export.truncated_query` when `--export-max-rows` cut the rows. Fails after `--export-massql-batch-timeout-secs` (4 h), keeping the closed parts.\n\n`format`: `jsonl` (default; `part-NNNNN.jsonl.zst`, zstd-compressed JSON lines) or `parquet` (`part-NNNNN.parquet`, each a complete Parquet file, zstd, 262,144-row row groups, written straight from the rows): the same rows, typed columns. search: one column per `results` key (same names and order; numbers Float64 / Int32 / UInt32 / Int64 / UInt64, `Dataset`, `Status` and metadata columns dictionary strings). batch: the columns of `GET /api/v2/batch/{id}/result?format=parquet` (`query_index` first; the JSONL `metadata` object flattened into one nullable string column per library metadata column). massql: the columns of the MassQL job Parquet (`matched` stays its JSON array text); massql_batch: `query_index` (UInt32) first, then the massql columns. Anything else is `422`. Listing, sha256, Range, retention and quota are the same for both.\n\nAt most `--export-workers` (2) exports run at once; the rest wait. `503` `export_quota` (Retry-After 60) when the export disk quota (`--export-quota`, 200 GB) is used up; an export that runs past it fails. Rate limit: the submission rate (as `POST /api/v2/batch`).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"type": "object", "required": ["kind"], "properties": {"kind": {"type": "string", "enum": ["search", "massql", "batch", "massql_batch"]}, "queries": {"type": "array", "items": {"type": "string"}, "description": "`massql_batch`: the MassQL queries (1 to `--massql-batch-max-queries`)."}, "max_matches_per_query": {"type": "integer", "minimum": 1, "description": "`massql_batch`: rows kept per query (default: no cap; the export row cap still applies)."}, "metadata_columns": {"type": "array", "items": {"type": "string", "minLength": 1}, "maxItems": 64, "description": "`massql` / `massql_batch`: per-spectrum metadata columns for every row, after the library's `result_metadata_columns` label (as in `POST /api/v2/massql`)."}, "format": {"type": "string", "enum": ["jsonl", "parquet"], "default": "jsonl", "description": "Part files: `jsonl` (`part-NNNNN.jsonl.zst`) or `parquet` (`part-NNNNN.parquet`, one complete Parquet file per part)."}}},
              "examples": {
                "analog": {"summary": "Every analog hit of one spectrum", "value": {"kind": "search", "library": "metabolomicspanrepo_index", "usi": "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00005435737", "analog": true, "cosine_threshold": 0.7}},
                "massql": {"summary": "Every scan with a fragment", "value": {"kind": "massql", "library": "metabolomicspanrepo_index", "query": "QUERY scaninfo(MS2DATA) WHERE MS2PROD=137.0597:TOLERANCEMZ=0.01"}},
                "parquet": {"summary": "Every scan with a fragment, as Parquet parts", "value": {"kind": "massql", "format": "parquet", "library": "metabolomicspanrepo_index", "query": "QUERY scaninfo(MS2DATA) WHERE MS2PROD=137.0597:TOLERANCEMZ=0.01"}},
                "massql_batch": {"summary": "Every match of several MassQL queries, in one pass", "value": {"kind": "massql_batch", "library": "metabolomicspanrepo_index", "queries": ["QUERY scaninfo(MS2DATA) WHERE MS2PROD=86.0964:TOLERANCEMZ=0.01", "QUERY scaninfo(MS2DATA) WHERE MS2PREC=443.2181:TOLERANCEMZ=0.01"]}}
              }
            }
          }
        },
        "responses": {
          "202": {"description": "Accepted; poll `status_url`, then read `result_url` (the parts).", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/JobAccepted"}}}},
          "403": {"description": "Not a whitelisted client.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "404": {"$ref": "#/components/responses/LibraryNotFound"},
          "413": {"description": "More query spectra than --max-batch-spectra, or (massql_batch) more queries than --massql-batch-max-queries (`too_many_queries`).", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "422": {"description": "Unknown kind or format, or an invalid body for the kind (massql_batch: `invalid_queries`, `errors` = `[{index, error}]` for every bad query).", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "501": {"description": "Exports are not enabled (--export-dir).", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "503": {"$ref": "#/components/responses/QueueFull"},
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/limits": {
      "get": {
        "tags": ["v2"],
        "operationId": "v2Limits",
        "summary": "What is available to whom: your client class and every feature's limits per class",
        "description": "`you`: your class (`anonymous`, labelled `public`, or `whitelisted`, labelled `collaborator`) as this server sees it, the address it counts your requests under, and your limits. `classes`: the same for both classes. Numbers come from the running configuration; `null` means no per-client limit (the server-wide worker pools, queue and result-memory budget still apply). Per-IP request rates are documented in docs/api.md \"Rate limits\". `whitelist` says who is whitelisted and how to ask. Feature keys: `search`, `batch`, `massql_job`, `massql_stream`, `compat_search`; ignore unknown keys. `search.max_hits`: hits a search keeps, all listed by `format: jsonl`; `search.max_hits_json`: hits a JSON response lists (the smaller of `max_hits` and `--max-hits-json`).",
        "responses": {
          "200": {
            "description": "Your class and the limits of both classes.",
            "content": {"application/json": {"schema": {"type": "object"}, "example": {"you": {"class": "anonymous", "label": "public", "address": "203.0.113.5", "features": {"search": {"endpoint": "POST /api/v2/search", "available": true, "exact_in_flight": 8, "analog_in_flight": 2, "max_analog_delta_da": 200.0, "max_pm_tolerance_da": 0.5, "max_hits": 1000000, "max_hits_json": 100000, "formats": ["json", "jsonl"]}, "massql_stream": {"endpoint": "POST|GET /api/v2/massql/stream", "available": true, "max_matches": null, "timeout_secs": 3600, "stall_secs": 120, "bulk_in_flight": 1}}}, "classes": {"anonymous": {"features": {}}, "whitelisted": {"features": {}}}, "whitelist": "Collaborators (class whitelisted): send the Wang lab the you.address shown here for the machine that will send the requests ...", "server": {"max_queue": 1000, "result_memory_budget_bytes": 34359738368, "result_ttl_secs": 600, "batch_result_ttl_secs": 3600}, "docs": "/docs"}}}
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    },
    "/api/v2/stats": {
      "get": {
        "tags": ["v2"],
        "operationId": "v2Stats",
        "summary": "Server statistics",
        "description": "Jobs, stored results, workers, the web-UI lane, the IO mode / block cache / IO totals, the process's CPU time, memory and disk IO, and engine search counts (what `fasst loadtest` reads). Sections may be added: ignore unknown keys.",
        "responses": {
          "200": {
            "description": "Stats.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/Stats"},
                "example": {
                  "jobs": {
                    "queued": 0,
                    "running": 0,
                    "stored": 0,
                    "by_state": {},
                    "active": {
                      "search": {"pending": 0, "running": 0},
                      "batch": {"pending": 0, "running": 0},
                      "massql": {"pending": 0, "running": 0},
                      "export": {"pending": 0, "running": 0}
                    },
                    "massql_streams": {"waiting": 0, "running": 0}
                  },
                  "exports": {"enabled": true, "running": 0, "workers": 2, "disk_used_bytes": 0, "disk_quota_bytes": 214748364800},
                  "results": {
                    "bytes": 0,
                    "max_bytes": 2147483648,
                    "max_result_size": 268435456,
                    "evicted_total": 0,
                    "result_ttl_seconds": 600,
                    "batch_result_ttl_seconds": 3600
                  },
                  "workers": {
                    "search": 32,
                    "batch": 16,
                    "analog": 24,
                    "search_available": 32,
                    "analog_available": 24,
                    "batch_available": 16,
                    "sync_budget_seconds": 10.0
                  },
                  "ui": {"workers": 4, "available": 4, "in_flight": 0, "waiting": 0},
                  "build": {
                    "version": "1.6.2",
                    "git_sha": "abc1234",
                    "build_time": "2026-09-28T18:40:12Z",
                    "display": "fasst 1.6.2 · abc1234 · built 2026-09-28 18:40 UTC"
                  },
                  "generation": 1,
                  "libraries": 2,
                  "io": null,
                  "process": {
                    "pid": 1,
                    "uptime_seconds": 3600.5,
                    "cpu_user_seconds": 812.4,
                    "cpu_system_seconds": 35.1,
                    "cpu_seconds": 847.5,
                    "available_cpus": 32,
                    "threads": 71,
                    "rss_bytes": 9126805504,
                    "max_rss_bytes": 9663676416,
                    "major_faults": 0,
                    "voluntary_context_switches": 1204331,
                    "involuntary_context_switches": 20411,
                    "disk": {"rchar": 70368744177, "wchar": 1048576, "syscr": 812345, "syscw": 120, "read_bytes": 68719476736, "write_bytes": 0, "cancelled_write_bytes": 0},
                    "cgroup": {
                      "usage_seconds": 850.2,
                      "user_seconds": 814.0,
                      "system_seconds": 36.2,
                      "nr_periods": 36000,
                      "nr_throttled": 0,
                      "throttled_seconds": 0.0,
                      "limit_cpus": 32.0
                    }
                  },
                  "searches": {
                    "started": 120433,
                    "finished": 120431,
                    "in_flight": 2,
                    "wall_seconds": 790.2,
                    "thread_cpu_seconds": 701.9,
                    "by_library": [
                      {"library": "gnpslibrary", "mode": "exact", "lane": "v2", "searches": 118000, "failed": 12, "wall_seconds": 590.0, "thread_cpu_seconds": 560.1},
                      {"library": "metabolomicspanrepo_index", "mode": "analog", "lane": "ui", "searches": 2431, "failed": 3, "wall_seconds": 200.2, "thread_cpu_seconds": 141.8}
                    ],
                    "log": {"dir": "/srv/fasst/stats", "interval_seconds": 600, "last_write_unix": 1794218400, "lines_written": 312, "last_error": null}
                  }
                }
              }
            }
          },
          "429": {"$ref": "#/components/responses/RateLimited"}
        }
      }
    }
  },
  "components": {
    "schemas": {
      "FastQuery": {
        "type": "object",
        "required": ["library"],
        "description": "Production `FastQuery` search parameters (compat API). Either `usi` or `query_spectrum` is required.",
        "properties": {
          "library": {
            "type": "string",
            "description": "A library name from `GET /libraries`.",
            "examples": ["gnpslibrary"]
          },
          "usi": {
            "type": "string",
            "description": "Query spectrum as a Universal Spectrum Identifier, resolved via metabolomics-usi.gnps2.org.",
            "examples": ["mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547"]
          },
          "query_spectrum": {
            "type": "string",
            "description": "The query spectrum as a JSON **string** `{\"peaks\": [[mz, intensity], ...], \"precursor_mz\": x, \"precursor_charge\": z}`; wins over `usi` when it parses (production silently falls back to `usi` otherwise)."
          },
          "lower_delta": {
            "type": "number",
            "default": 130,
            "description": "Analog window below the query precursor (Da, truncated to an integer)."
          },
          "upper_delta": {
            "type": "number",
            "default": 200,
            "description": "Analog window above the query precursor (Da, truncated to an integer)."
          },
          "pm_tolerance": {
            "type": "number",
            "default": 0.05,
            "description": "Precursor m/z tolerance (Da): the exact-search window, and the non-analog `results` filter."
          },
          "fragment_tolerance": {"type": "number", "default": 0.05, "description": "Fragment m/z tolerance (Da)."},
          "cosine_threshold": {"type": "number", "default": 0.7, "description": "Minimum cosine."},
          "cache": {"type": "string", "default": "Yes", "description": "Accepted for compatibility and ignored."},
          "analog": {
            "type": "string",
            "enum": ["Yes", "No"],
            "default": "No",
            "description": "Analog search: window `[q - lower_delta, q + upper_delta]`."
          }
        }
      },
      "QuerySpectrum": {
        "type": "object",
        "required": ["peaks", "precursor_mz"],
        "description": "A query spectrum. A missing or zero `precursor_charge` is treated as 1.",
        "properties": {
          "peaks": {
            "type": "array",
            "description": "`[m/z, intensity]` pairs.",
            "items": {
              "type": "array",
              "prefixItems": [
                {"type": "number"},
                {"type": "number"}
              ],
              "minItems": 2,
              "maxItems": 2
            }
          },
          "precursor_mz": {"type": "number"},
          "precursor_charge": {"type": "integer", "default": 1}
        }
      },
      "MetaFilter": {
        "type": "object",
        "additionalProperties": false,
        "description": "Query-time metadata filters, evaluated against the index's per-spectrum metadata store (`fasst_meta::MetaFilter`). `{}` is accepted. Unknown keys or invalid values → `422`; an index built without a metadata store → `400`.",
        "properties": {
          "polarity": {"type": "string", "enum": ["positive", "negative"]},
          "files": {
            "type": "array",
            "items": {"type": "string"},
            "description": "Stored file names (exact) to keep."
          },
          "datasets": {
            "type": "array",
            "items": {"type": "string"},
            "description": "Dataset accessions to keep, e.g. `MSV000086206`."
          },
          "rt_min": {"type": "number", "description": "Retention time lower bound (s); spectra without RT never match."},
          "rt_max": {"type": "number", "description": "Retention time upper bound (s)."},
          "charges": {
            "type": "array",
            "items": {"type": "integer"},
            "description": "Allowed stored precursor charges (0 = unknown)."
          },
          "ms_level": {"type": "integer"},
          "has_annotation": {"type": "boolean", "description": "`true`: at least one annotation column present; `false`: none."},
          "has": {
            "type": "array",
            "items": {"type": "string"},
            "description": "Annotation columns that must be present."
          },
          "equals": {
            "type": "object",
            "additionalProperties": {"type": "string"},
            "description": "Column equality, e.g. `{\"ADDUCT\": \"M+H\"}` or a layer column `{\"buddy.formula\": \"C6H12O6\"}`."
          },
          "contains": {
            "type": "object",
            "additionalProperties": {"type": "string"},
            "description": "Case-sensitive substring conditions."
          },
          "ranges": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "prefixItems": [
                {"type": ["number", "null"]},
                {"type": ["number", "null"]}
              ],
              "minItems": 2,
              "maxItems": 2
            },
            "description": "Numeric `[min, max]` ranges (either may be null)."
          },
          "m1_ratio_min": {"type": "number"},
          "m1_ratio_max": {"type": "number"},
          "m2_ratio_min": {"type": "number"},
          "m2_ratio_max": {"type": "number"},
          "purity_min": {"type": "number", "description": "Minimum precursor purity in [0, 1]."},
          "exclude_m_minus1": {"type": "boolean", "description": "Drop spectra whose precursor may be an isotope peak."}
        }
      },
      "V2SearchRequest": {
        "type": "object",
        "required": ["library"],
        "description": "v2 search: the compat parameters plus v2 options. One of `spectrum`, `query_spectrum` or `usi` is required.",
        "properties": {
          "library": {
            "type": "string",
            "description": "A library name from `GET /libraries`.",
            "examples": ["gnpslibrary"]
          },
          "usi": {
            "type": "string",
            "description": "Query spectrum as a Universal Spectrum Identifier, resolved via metabolomics-usi.gnps2.org.",
            "examples": ["mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000001547"]
          },
          "query_spectrum": {
            "type": "string",
            "description": "The query spectrum as a JSON **string** `{\"peaks\": [[mz, intensity], ...], \"precursor_mz\": x, \"precursor_charge\": z}`; wins over `usi` when it parses (production silently falls back to `usi` otherwise)."
          },
          "lower_delta": {
            "type": "number",
            "default": 100,
            "description": "Analog window below the query precursor (Da, truncated to an integer). v2 default 100 (the compat API keeps production's 130)."
          },
          "upper_delta": {
            "type": "number",
            "default": 100,
            "description": "Analog window above the query precursor (Da, truncated to an integer). v2 default 100 (the compat API keeps production's 200)."
          },
          "pm_tolerance": {
            "type": "number",
            "default": 0.05,
            "description": "Precursor m/z tolerance (Da): the exact-search window, and the non-analog `results` filter."
          },
          "fragment_tolerance": {"type": "number", "default": 0.05, "description": "Fragment m/z tolerance (Da)."},
          "cosine_threshold": {"type": "number", "default": 0.7, "description": "Minimum cosine."},
          "cache": {"type": "string", "default": "Yes", "description": "Accepted for compatibility and ignored."},
          "analog": {
            "oneOf": [
              {"type": "boolean"},
              {"type": "string", "enum": ["Yes", "No"]}
            ],
            "default": false,
            "description": "Analog search (`true`/`false`, or production's `\"Yes\"`/`\"No\"`)."
          },
          "spectrum": {
            "$ref": "#/components/schemas/QuerySpectrum",
            "description": "Query spectrum as a JSON object; wins over `usi` / `query_spectrum`."
          },
          "min_matched_peaks": {"type": "integer", "minimum": 0, "description": "Minimum matched peaks per hit. Default 4 for every search; analog searches use at least 3 (smaller values are raised to 3). 0 (exact only) turns the minimum off."},
          "score": {
            "type": "string",
            "enum": ["cosine", "entropy", "reverse_cosine"],
            "default": "cosine",
            "description": "Similarity score (engine-ls libraries; engine-ref libraries accept only `cosine`, others answer 422). `cosine`: GNPS cosine, modified cosine for analog searches. `entropy`: spectral entropy similarity (Li et al. 2021) on the stored peaks. `reverse_cosine`: cosine with the unmatched peaks of the `reverse` side ignored. `cosine_threshold` is the minimum of this score, and the result's score column is named after it (`Entropy`, `Reverse Cosine`; batch: `entropy`, `reverse_cosine`). See docs/api.md, Score modes."
          },
          "reverse": {
            "type": "string",
            "enum": ["index", "query"],
            "default": "index",
            "description": "`score: reverse_cosine` only: the side whose peaks without a match are ignored. `index`: the indexed spectrum (e.g. a library spectrum as query against repository spectra with co-isolated peaks); `query`: the query (a mixture query against a library)."
          },
          "top_k": {"type": "integer", "minimum": 1, "description": "Keep only the best k hits."},
          "filters": {"$ref": "#/components/schemas/MetaFilter"},
          "metadata_columns": {
            "type": "array",
            "items": {"type": "string"},
            "description": "Extra metadata fields per result row, e.g. `[\"rt_seconds\", \"native_id\"]`, or `[\"*\"]` for all, in addition to the library's configured columns."
          },
          "async": {
            "type": "boolean",
            "default": false,
            "description": "Skip the synchronous wait and answer `202` with a job immediately."
          },
          "format": {
            "type": "string",
            "enum": ["json", "jsonl"],
            "default": "json",
            "description": "`jsonl`: answer with the `results` records one per line (same records and order as the JSON), then `{\"end\": {\"complete\", \"results\", \"kept_hits\", \"total_results\", \"truncated\", \"truncated_reason\", \"seconds\"}}` (`application/x-ndjson`). Both formats are streamed; a v2 result has no size cap, only hit caps: JSONL lists every kept hit (the client's hit cap, 1 000 000 for every client), JSON the best `--max-hits-json` (default 100 000) of them, flagged `truncated_reason: max_hits_json` with the exact `total_results`. `GET /api/v2/limits` → `features.search.max_hits` / `max_hits_json`."
          },
          "peak_histogram": {
            "oneOf": [
              {"type": "boolean"},
              {"$ref": "#/components/schemas/PeakHistogramParams"}
            ],
            "description": "Also histogram the stored MS/MS peaks of every **kept** hit (all hits `results` would list, up to the client's hit cap: 1 000 000 for every client, effectively all): fragment m/z and, by default, neutral loss. `true` = defaults; `false`/absent = off. Adds `peak_histogram` to the result. Not available in batches (422). See docs/api.md, Peak histogram."
          }
        }
      },
      "PeakHistogramParams": {
        "type": "object",
        "additionalProperties": false,
        "description": "Bins `[min_mz + k*bin_width, min_mz + (k+1)*bin_width)`; at most 1,000,000 bins (`(max_mz - min_mz) / bin_width`); out-of-range values answer 422.",
        "properties": {
          "bin_width": {"type": "number", "minimum": 0.001, "maximum": 10, "default": 0.01, "description": "Bin width (Da)."},
          "min_mz": {"type": "number", "minimum": 0, "default": 0, "description": "Lower edge of the first bin (Da); applies to fragments and losses."},
          "max_mz": {"type": "number", "default": 2500, "description": "Upper edge (Da, exclusive); greater than `min_mz`."},
          "neutral_loss": {"type": "boolean", "default": true, "description": "Also histogram neutral losses: `M - fragment` with `M = (precursor_mz - 1.007276)*z + 1.007276` (z <= 1 or unknown: `precursor_mz - fragment`; fragments assumed 1+). Negative losses are skipped."},
          "min_count": {"type": "integer", "minimum": 1, "default": 1, "description": "Omit bins with fewer hit spectra."}
        }
      },
      "PeakHistogramBin": {
        "type": "array",
        "description": "`[mz, count, intensity_sum]`: bin start (Da), hit spectra with at least one peak in the bin (each spectrum counts once per bin), summed relative intensity (stored intensity squared: each peak's fraction of its spectrum's stored intensity, so a hit adds at most 1 over all bins).",
        "prefixItems": [{"type": "number"}, {"type": "integer"}, {"type": "number"}],
        "minItems": 3,
        "maxItems": 3
      },
      "PeakHistogram": {
        "type": "object",
        "required": ["bin_width", "min_mz", "max_mz", "hits", "fragment"],
        "properties": {
          "bin_width": {"type": "number"},
          "min_mz": {"type": "number"},
          "max_mz": {"type": "number"},
          "min_count": {"type": "integer"},
          "hits": {"type": "integer", "description": "Hit spectra histogrammed (every hit `results` would list, also when `results` was truncated)."},
          "peaks": {"type": "integer", "description": "Stored peaks of those spectra."},
          "columns": {"type": "array", "items": {"type": "string"}, "description": "`[\"mz\", \"count\", \"intensity_sum\"]`"},
          "fragment": {"type": "array", "items": {"$ref": "#/components/schemas/PeakHistogramBin"}, "description": "Non-empty fragment m/z bins, ascending."},
          "neutral_loss": {"type": "array", "items": {"$ref": "#/components/schemas/PeakHistogramBin"}, "description": "Non-empty neutral-loss bins, ascending (with `neutral_loss: true`)."},
          "seconds": {"type": "number", "description": "Time of the histogram pass."}
        }
      },
      "ResultRow": {
        "type": "object",
        "additionalProperties": true,
        "description": "One hit, production column names. Libraries add their metadata columns (e.g. `GNPSLibraryAccession`, `CompoundName`, `Adduct`); `metadata_columns` adds more.",
        "properties": {
          "Delta Mass": {"type": "number", "description": "Query precursor m/z − hit precursor m/z."},
          "USI": {"type": "string"},
          "Charge": {"type": "integer"},
          "Cosine": {"type": "number", "description": "The score; named `Entropy` or `Reverse Cosine` instead for those `score` modes (v2)."},
          "Entropy": {"type": "number", "description": "`score: entropy` (v2): entropy similarity, in place of `Cosine`."},
          "Reverse Cosine": {"type": "number", "description": "`score: reverse_cosine` (v2): reverse cosine, in place of `Cosine`."},
          "Matching Peaks": {"type": "integer"},
          "Query Matched Intensity": {"type": "number", "description": "`score: reverse_cosine` (v2): fraction of the query's intensity on matched peaks."},
          "Library Matched Intensity": {"type": "number", "description": "`score: reverse_cosine` (v2): fraction of the library spectrum's intensity on matched peaks."},
          "Unit Delta Mass": {"type": "integer"},
          "Dataset": {"type": "string"},
          "Status": {"type": "string", "description": "`HasID` when the hit has a library annotation, else `NoID`."},
          "GNPSLibraryAccession": {"type": "string"},
          "CompoundName": {"type": "string"},
          "Adduct": {"type": "string"},
          "Query Scan": {"type": "integer"},
          "Index UnitPM": {"type": "integer"},
          "Index IdxInUnitPM": {"type": "integer"}
        }
      },
      "SearchResult": {
        "type": "object",
        "required": ["results"],
        "description": "The production result JSON.",
        "properties": {
          "results": {
            "type": "array",
            "items": {"$ref": "#/components/schemas/ResultRow"},
            "description": "Hits; non-analog searches keep hits within `pm_tolerance`."
          },
          "timing": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "desc": {"type": "string"},
                "timing": {"type": "number", "description": "seconds"}
              }
            }
          },
          "grouped_by_unit_delta_mass": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "properties": {
                "Frequency": {"type": "integer"}
              },
              "required": ["Frequency"]
            },
            "description": "`{Frequency, Unit Delta Mass}` rows."
          },
          "grouped_by_dataset": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "properties": {
                "Frequency": {"type": "integer"}
              },
              "required": ["Frequency"]
            },
            "description": "`{Frequency, Dataset}` rows."
          },
          "grouped_by_dataset_unit_delta": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "properties": {
                "Frequency": {"type": "integer"}
              },
              "required": ["Frequency"]
            },
            "description": "`{Frequency, Dataset, Unit Delta Mass}` rows."
          },
          "metadata_groupings": {
            "type": "array",
            "description": "Per metadata column: `[column, [{Frequency, <column>, Best Cosine, Best Delta Mass, Best USI, Best Charge}, ...]]`.",
            "items": {
              "type": "array",
              "prefixItems": [
                {"type": "string"},
                {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": true,
                    "properties": {
                      "Frequency": {"type": "integer"}
                    },
                    "required": ["Frequency"]
                  }
                }
              ],
              "minItems": 2,
              "maxItems": 2
            }
          },
          "log": {"type": "string"},
          "temp_json_path": {"type": "string"},
          "truncated": {
            "type": "boolean",
            "description": "Present (true) only when the result was cut to its best rows (hit cap; compat API and web UI also the per-result size limit)."
          },
          "total_results": {"type": "integer", "description": "Hits found (exact; only with `truncated`)."},
          "truncated_reason": {"type": "string", "enum": ["memory_budget", "max_hits_json"], "description": "v2: `max_hits_json` when the JSON response lists only the best `--max-hits-json` (default 100 000) of the kept hits (`format: jsonl` lists every kept hit, up to the client's cap); otherwise `memory_budget` when the server's result-memory budget (`--result-memory-budget`) kept fewer hits than the client's cap. Absent when the client's cap alone cut the result."},
          "truncated_hint": {"type": "string", "description": "v2, with `truncated_reason: max_hits_json`: how to get more hits (`\"format\": \"jsonl\"` or `?format=jsonl` on the job result, a collaborator bulk export)."}
        }
      },
      "V2SearchResult": {
        "allOf": [
          {"$ref": "#/components/schemas/SearchResult"},
          {
            "type": "object",
            "properties": {
              "library": {"type": "string"},
              "engine": {"type": "string", "enum": ["ls", "ref"]},
              "took_ms": {"type": "number"},
              "generation": {"type": "integer", "description": "Library registry generation (bumped by reloads)."},
              "score": {"type": "string", "enum": ["entropy", "reverse_cosine"], "description": "Present when the search used a score other than cosine; names the result's score column."},
              "peak_histogram": {"$ref": "#/components/schemas/PeakHistogram", "description": "With the `peak_histogram` request option."}
            }
          }
        ]
      },
      "CompatSubmitted": {
        "type": "object",
        "required": ["id", "status"],
        "properties": {
          "id": {"type": "string", "format": "uuid"},
          "result_task": {"type": "string"},
          "status": {"type": "string", "const": "PENDING"}
        }
      },
      "CompatStatus": {
        "type": "object",
        "required": ["status"],
        "properties": {
          "status": {"type": "string", "enum": ["PENDING", "RUNNING", "COMPLETED", "FAILURE", "NOT_FOUND"]},
          "message": {"type": "string"},
          "error": {"type": "string"}
        }
      },
      "BatchProgress": {
        "type": "object",
        "required": ["total", "completed"],
        "properties": {
          "total": {"type": "integer"},
          "completed": {"type": "integer"},
          "failed": {"type": "integer"},
          "hits": {"type": "integer"},
          "truncated": {"type": "boolean"}
        }
      },
      "JobAccepted": {
        "type": "object",
        "required": ["id", "kind", "status", "status_url", "result_url"],
        "properties": {
          "id": {"type": "string", "format": "uuid"},
          "kind": {"type": "string", "enum": ["search", "batch", "massql"]},
          "status": {"type": "string", "enum": ["PENDING", "RUNNING"]},
          "status_url": {"type": "string"},
          "result_url": {"type": "string"},
          "total": {"type": "integer", "description": "Batch only: number of query spectra."},
          "library": {"type": "string", "description": "Batch and MassQL."},
          "query": {"type": "string", "description": "MassQL only."},
          "max_matches": {"type": "integer", "description": "MassQL only: the effective match limit."}
        }
      },
      "JobStatus": {
        "type": "object",
        "required": ["id", "kind", "status"],
        "properties": {
          "id": {"type": "string", "format": "uuid"},
          "kind": {"type": "string", "enum": ["search", "batch", "massql", "export"]},
          "status": {"type": "string", "enum": ["PENDING", "RUNNING", "COMPLETED", "FAILED", "CANCELLED", "EXPIRED"], "description": "`CANCELLED`: MassQL jobs and exports stopped by `DELETE`."},
          "export": {"type": "object", "description": "Export jobs: `kind`, `format` (`jsonl` / `parquet`), `library`, `phase`, `rows`, `found`, `max_rows`, `truncated`, `parts` (closed so far), `disk_bytes`, `ttl_secs`, `expires_in_secs` (once finished), batch `queries`, MassQL `shards`."},
          "final": {"type": "boolean", "description": "Export parts listing (`/api/v2/jobs/{id}/files`) only: `true` on a failed or cancelled export."},
          "age_seconds": {"type": "number"},
          "result_bytes": {"type": "integer"},
          "status_url": {"type": "string"},
          "result_url": {"type": "string"},
          "error": {"type": "string", "description": "FAILED (MassQL: also a run that timed out, `progress.stop_reason` `timeout`) and cancelled MassQL jobs; a MassQL job keeps the rows found before it stopped."},
          "library": {"type": "string", "description": "Batch and MassQL."},
          "query": {"type": "string", "description": "MassQL only."},
          "max_matches": {"type": "integer", "description": "MassQL only."},
          "progress": {
            "description": "Batch: `BatchProgress`; MassQL: `MassqlProgress`.",
            "oneOf": [{"$ref": "#/components/schemas/BatchProgress"}, {"$ref": "#/components/schemas/MassqlProgress"}]
          }
        }
      },
      "ExportFiles": {
        "type": "object",
        "required": ["id", "status", "final", "parts", "rows", "found", "truncated"],
        "properties": {
          "id": {"type": "string", "format": "uuid"},
          "status": {"type": "string", "enum": ["PENDING", "RUNNING", "COMPLETED"]},
          "final": {"type": "boolean", "description": "`true`: the export is `COMPLETED` and `parts` is complete. `false`: it is still running; more parts may follow and `rows` / `found` are so far."},
          "format": {"type": "string", "enum": ["jsonl", "parquet"], "description": "The parts' file format (the request's `format`)."},
          "parts": {
            "type": "array",
            "description": "Closed parts in order (`part-00000.jsonl.zst`, `part-00001.jsonl.zst`, ..., or `part-00000.parquet`, ... for a Parquet export). Each is a complete file with its final `bytes`, `rows` and `sha256`, and never changes once listed; the part being written is not listed.",
            "items": {
              "type": "object",
              "required": ["name", "rows", "bytes", "sha256", "url"],
              "properties": {
                "name": {"type": "string"},
                "rows": {"type": "integer"},
                "bytes": {"type": "integer"},
                "sha256": {"type": "string", "description": "Of the compressed file (also its download `ETag`)."},
                "url": {"type": "string"}
              }
            }
          },
          "rows": {"type": "integer", "description": "Rows written (while running: including the part being written, so at least the listed parts' sum)."},
          "found": {"type": "integer"},
          "truncated": {"type": "boolean"},
          "expires_in_secs": {"type": ["integer", "null"], "description": "Seconds until the files are deleted (null while running)."}
        }
      },
      "NotFoundJob": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "status": {"type": "string", "const": "NOT_FOUND"},
          "error": {"type": "string"}
        }
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {"type": "string"}
        }
      },
      "Detail": {
        "type": "object",
        "required": ["detail"],
        "properties": {
          "detail": {"type": "string"}
        }
      },
      "RateLimited": {
        "type": "object",
        "properties": {
          "detail": {"type": "string"},
          "error": {"type": "string"},
          "code": {"type": "string", "enum": ["rate_limited", "busy", "queue_full"], "description": "`rate_limited`: the per-IP request-rate limit; `busy`: fasst's per-client in-flight cap (clients that are not whitelisted); `queue_full`: fasst's global queue (503)."},
          "retry_after": {"type": "integer"},
          "limit": {"type": "integer", "description": "`busy`: the in-flight cap that was hit."},
          "kind": {"type": "string", "enum": ["exact", "analog", "bulk"], "description": "`busy`: which cap (bulk = batch + MassQL jobs)."}
        }
      },
      "BatchSpectrum": {
        "oneOf": [
          {"type": "string", "description": "A USI (also the query id)."},
          {
            "type": "object",
            "required": ["usi"],
            "properties": {
              "id": {"type": ["string", "integer"]},
              "usi": {"type": "string"}
            }
          },
          {
            "type": "object",
            "required": ["peaks", "precursor_mz"],
            "properties": {
              "id": {"type": ["string", "integer"]},
              "peaks": {
                "type": "array",
                "items": {
                  "type": "array",
                  "prefixItems": [
                    {"type": "number"},
                    {"type": "number"}
                  ],
                  "minItems": 2,
                  "maxItems": 2
                }
              },
              "precursor_mz": {"type": "number"},
              "precursor_charge": {"type": "integer"}
            }
          }
        ]
      },
      "BatchRequest": {
        "type": "object",
        "required": ["library", "spectra"],
        "description": "JSON batch: search parameters shared by all queries plus the query spectra.",
        "properties": {
          "library": {
            "type": "string",
            "description": "A library name from `GET /libraries`.",
            "examples": ["gnpslibrary"]
          },
          "lower_delta": {
            "type": "number",
            "default": 100,
            "description": "Analog window below the query precursor (Da, truncated to an integer). v2 default 100 (the compat API keeps production's 130)."
          },
          "upper_delta": {
            "type": "number",
            "default": 100,
            "description": "Analog window above the query precursor (Da, truncated to an integer). v2 default 100 (the compat API keeps production's 200)."
          },
          "pm_tolerance": {
            "type": "number",
            "default": 0.05,
            "description": "Precursor m/z tolerance (Da): the exact-search window, and the non-analog `results` filter."
          },
          "fragment_tolerance": {"type": "number", "default": 0.05, "description": "Fragment m/z tolerance (Da)."},
          "cosine_threshold": {"type": "number", "default": 0.7, "description": "Minimum cosine."},
          "cache": {"type": "string", "default": "Yes", "description": "Accepted for compatibility and ignored."},
          "analog": {
            "oneOf": [
              {"type": "boolean"},
              {"type": "string", "enum": ["Yes", "No"]}
            ],
            "default": false,
            "description": "Analog search (`true`/`false`, or production's `\"Yes\"`/`\"No\"`)."
          },
          "min_matched_peaks": {"type": "integer", "minimum": 0, "description": "Minimum matched peaks per hit. Default 4 for every search; analog searches use at least 3 (smaller values are raised to 3). 0 (exact only) turns the minimum off."},
          "score": {
            "type": "string",
            "enum": ["cosine", "entropy", "reverse_cosine"],
            "default": "cosine",
            "description": "Similarity score (engine-ls libraries; engine-ref libraries accept only `cosine`, others answer 422). `cosine`: GNPS cosine, modified cosine for analog searches. `entropy`: spectral entropy similarity (Li et al. 2021) on the stored peaks. `reverse_cosine`: cosine with the unmatched peaks of the `reverse` side ignored. `cosine_threshold` is the minimum of this score, and the result's score column is named after it (`Entropy`, `Reverse Cosine`; batch: `entropy`, `reverse_cosine`). See docs/api.md, Score modes."
          },
          "reverse": {
            "type": "string",
            "enum": ["index", "query"],
            "default": "index",
            "description": "`score: reverse_cosine` only: the side whose peaks without a match are ignored. `index`: the indexed spectrum (e.g. a library spectrum as query against repository spectra with co-isolated peaks); `query`: the query (a mixture query against a library)."
          },
          "top_k": {"type": "integer", "minimum": 1, "description": "Keep only the best k hits."},
          "filters": {"$ref": "#/components/schemas/MetaFilter"},
          "metadata_columns": {
            "type": "array",
            "items": {"type": "string"},
            "description": "Extra metadata fields per result row, e.g. `[\"rt_seconds\", \"native_id\"]`, or `[\"*\"]` for all, in addition to the library's configured columns."
          },
          "spectra": {
            "type": "array",
            "minItems": 1,
            "items": {"$ref": "#/components/schemas/BatchSpectrum"},
            "description": "At most `--max-batch-spectra` (default 10 000)."
          }
        }
      },
      "BatchHit": {
        "type": "object",
        "properties": {
          "library": {"type": "string"},
          "library_file": {"type": "string"},
          "library_scan": {"type": "integer"},
          "library_usi": {"type": "string"},
          "charge": {"type": "integer"},
          "precursor_mz": {"type": "number"},
          "delta_mass": {"type": "number"},
          "cosine": {"type": "number", "description": "The score; the key is `entropy` or `reverse_cosine` instead for those `score` modes."},
          "entropy": {"type": "number", "description": "`score: entropy`, in place of `cosine`."},
          "reverse_cosine": {"type": "number", "description": "`score: reverse_cosine`, in place of `cosine`."},
          "matched_peaks": {"type": "integer"},
          "spectrum_id": {"type": "integer"},
          "query_matched_intensity": {"type": "number", "description": "`score: reverse_cosine`: fraction of the query's intensity (Σ stored², stored = √raw) on matched peaks."},
          "library_matched_intensity": {"type": "number", "description": "`score: reverse_cosine`: fraction of the library spectrum's intensity on matched peaks."},
          "metadata": {
            "type": "object",
            "additionalProperties": {"type": "string"}
          }
        }
      },
      "BatchResultLine": {
        "type": "object",
        "description": "One JSONL line per query, in completion order.",
        "properties": {
          "query_index": {"type": "integer"},
          "query_id": {"type": ["string", "null"]},
          "query_file": {"type": "string"},
          "query_scan": {"type": "integer"},
          "query_charge": {"type": "integer"},
          "query_precursor_mz": {"type": "number"},
          "num_hits": {"type": "integer"},
          "total_hits": {"type": "integer"},
          "truncated": {"type": "boolean"},
          "hits": {
            "type": "array",
            "items": {"$ref": "#/components/schemas/BatchHit"}
          },
          "error": {"type": "string", "description": "Failed queries only."}
        }
      },
      "MassqlRequest": {
        "type": "object",
        "required": ["library", "query"],
        "properties": {
          "library": {"type": "string", "description": "An engine-ls library."},
          "query": {"type": "string", "description": "MassQL query text (MS2 conditions; `#` comments allowed)."},
          "max_matches": {"type": "integer", "minimum": 1, "description": "Stop after this many matching scans (capped by the server's `--massql-max-matches`)."},
          "filters": {"$ref": "#/components/schemas/MetaFilter"},
          "metadata_columns": {"type": "array", "items": {"type": "string", "minLength": 1}, "maxItems": 64, "description": "Per-spectrum metadata columns for every row, after the library's `result_metadata_columns` label: stored MGF headers / annotation columns, `layer.column`, or core fields such as `native_id`. Rows then end with a `metadata` object (JSON) or have one nullable string column per key (Parquet; `meta_<key>` for a key named like a fixed column). `*` is refused (422)."}
        }
      },
      "MassqlMatched": {
        "type": "object",
        "required": ["condition", "type", "observed"],
        "properties": {
          "condition": {"type": "integer", "description": "Condition position in the query (0-based)."},
          "type": {"type": "string", "enum": ["MS2PROD", "MS2NL", "MS2PREC"]},
          "value": {"type": ["number", "null"], "description": "Condition value (the evaluated expression for `X`; null for `ANY`)."},
          "observed": {"type": "number", "description": "Peak m/z (MS2PROD), loss `precursor − mz` (MS2NL) or precursor m/z (MS2PREC) of the most intense matching peak."},
          "mz": {"type": ["number", "null"]},
          "intensity_percent": {"type": ["number", "null"], "description": "Of the raw spectrum's base peak (indices built before FASST stored the raw intensity scale: of the stored base peak)."},
          "intensity": {"type": "number", "description": "Absolute (raw) intensity of the peak, stored² × kept_intensity_sum; omitted on indices without the scale."}
        }
      },
      "MassqlRow": {
        "type": "object",
        "required": ["spectrum_id", "usi", "file", "dataset", "scan", "precursor_mz", "charge", "polarity", "matched"],
        "properties": {
          "spectrum_id": {"type": "integer"},
          "usi": {"type": "string"},
          "file": {"type": "string"},
          "dataset": {"type": "string"},
          "scan": {"type": "integer"},
          "rt": {"type": ["number", "null"], "description": "Retention time in minutes."},
          "precursor_mz": {"type": "number"},
          "charge": {"type": "integer"},
          "polarity": {"type": "string", "enum": ["positive", "negative", ""]},
          "x": {"type": "number", "description": "Queries with `X`: a value of X satisfying every condition."},
          "matched": {"type": "array", "items": {"$ref": "#/components/schemas/MassqlMatched"}},
          "metadata": {"type": "object", "additionalProperties": {"type": ["string", "null"]}, "description": "Only with metadata columns (the library's `result_metadata_columns` label and / or the request's `metadata_columns`): every column in order, its value as a string, null when the spectrum has none. The row's last field.", "example": {"SOURCE_FILE": "MSV000086206/raw/S_P2.mzML", "SOURCE_SCAN": "2625", "FEATURE_ID": null}}
        }
      },
      "MassqlProgress": {
        "type": "object",
        "required": ["matches", "finished"],
        "properties": {
          "matches": {"type": "integer"},
          "datasets": {"type": "integer"},
          "shards_done": {"type": "integer", "description": "Shards of the library searched so far."},
          "shards_total": {"type": "integer", "description": "Shards of the library (0 until the run has started)."},
          "finished": {"type": "boolean"},
          "truncated": {"type": "boolean", "description": "Stopped before searching every shard (see stop_reason)."},
          "stop_reason": {"type": ["string", "null"], "enum": ["max_matches", "result_size", "timeout", "cancelled", "error", null], "description": "Why the run stopped early: max_matches reached, the per-result size limit, the timeout (status FAILED), DELETE (status CANCELLED), an error; null while running or when every shard was searched."},
          "stats": {"type": "object", "description": "Execution statistics (shards, candidates, verified, postings, plan, warnings) once done."}
        }
      },
      "MassqlCounts": {
        "type": "object",
        "required": ["matches", "datasets"],
        "properties": {
          "id": {"type": "string"},
          "library": {"type": "string"},
          "status": {"type": "string", "description": "The job status (counts are partial while RUNNING, and cover the rows found before a FAILED or CANCELLED run stopped)."},
          "error": {"type": "string", "description": "Failed, timed-out or cancelled runs."},
          "finished": {"type": "boolean"},
          "truncated": {"type": "boolean"},
          "matches": {"type": "integer"},
          "datasets": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {"dataset": {"type": "string"}, "scans": {"type": "integer"}, "files": {"type": "integer"}}
            }
          }
        }
      },
      "LibraryOption": {
        "type": "object",
        "properties": {
          "label": {"type": "string"},
          "value": {"type": "string"}
        }
      },
      "LibraryFile": {
        "type": "object",
        "properties": {
          "filepath": {"type": "string"},
          "dataset": {"type": "string"},
          "mri": {"type": "string"}
        }
      },
      "LibraryInfo": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "engine": {"type": "string", "enum": ["ls", "ref"]},
          "engine_format_version": {"type": "integer"},
          "massql": {"type": "boolean", "description": "MassQL queries (`POST /api/v2/massql`) run on this library (engine-ls, and the server has a MassQL executor)."},
          "version": {
            "type": ["string", "null"],
            "description": "libsync version stamp (`<name>@<utc>`, the `.versions/` directory the library resolves to), else null."
          },
          "num_spectra": {"type": "integer", "description": "Spectra in the index."},
          "num_files": {"type": "integer", "description": "Source files indexed (repository indices: peak files; GNPS libraries: library MGFs)."},
          "created_unix": {"type": "integer"},
          "preprocessing": {"type": "object"},
          "labels": {
            "type": "object",
            "additionalProperties": {"type": "string"},
            "description": "Manifest labels, e.g. `result_metadata_columns`, and from libsync `libsync.built_at`, `libsync.imported_at_max` (newest source library import), `libsync.source_url`."
          }
        }
      },
      "V2Libraries": {
        "type": "object",
        "properties": {
          "generation": {"type": "integer"},
          "loaded_unix": {"type": "integer"},
          "libraries": {
            "type": "array",
            "items": {"$ref": "#/components/schemas/LibraryInfo"}
          },
          "errors": {
            "type": "object",
            "additionalProperties": {"type": "string"},
            "description": "Libraries that failed to open: name → reason."
          },
          "io": {"type": "object", "description": "IO mode / block cache, when the binary provides it."}
        }
      },
      "StoredSpectrum": {
        "type": "object",
        "properties": {
          "spectrum_id": {"type": "integer"},
          "filename": {"type": "string"},
          "scan": {"type": "integer"},
          "charge": {"type": "integer"},
          "precursor_mz": {"type": "number"},
          "usi": {"type": "string"},
          "peaks": {
            "type": "array",
            "description": "Stored (preprocessed) peaks.",
            "items": {
              "type": "array",
              "prefixItems": [
                {"type": "number"},
                {"type": "number"}
              ],
              "minItems": 2,
              "maxItems": 2
            }
          },
          "metadata": {
            "type": ["object", "null"],
            "additionalProperties": {"type": "string"}
          }
        }
      },
      "ActiveJobs": {
        "type": "object",
        "description": "Jobs of one kind pending (queued) and running now.",
        "properties": {"pending": {"type": "integer"}, "running": {"type": "integer"}}
      },
      "Stats": {
        "type": "object",
        "additionalProperties": true,
        "description": "Sections; clients must ignore unknown keys.",
        "properties": {
          "jobs": {
            "type": "object",
            "description": "`queued` / `running` (all kinds, MassQL streams waiting for slots included), `stored`, `by_state` (kind -> state -> count; only kinds with jobs), `active` (every kind, zeros included: jobs pending and running now) and `massql_streams` (`/api/v2/massql/stream` connections waiting for slots / searching; they are not jobs).",
            "properties": {
              "queued": {"type": "integer"},
              "running": {"type": "integer"},
              "stored": {"type": "integer"},
              "by_state": {"type": "object", "additionalProperties": {"type": "object", "additionalProperties": {"type": "integer"}}},
              "active": {
                "type": "object",
                "properties": {
                  "search": {"$ref": "#/components/schemas/ActiveJobs"},
                  "batch": {"$ref": "#/components/schemas/ActiveJobs"},
                  "massql": {"$ref": "#/components/schemas/ActiveJobs"},
                  "export": {"$ref": "#/components/schemas/ActiveJobs"}
                }
              },
              "massql_streams": {
                "type": "object",
                "properties": {"waiting": {"type": "integer"}, "running": {"type": "integer"}}
              }
            }
          },
          "exports": {
            "type": "object",
            "description": "Bulk exports: `enabled` (`--export-dir` set and usable), `running` (exports holding one of the `workers` export slots, `--export-workers`), `disk_used_bytes` of `disk_quota_bytes` (`--export-quota`).",
            "properties": {
              "enabled": {"type": "boolean"},
              "running": {"type": "integer"},
              "workers": {"type": "integer"},
              "disk_used_bytes": {"type": "integer"},
              "disk_quota_bytes": {"type": "integer"}
            }
          },
          "results": {"type": "object"},
          "workers": {"type": "object", "description": "`search` workers and `search_available`; `analog`: analog searches allowed at once among them (`--analog-workers`), `analog_available`; `batch` slots and `batch_available`; `sync_budget_seconds`."},
          "ui": {"type": "object"},
          "build": {"$ref": "#/components/schemas/BuildInfo"},
          "generation": {"type": "integer"},
          "libraries": {"type": "integer"},
          "io": {
            "description": "IO mode and block cache of the engines (null when the binary provides none). engine-ls: `mode`, `backend`, `cache` (capacity, pinned, `data_bytes`, `free_bytes`, `shards`, hits, misses, `hit_rate`, inserts, evictions, `room_inserts` / `room_refused` = pages added into free room only / refused because the cache was full, `released_pages` = given back when an index was closed), `totals` (process-wide fetch counters since start: `reads` = device reads after coalescing, `bytes` read, `pages` requested, `hit_pages` served by the cache, `rounds`, `req_bytes`, `cached_pages` added to the cache), `massql` (the part of the totals MassQL's explicit reads issued), `massql_cache` (`elastic`, `bypass` or `fill`) and `warmup` (FASST_WARMUP progress: `level`, `state`, `queued`, `finished`, `current`, `target_bytes`, `read_bytes`, `cached_bytes`, `resident_bytes`, `seconds`, `mib_per_s`, `done` with each finished index's `outcome`)."
          },
          "process": {
            "type": "object",
            "description": "The server process, cumulative since start. `cpu_seconds` = user + system CPU time of all its threads (`getrusage`); load tests divide its delta by the searches they ran (CPU-ms per query). `disk` is `/proc/self/io` (`read_bytes` = storage-layer bytes, O_DIRECT reads included) and `cgroup` the cgroup v2 CPU accounting of the container (`usage_seconds` covers every process in it; `throttled_seconds` > 0 means the CPU limit `limit_cpus` was hit); each is null where unreadable.",
            "properties": {
              "pid": {"type": "integer"},
              "uptime_seconds": {"type": "number"},
              "cpu_user_seconds": {"type": "number"},
              "cpu_system_seconds": {"type": "number"},
              "cpu_seconds": {"type": "number"},
              "available_cpus": {"type": "integer", "description": "CPUs this process may use (affinity and cgroup quota)."},
              "threads": {"type": ["integer", "null"]},
              "rss_bytes": {"type": ["integer", "null"]},
              "max_rss_bytes": {"type": ["integer", "null"]},
              "major_faults": {"type": ["integer", "null"]},
              "voluntary_context_switches": {"type": ["integer", "null"]},
              "involuntary_context_switches": {"type": ["integer", "null"]},
              "disk": {"type": ["object", "null"], "additionalProperties": {"type": "integer"}},
              "cgroup": {"type": ["object", "null"]}
            }
          },
          "searches": {
            "type": "object",
            "description": "Engine searches since start, every lane (compat, v2, batch queries, web UI): `started`, `finished` (success or failure), `in_flight`, and their summed `wall_seconds` and `thread_cpu_seconds` (CPU of the searching thread only; the process total is `process.cpu_seconds`).",
            "properties": {
              "started": {"type": "integer"},
              "finished": {"type": "integer"},
              "in_flight": {"type": "integer"},
              "wall_seconds": {"type": "number"},
              "thread_cpu_seconds": {"type": "number"}
            }
          }
        }
      },
      "BuildInfo": {
        "type": "object",
        "required": ["version", "git_sha", "build_time"],
        "properties": {
          "version": {"type": "string", "description": "fasst version."},
          "git_sha": {
            "type": "string",
            "description": "Short git commit (`-dirty` when built from a modified tree; `unknown` without git)."
          },
          "build_time": {"type": "string", "description": "Build time, RFC 3339 UTC."},
          "display": {"type": "string", "description": "One line for people (shown in the web UI footer)."}
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "status": {"type": "string"},
          "message": {"type": "string"}
        }
      }
    },
    "responses": {
      "RateLimited": {
        "description": "Too many requests: the per-IP request-rate limit (`code: rate_limited`), or, for clients that are not whitelisted, too many of your jobs queued or running (`code: busy`; async submissions count until they finish; see docs/api.md \"Limits\"). Retry after `Retry-After` seconds.",
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait.",
            "schema": {"type": "integer"}
          }
        },
        "content": {
          "application/json": {
            "schema": {"$ref": "#/components/schemas/RateLimited"},
            "example": {
              "detail": "Too many requests: search rate limit exceeded, retry later",
              "error": "rate limit exceeded",
              "code": "rate_limited",
              "retry_after": 1
            }
          }
        }
      },
      "QueueFull": {
        "description": "The server's job queue is full (`code: queue_full`); retry after `Retry-After` seconds.",
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait (5).",
            "schema": {"type": "integer"}
          }
        },
        "content": {
          "application/json": {
            "schema": {"$ref": "#/components/schemas/RateLimited"},
            "example": {"detail": "Search queue is full, retry shortly", "error": "Search queue is full, retry shortly", "code": "queue_full", "retry_after": 5}
          }
        }
      },
      "LibraryNotFound": {
        "description": "Unknown library.",
        "content": {
          "application/json": {
            "schema": {"$ref": "#/components/schemas/Error"},
            "example": {"error": "library 'nope' not found"}
          }
        }
      },
      "JobNotFound": {
        "description": "Unknown job id (never submitted, or past its TTL).",
        "content": {
          "application/json": {
            "schema": {"$ref": "#/components/schemas/NotFoundJob"},
            "example": {"id": "2dac008f-be4e-477c-998c-7d3634d61809", "status": "NOT_FOUND", "error": "unknown job id"}
          }
        }
      }
    },
    "parameters": {
      "JobId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Job id returned by the submission.",
        "schema": {"type": "string"},
        "example": "2dac008f-be4e-477c-998c-7d3634d61809"
      },
      "BatchId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Batch id returned by `POST /api/v2/batch`.",
        "schema": {"type": "string"},
        "example": "e0c1cb1c-cb7a-4a33-bb86-d1fabda575e1"
      }
    }
  }
}
