{
 "openapi": "3.1.0",
 "info": {
  "title": "STARCO Dev API",
  "version": "1.1.0-draft",
  "summary": "Hosted digital twins for developers (sandbox, synthetic data only).",
  "description": "STARCO Dev is a hosted framework for digital twins, operated by STARCO SYSTEMS EUROPE, S.L. Developers create projects,\nget scoped and expiring API keys, create twins from templates, send observations, read the recomputed layers,\nexport twins with a SHA-256 fingerprint and verify a hash-chained audit log of every access to their project.\n\nv1.1 extends the twin model (twins → layers → typed measures → observations → recomputed layers): layer schemas\n(custom layers with typed measures, versioned), the twin's current state per measure (versions, ETag,\ncompare-and-set, transactions with watch), the observation series of each numeric measure (raw or bucketed), the\nhistory of each measure, project events (cursor and long-poll) and signed webhooks. Experimental: the illustrative\nscenario and the statistical fits (regression curves) of a numeric measure of a twin, and the cohort summary of a\nnumeric measure over the twins of a project; the three carry the SHA-256 fingerprints of what they read and of what\nthey answer.\n\n**Sandbox: synthetic data only.** Do not send real personal or health data. Labels that look like real identifiers\n(e-mail addresses, phone numbers, national ids, SSNs, IBANs, long numbers) and fields named like identifiers are\nrefused. Layer values are descriptive (count, latest, min, max, mean): no reference ranges, no interpretation, no\nscores; `null` means no data.\n\n**Experimental: illustrative scenarios.** `GET /twins/{twin}/scenarios/{measure}` is computed on the server and\ndescribes one twin's own days shifted by a change the caller declares: a baseline of the twin's own days in a window\n(how many, mean, min, max, quartiles) and the middle half of those days moved by that change, kept inside the accepted\nbounds of the measure. It is labelled \"Illustrative scenario, not a prediction\": it reads no other twin, compares\nwith no reference range, interprets nothing, gives no score and states no health outcome; with fewer than 7 days with\na value every figure is `null`. Experimental: its fields can still change and the operation can be withdrawn; this\ndescription and the changelog will say so.\n\n**Experimental: statistical fits.** `GET /twins/{twin}/fits/{measure}` is computed on the server and fits regression\ncurves by ordinary least squares to one twin's own daily series: linear, quadratic, cubic, exponential, logarithmic\nand power, over time or over other numeric measures of the same twin. It returns each model's coefficients and fit\nstatistics side by side in a fixed order, the fitted value of every observed day and, on request, estimates with a\n95 % prediction interval. It never ranks the models and never marks one as preferable: choosing a model is the\nresearcher's job. Every answer is labelled \"Experimental. A statistical fit of this twin's own series: an\nextrapolation, not a health prediction.\": it reads no other twin, compares with no reference range, interprets\nnothing, gives no score and states no health outcome; an estimate is never clamped (it is flagged when it leaves\nthe accepted bounds of the measure); with fewer than 7 days with a value there is no fit, and what is not defined\nis `null` with a reason. Experimental: its fields can still change and the operation can be withdrawn; this\ndescription and the changelog will say so.\n\n**Experimental: cohort summaries.** `GET /cohort/{measure}` is computed on the server and describes a numeric measure\nover the twins of the project of the key: for each twin, the days of a window with a value and the mean of those\ndaily values, and for the cohort the minimum, quartiles, maximum and mean of those per-twin means with a histogram of\nbins of equal width. It is the one experimental operation that reads several twins: only twins of the project of the\nkey, never another project, and at most 200 in a call (a larger selection is refused, never cut short). It is\nlabelled \"Experimental. A description of the twins of this project, in the order they were created: not a ranking,\nnot a reference range and not a health assessment.\": the twins are listed in the order they were created, nothing is\nranked, no twin is flagged, the distribution is the project's own data and not a reference range, and nothing is\nscored, interpreted or predicted; a twin with fewer than 7 days with a value has a `null` mean with a reason.\nExperimental: its fields can still change and the operation can be withdrawn; this description and the changelog\nwill say so.\n\n**Experimental: fingerprints of a computed result.** The answers of the three experimental operations carry\n`input_sha256` and `result_sha256`: the SHA-256 of what the computation read and was asked, and the SHA-256 of what\nit answered, each over a canonical text that anyone holding the same data can write again (schema\n`ComputedFingerprints`). The audit row of the call holds `result_sha256`, so the hash chain of the project attests\nthat this result was given at that time. A fingerprint tells whether two results are the same; it is not a signature\nand it says nothing about whether a result is right.\n\nFour kinds of access:\n- open: status, terms, sign-up and sign-in (rate limited per IP);\n- console token (`starco_dc_…`, 12 hours): account, projects (with their usage and limits) and keys;\n- project key (`starco_dk_…`, scopes `read` / `write`, at most 90 days): templates, twins, observations, layers,\n  export and audit. Every request with a key is one row of the project's audit chain.\n- project MCP token (`starco_dm_…`, fixed `mcp:read`, one hour): six read-only tools in a synthetic project.\n\nErrors: `{\"success\": false, \"code\": \"<stable_snake_case>\", \"error\": \"<sentence>\"}` plus fields that help (`expected`,\n`field`, `needs`, `errors`).\nEvery `code` the API can answer, with its HTTP status, is listed in `components.x-error-codes`.\n\nRate limits: every operation is rate limited per minute (open operations per IP, the console per account, a key or\nan MCP token per project, `rate_limit_per_minute` of the project). Answers carry `X-RateLimit-Limit` and\n`X-RateLimit-Remaining`; a 429 (`too_many_attempts`) also carries `Retry-After` in seconds.\n\nRetries: there is no idempotency header. Safe to retry: every GET; PUT, DELETE and incr of a measure with\n`if_version` / `If-Match` (a replay is refused with 409 version_conflict); observations (a replayed line is rejected as\n`duplicate_observation`, never stored twice). Not safe to retry blindly: POST /twins (a replay creates a second twin;\nlist the twins, e.g. by label, before retrying), POST /schemas, POST /webhooks, POST keys and MCP tokens.\n\nVersions: the path version is `v1`; `info.version` is the version of this description (GET /status names both).\nv1.1 only added operations and fields to v1. No operation is deprecated, and no deprecation policy (notice period,\nDeprecation/Sunset headers) is defined yet.\n\nEdge mapping (not configured in the application): `https://api.starco.dev/v1/<path>` is rewritten to\n`/<deployment>/api/dev/v1/<path>` of the deployment that serves the API (`STARCO_DEV_API_DEPLOYMENT`).\n"
 },
 "servers": [
  {
   "url": "https://api.starco.dev/v1",
   "description": "Public address (edge rewrite, planned)"
  },
  {
   "url": "{origin}/{deployment}/api/dev/v1",
   "description": "Application address",
   "variables": {
    "origin": {
     "default": "http://localhost:8000"
    },
    "deployment": {
     "default": "cat"
    }
   }
  }
 ],
 "tags": [
  {
   "name": "Accounts"
  },
  {
   "name": "Billing"
  },
  {
   "name": "Projects"
  },
  {
   "name": "Twins"
  },
  {
   "name": "Observations"
  },
  {
   "name": "Audit"
  },
  {
   "name": "Layer schemas"
  },
  {
   "name": "State"
  },
  {
   "name": "Series"
  },
  {
   "name": "Scenarios",
   "description": "Experimental. Illustrative scenarios over synthetic data: a twin's own days shifted by a declared change. Not a prediction."
  },
  {
   "name": "Fits",
   "description": "Experimental. Statistical fits over synthetic data: regression curves fitted to a twin's own daily series, side by side and never ranked. An extrapolation, not a health prediction."
  },
  {
   "name": "Cohort",
   "description": "Experimental. Cohort summaries over synthetic data: the per-twin means of a numeric measure over the twins of the project and their distribution. Never ranked, not a reference range."
  },
  {
   "name": "Events"
  }
 ],
 "security": [
  {
   "projectKey": []
  }
 ],
 "paths": {
  "/status": {
   "get": {
    "tags": [
     "Accounts"
    ],
    "summary": "Whether the API answers here and which versions it speaks",
    "description": "Open, rate limited per IP in its own bucket (polling it never uses the sign-in attempts). `ok` means the application\nanswered and its database replied to a trivial query; nothing else is claimed (no uptime, no latency figure).\n",
    "security": [],
    "responses": {
     "200": {
      "description": "Answering, with the versions.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "api_version",
          "spec_version",
          "terms_version",
          "mcp_protocol_version",
          "server_time"
         ],
         "properties": {
          "status": {
           "const": "ok"
          },
          "api_version": {
           "type": "string",
           "examples": [
            "v1"
           ]
          },
          "spec_version": {
           "type": "string",
           "description": "info.version of this description.",
           "examples": [
            "1.1.0-draft"
           ]
          },
          "terms_version": {
           "type": "string",
           "examples": [
            "2026-11-27"
           ]
          },
          "mcp_protocol_version": {
           "type": "string",
           "examples": [
            "2025-06-18"
           ]
          },
          "server_time": {
           "type": "string",
           "format": "date-time"
          }
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "description": "service_unavailable: the database did not reply; the versions come in the envelope.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/terms": {
   "get": {
    "tags": [
     "Accounts"
    ],
    "summary": "Developer terms in force",
    "security": [],
    "responses": {
     "200": {
      "description": "Version to accept at sign-up.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "version",
          "status",
          "operator",
          "data_policy"
         ],
         "properties": {
          "version": {
           "type": "string",
           "examples": [
            "2026-11-27"
           ]
          },
          "status": {
           "type": "string",
           "enum": [
            "draft",
            "in_force"
           ]
          },
          "operator": {
           "type": "string"
          },
          "data_policy": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/accounts": {
   "post": {
    "tags": [
     "Accounts"
    ],
    "summary": "Create a developer account",
    "description": "The answer is the same whether the address already has an account or not. A message goes to the address: a\nsingle-use verification link or token for a new address (or for an account not verified yet, whose password\nbecomes the one sent now), or a notice for an address that already has a verified account (nothing changes).\nThe account cannot sign in until its address is verified (POST /accounts/verify). At most three messages per\naddress and hour; beyond that the answer is the same and nothing is sent.\n",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "email",
         "password",
         "accept_terms_version"
        ],
        "properties": {
         "email": {
          "type": "string",
          "format": "email"
         },
         "password": {
          "type": "string",
          "minLength": 12,
          "description": "At most 72 bytes; common passwords are refused."
         },
         "accept_terms_version": {
          "type": "string",
          "description": "Exactly the version of GET /terms."
         }
        }
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Accepted; a message was sent to the address (the same answer for any address).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "expires_in_minutes"
         ],
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "verification_required"
           ]
          },
          "expires_in_minutes": {
           "type": "integer"
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/accounts/verify": {
   "post": {
    "tags": [
     "Accounts"
    ],
    "summary": "Verify the address of an account with the token of the message",
    "description": "The token works once and expires (24 hours). Only its SHA-256 is stored.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "token"
        ],
        "properties": {
         "token": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Verified; the account can sign in.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "verified": {
           "type": "boolean"
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/password/forgot": {
   "post": {
    "tags": [
     "Accounts"
    ],
    "summary": "Ask for a link to set a new password",
    "description": "The answer is the same whether the address has an account or not; the message is sent after the answer. The link\nor token works once and expires (60 minutes). The messages of an address share one budget of three per hour.\n",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "email"
        ],
        "properties": {
         "email": {
          "type": "string",
          "format": "email"
         }
        }
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Accepted (the same answer for any address).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "status",
          "expires_in_minutes"
         ],
         "properties": {
          "status": {
           "type": "string",
           "enum": [
            "sent_if_account_exists"
           ]
          },
          "expires_in_minutes": {
           "type": "integer"
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/password/reset": {
   "post": {
    "tags": [
     "Accounts"
    ],
    "summary": "Set a new password with the token of the message",
    "description": "Signs out every console session of the account, voids every other link and counts as verifying the address.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "token",
         "password"
        ],
        "properties": {
         "token": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
         },
         "password": {
          "type": "string",
          "minLength": 12,
          "description": "At most 72 bytes; common passwords are refused."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Password changed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "password_changed": {
           "type": "boolean"
          },
          "sessions_closed": {
           "type": "integer"
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/sessions": {
   "post": {
    "tags": [
     "Accounts"
    ],
    "summary": "Sign in and get a console token (shown once)",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "email",
         "password"
        ],
        "properties": {
         "email": {
          "type": "string"
         },
         "password": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Console token.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "token",
          "prefix",
          "expires_at"
         ],
         "properties": {
          "token": {
           "type": "string",
           "pattern": "^starco_dc_[0-9a-f]{8}_[A-Za-z0-9_-]{43}$"
          },
          "prefix": {
           "type": "string"
          },
          "expires_at": {
           "type": "string",
           "format": "date-time"
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "get": {
    "tags": [
     "Accounts"
    ],
    "summary": "Open console sessions of the account",
    "description": "The sessions that are neither closed nor expired, newest first (at most 200). A session is named by the visible prefix of its console token; the token itself is never shown again. `current` marks the one making the request.",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Sessions.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data"
         ],
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ConsoleSession"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/sessions/{session}": {
   "parameters": [
    {
     "name": "session",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "pattern": "^starco_dc_[0-9a-f]{8}$"
     },
     "description": "The id of a session: the visible prefix of its console token."
    }
   ],
   "delete": {
    "tags": [
     "Accounts"
    ],
    "summary": "Close one console session of the account",
    "description": "Revokes the console token of that session, the one in use included (its next request answers 401 token_revoked). A session that is closed, expired, unknown or of another account answers 404.",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Closed.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "revoked",
          "id"
         ],
         "properties": {
          "revoked": {
           "type": "boolean"
          },
          "id": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/sessions/current": {
   "delete": {
    "tags": [
     "Accounts"
    ],
    "summary": "Revoke the console token in use",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Revoked.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "revoked": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/account": {
   "get": {
    "tags": [
     "Accounts"
    ],
    "summary": "The signed-in account",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Account.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "account": {
           "$ref": "#/components/schemas/Account"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Accounts"
    ],
    "summary": "Erase the account with all its projects, keys, twins and audit chains",
    "description": "A subscription of the account is ended in Stripe first, and the Checkout sessions it left open are expired\nthere (nobody can pay them afterwards); if Stripe does not confirm it, nothing is erased\n(502 billing_cancel_failed). Invoice records (Stripe ids, numbers, amounts and dates) are kept without the\naccount for the accounting of the seller; the invoices themselves stay in Stripe.\n",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "password"
        ],
        "properties": {
         "password": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Erasure receipt.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "receipt": {
           "type": "object",
           "properties": {
            "projects_erased": {
             "type": "integer"
            },
            "twins_erased": {
             "type": "integer"
            },
            "erased_at": {
             "type": "string",
             "format": "date-time"
            },
            "billing": {
             "type": "object",
             "properties": {
              "subscription_cancelled": {
               "type": "boolean"
              },
              "checkout_sessions_closed": {
               "type": "integer",
               "description": "Open Checkout sessions of the account expired in Stripe before the erasure."
              },
              "invoice_records_kept": {
               "type": "integer"
              },
              "note": {
               "type": "string"
              }
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "502": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/billing/plans": {
   "get": {
    "tags": [
     "Billing"
    ],
    "summary": "The plans, their limits and the price Stripe has for each",
    "description": "Billing routes answer 404 while billing is off on the server. The seller is STARCO SYSTEMS EUROPE, S.L.; payments are\nhandled by Stripe (Checkout and customer portal, hosted by Stripe): this API never receives a card. The amount of\na price is read from Stripe; `amount: null` means it could not be read and that plan and period cannot be bought\nnow. Taxes are not computed by this API.\n",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Plans.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "billing": {
           "$ref": "#/components/schemas/BillingService"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Plan"
           }
          },
          "contact": {
           "type": "object",
           "properties": {
            "url": {
             "type": "string"
            },
            "note": {
             "type": "string"
            }
           }
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/billing/subscription": {
   "get": {
    "tags": [
     "Billing"
    ],
    "summary": "The plan in force and the state of the subscription",
    "description": "The plan changes only when Stripe confirms it to this API with a signed webhook, never when the browser comes back\nfrom Checkout: poll this after paying. `past_due` keeps the plan until `grace_until`; after that the account is on\n`sandbox` and what is over its limits is read-only (nothing is deleted) until an invoice is paid.\n",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Plan and subscription.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "billing": {
           "$ref": "#/components/schemas/BillingService"
          },
          "plan": {
           "type": "string"
          },
          "limits": {
           "$ref": "#/components/schemas/PlanLimits"
          },
          "subscription": {
           "oneOf": [
            {
             "$ref": "#/components/schemas/Subscription"
            },
            {
             "type": "null"
            }
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/billing/checkout": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Start a Stripe Checkout session to subscribe to a plan",
    "description": "One call: the answer is the address of Stripe's hosted payment page, with the account's address already filled in.\nNot safe to retry blindly (each call creates a session; an abandoned one charges nothing). An account with a\nsubscription changes plan in the portal instead.\n",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "plan"
        ],
        "properties": {
         "plan": {
          "type": "string",
          "examples": [
           "supporter",
           "builder",
           "team"
          ]
         },
         "period": {
          "type": "string",
          "enum": [
           "month",
           "year"
          ],
          "default": "month"
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Checkout session.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "checkout_id",
          "checkout_url"
         ],
         "properties": {
          "checkout_id": {
           "type": "string",
           "format": "uuid"
          },
          "checkout_url": {
           "type": "string",
           "description": "Stripe's hosted payment page."
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "502": {
      "$ref": "#/components/responses/Error"
     },
     "503": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/billing/portal": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Open the Stripe customer portal (payment method, invoices, change plan, cancel)",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "201": {
      "description": "Portal session.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "portal_url"
         ],
         "properties": {
          "portal_url": {
           "type": "string"
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "502": {
      "$ref": "#/components/responses/Error"
     },
     "503": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/billing/invoices": {
   "get": {
    "tags": [
     "Billing"
    ],
    "summary": "The invoices of the account, with the page Stripe hosts for each",
    "description": "Read from Stripe at the time of the call, newest first.",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 24
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Invoices.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Invoice"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "502": {
      "$ref": "#/components/responses/Error"
     },
     "503": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/billing/subscription/cancel": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Cancel the subscription at the end of the paid period",
    "description": "Asks Stripe not to renew. The plan stays until the end of the period; `cancel_at_period_end` of\nGET /billing/subscription turns true once Stripe confirms it. Safe to retry. Undoing it is done in the portal.\n",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "202": {
      "description": "Asked to Stripe.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "cancel_requested": {
           "type": "boolean"
          },
          "current_period_end": {
           "type": [
            "string",
            "null"
           ],
           "format": "date-time"
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "502": {
      "$ref": "#/components/responses/Error"
     },
     "503": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/billing/stripe/webhook": {
   "post": {
    "tags": [
     "Billing"
    ],
    "summary": "Stripe's webhook (for Stripe only)",
    "description": "Not for developers: Stripe calls it. Authenticated by the `Stripe-Signature` header (HMAC-SHA256 with the\nendpoint's secret, five minutes of tolerance). Each event id is applied once; an event older than the last one\napplied changes nothing. Every verified event is answered 200 with what was done. The plan follows the state\nStripe reports for the subscription; an invoice only starts the grace period (first failure) or ends it (no\nother invoice of the subscription known as failed). An event of a subscription created by a Checkout of this\nAPI whose account no longer exists ends that subscription in Stripe (`orphan_cancelled`); if Stripe does not\nconfirm it the answer is 502 billing_provider_error, nothing is recorded and Stripe delivers the event again.\n",
    "security": [],
    "parameters": [
     {
      "name": "Stripe-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "received": {
           "type": "boolean"
          },
          "outcome": {
           "type": "string",
           "examples": [
            "applied",
            "duplicate",
            "stale",
            "ignored",
            "orphan_cancelled"
           ]
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "502": {
      "$ref": "#/components/responses/Error"
     },
     "503": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/projects": {
   "get": {
    "tags": [
     "Projects"
    ],
    "summary": "Projects of the account",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Projects.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Project"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Projects"
    ],
    "summary": "Create a project (with its synthetic cohort of 8 twins)",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name"
        ],
        "properties": {
         "name": {
          "type": "string",
          "maxLength": 80
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Project created; its cohort is ready.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "project": {
           "$ref": "#/components/schemas/Project"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/projects/{project}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/ProjectId"
    }
   ],
   "get": {
    "tags": [
     "Projects"
    ],
    "summary": "One project",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Project.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "project": {
           "$ref": "#/components/schemas/Project"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Projects"
    ],
    "summary": "Rename a project or change its rate limit",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "maxLength": 80
         },
         "rate_limit_per_minute": {
          "type": "integer",
          "minimum": 1,
          "maximum": 600
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Project.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "project": {
           "$ref": "#/components/schemas/Project"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Projects"
    ],
    "summary": "Erase one project with its twins, keys, MCP tokens, events, webhooks and audit chain",
    "description": "Confirmed with the account password. The account and its other projects stay. A project on which a Studio study is\nbuilt is refused (409 project_has_study): the study would go with it. Nothing of the project is kept but the receipt.\n",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "password"
        ],
        "properties": {
         "password": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Erasure receipt.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "receipt": {
           "type": "object",
           "required": [
            "project_id",
            "twins_erased",
            "observations_erased",
            "keys_erased",
            "erased_at"
           ],
           "properties": {
            "project_id": {
             "type": "string",
             "format": "uuid"
            },
            "twins_erased": {
             "type": "integer"
            },
            "observations_erased": {
             "type": "integer"
            },
            "keys_erased": {
             "type": "integer",
             "description": "Project keys and MCP tokens, active or not."
            },
            "erased_at": {
             "type": "string",
             "format": "date-time"
            },
            "note": {
             "type": "string"
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/projects/{project}/usage": {
   "parameters": [
    {
     "$ref": "#/components/parameters/ProjectId"
    }
   ],
   "get": {
    "tags": [
     "Projects"
    ],
    "summary": "What the project uses against each limit of the account's plan",
    "description": "Counts only (never a value). The limits are those of the account's plan (`plan`; `sandbox` is the free one and the\nonly one while billing is off). `rate_limit_per_minute` is the project's own setting (PATCH /projects/{project});\n`rate_limit_effective_per_minute` is what it really gets (never above the plan's maximum). `read_only` is true\nwhen the project is beyond the plan's number of projects: it can be read, exported and erased, not written.\n",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Usage and limits.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "project_id",
          "usage",
          "limits"
         ],
         "properties": {
          "project_id": {
           "type": "string",
           "format": "uuid"
          },
          "plan": {
           "type": "string",
           "examples": [
            "sandbox"
           ]
          },
          "read_only": {
           "type": "boolean"
          },
          "usage": {
           "type": "object",
           "properties": {
            "twins": {
             "type": "integer"
            },
            "active_keys": {
             "type": "integer",
             "description": "Not revoked and not expired, MCP tokens included (they count against the same limit)."
            },
            "observations": {
             "type": "integer"
            },
            "layer_schemas": {
             "type": "integer"
            },
            "active_webhooks": {
             "type": "integer"
            },
            "audit_events": {
             "type": "integer"
            }
           }
          },
          "limits": {
           "type": "object",
           "properties": {
            "projects_per_account": {
             "type": "integer"
            },
            "active_keys_per_project": {
             "type": "integer"
            },
            "twins_per_project": {
             "type": "integer"
            },
            "observations_per_twin": {
             "type": "integer"
            },
            "observations_per_batch": {
             "type": "integer"
            },
            "layer_schemas_per_project": {
             "type": "integer"
            },
            "custom_layers_per_twin": {
             "type": "integer"
            },
            "webhooks_per_project": {
             "type": "integer"
            },
            "operations_per_transaction": {
             "type": "integer"
            },
            "points_per_append": {
             "type": "integer"
            },
            "rate_limit_per_minute": {
             "type": "integer"
            },
            "rate_limit_effective_per_minute": {
             "type": "integer"
            },
            "rate_limit_max_per_minute": {
             "type": "integer"
            },
            "key_max_ttl_days": {
             "type": "integer"
            },
            "events_retention_days": {
             "type": "integer"
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/cloud-link-intents/inspect": {
   "post": {
    "tags": [
     "Projects"
    ],
    "summary": "Inspect a manually shared Cloud association code",
    "description": "Console account only; both Dev and Cloud must be enabled in the same deployment. A Cloud manager deliberately shares this 128-bit bearer authorization for one registered instance with the intended Dev project owner. It expires after ten minutes. Send it only in the JSON body, never in a URL or log. Inspection does not consume it or grant access. Verify the displayed organization and instance before confirming. No hosting, provisioning, twin data transfer or Dev permission is granted.",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "code"
        ],
        "properties": {
         "code": {
          "$ref": "#/components/schemas/CloudAssociationCode"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Private, no-store. Inspect a manually shared Cloud association code.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "target",
          "expires_at",
          "provisioning",
          "data_access"
         ],
         "properties": {
          "target": {
           "type": "object",
           "required": [
            "organization",
            "instance"
           ],
           "properties": {
            "organization": {
             "type": "string"
            },
            "instance": {
             "type": "string"
            }
           }
          },
          "expires_at": {
           "type": "string",
           "format": "date-time"
          },
          "provisioning": {
           "const": "none"
          },
          "data_access": {
           "const": false
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/projects/{project}/cloud-links": {
   "parameters": [
    {
     "$ref": "#/components/parameters/ProjectId"
    }
   ],
   "get": {
    "tags": [
     "Projects"
    ],
    "summary": "List this owner's active Cloud references for a project",
    "description": "Console account only, never a project key or Ritmical identity. At most ten active links per project. Only explicit shared aliases and destination names are returned, without Cloud credentials or infrastructure access. Requires both Dev and Cloud in the same deployment.",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Private, no-store. List this owner's active Cloud references for a project.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "links",
          "provisioning",
          "data_access"
         ],
         "properties": {
          "links": {
           "type": "array",
           "maxItems": 10,
           "items": {
            "$ref": "#/components/schemas/CloudProjectLink"
           }
          },
          "provisioning": {
           "const": "none"
          },
          "data_access": {
           "const": false
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Projects"
    ],
    "summary": "Confirm a synthetic project's reference to the inspected Cloud destination",
    "description": "The verified Dev account must own the project, whose data class must be synthetic. Confirm the destination and deliberately choose the alias shared with Cloud organization members; do not put personal data in it. The alias is not the private project name. Organization, creator's current manager role, instance availability, deployment, account, ownership and unused/unexpired code are rechecked atomically. A project/instance pair is unique; limits are ten active links per project and one hundred per organization. This consumes the code once and writes minimized Cloud and Dev audit records. It does not create an instance, copy twin data, authorize Dev access or transfer credentials. If the response is lost, read this project's links before retrying: consumption is not replayed.",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "code",
         "alias",
         "confirm"
        ],
        "properties": {
         "code": {
          "$ref": "#/components/schemas/CloudAssociationCode"
         },
         "alias": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80,
          "description": "Trimmed synthetic label; letters, numbers, spaces, underscore, dot or hyphen. Identifier-like values are refused."
         },
         "confirm": {
          "const": true
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Private, no-store. Confirm a synthetic project's reference to the inspected Cloud destination.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "link",
          "provisioning",
          "data_access"
         ],
         "properties": {
          "link": {
           "$ref": "#/components/schemas/CloudProjectLink"
          },
          "provisioning": {
           "const": "none"
          },
          "data_access": {
           "const": false
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/projects/{project}/cloud-links/{link}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/ProjectId"
    },
    {
     "name": "link",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "format": "uuid"
     }
    }
   ],
   "delete": {
    "tags": [
     "Projects"
    ],
    "summary": "Revoke this owner's explicit Cloud metadata reference",
    "description": "Console account only; the project must belong to the account in this deployment. Revocation hides the reference from both consoles. Safe to repeat while the project and reference still exist. Cloud managers may also revoke it from Cloud. It does not delete a project, stop an instance, move data or erase independent audit history. Requires both Dev and Cloud in the same deployment.",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Private, no-store. Revoke this owner's explicit Cloud metadata reference.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "revoked"
         ],
         "properties": {
          "revoked": {
           "const": true
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/projects/{project}/keys": {
   "parameters": [
    {
     "$ref": "#/components/parameters/ProjectId"
    }
   ],
   "get": {
    "tags": [
     "Projects"
    ],
    "summary": "Keys of a project (never their secrets)",
    "description": "Every key ever created in the project, oldest first, in pages. Without parameters, the first 200.",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 200,
       "default": 200
      },
      "description": "Out-of-range values are clamped."
     },
     {
      "name": "after",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Cursor: next_after of the previous page."
     }
    ],
    "responses": {
     "200": {
      "description": "Keys.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Key"
           }
          },
          "next_after": {
           "type": [
            "integer",
            "null"
           ],
           "description": "null on the last page."
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Projects"
    ],
    "summary": "Create a key (the secret is shown once)",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name",
         "scopes"
        ],
        "properties": {
         "name": {
          "type": "string",
          "maxLength": 80
         },
         "scopes": {
          "type": "array",
          "minItems": 1,
          "items": {
           "type": "string",
           "enum": [
            "read",
            "write"
           ]
          }
         },
         "ttl_days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 90,
          "default": 30
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Key and its secret.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "key",
          "secret"
         ],
         "properties": {
          "key": {
           "$ref": "#/components/schemas/Key"
          },
          "secret": {
           "type": "string",
           "pattern": "^starco_dk_[0-9a-f]{8}_[A-Za-z0-9_-]{43}$"
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/projects/{project}/keys/{key}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/ProjectId"
    },
    {
     "name": "key",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "format": "uuid"
     }
    }
   ],
   "delete": {
    "tags": [
     "Projects"
    ],
    "summary": "Revoke a key",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "responses": {
     "200": {
      "description": "Revoked key.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "key": {
           "$ref": "#/components/schemas/Key"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/templates": {
   "get": {
    "tags": [
     "Twins"
    ],
    "summary": "Templates, layers and observation kinds with their units (scope read)",
    "responses": {
     "200": {
      "description": "Catalogue.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "templates": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "id": {
              "type": "string"
             },
             "name": {
              "type": "string"
             },
             "focus": {
              "type": "string"
             },
             "layers": {
              "type": "array",
              "items": {
               "type": "string"
              }
             },
             "wellness_kinds": {
              "type": "array",
              "items": {
               "type": "string"
              }
             }
            }
           }
          },
          "layers": {
           "type": "array",
           "items": {
            "type": "string",
            "enum": [
             "wellness",
             "biomarkers"
            ]
           }
          },
          "kinds": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "kind": {
              "type": "string"
             },
             "layer": {
              "type": "string"
             },
             "unit": {
              "type": "string"
             },
             "accepted_min": {
              "type": "number"
             },
             "accepted_max": {
              "type": "number"
             },
             "integer": {
              "type": "boolean"
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins": {
   "get": {
    "tags": [
     "Twins"
    ],
    "summary": "Twins of the key's project (scope read)",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 200,
       "default": 50
      }
     },
     {
      "name": "after",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Cursor: next_after of the previous page."
     }
    ],
    "responses": {
     "200": {
      "description": "Page of twins.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Twin"
           }
          },
          "next_after": {
           "type": [
            "integer",
            "null"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Twins"
    ],
    "summary": "Create a twin from a template and/or layer schemas (scope write)",
    "description": "Without schemas, template and layers are required (v1). With schemas (one per custom layer), both are optional.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
         "template": {
          "type": "string",
          "examples": [
           "daily_movement"
          ]
         },
         "layers": {
          "type": "array",
          "maxItems": 2,
          "items": {
           "type": "string",
           "enum": [
            "wellness",
            "biomarkers"
           ]
          }
         },
         "schemas": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "items": {
           "type": "string",
           "format": "uuid"
          }
         },
         "label": {
          "type": [
           "string",
           "null"
          ],
          "maxLength": 64
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Twin created.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "twin": {
           "$ref": "#/components/schemas/Twin"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    }
   ],
   "get": {
    "tags": [
     "Twins"
    ],
    "summary": "One twin (scope read)",
    "responses": {
     "200": {
      "description": "Twin with the state of its layers.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "twin": {
           "$ref": "#/components/schemas/Twin"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Twins"
    ],
    "summary": "Erase a twin with its observations and layers (scope write)",
    "responses": {
     "200": {
      "description": "Erasure receipt (also kept in the audit chain).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "receipt": {
           "type": "object",
           "required": [
            "twin_id",
            "erased_at",
            "observations_erased",
            "layers_erased",
            "content_sha256"
           ],
           "properties": {
            "twin_id": {
             "type": "string",
             "format": "uuid"
            },
            "erased_at": {
             "type": "string",
             "format": "date-time"
            },
            "observations_erased": {
             "type": "integer"
            },
            "layers_erased": {
             "type": "integer"
            },
            "content_sha256": {
             "type": "string",
             "description": "SHA-256 of the twin's export right before erasure."
            },
            "note": {
             "type": "string"
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/observations": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    }
   ],
   "get": {
    "tags": [
     "Observations"
    ],
    "summary": "Series of observations (scope read)",
    "parameters": [
     {
      "name": "kind",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "Inclusive."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "Exclusive."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 5000,
       "default": 1000
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Observations in time order.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "twin_id": {
           "type": "string",
           "format": "uuid"
          },
          "data": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "kind": {
              "type": "string"
             },
             "value": {
              "type": "number"
             },
             "unit": {
              "type": "string"
             },
             "observed_at": {
              "type": "string",
              "format": "date-time"
             },
             "origin": {
              "type": "string",
              "enum": [
               "api",
               "synthetic_cohort"
              ]
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Observations"
    ],
    "summary": "Send a batch of observations (scope write)",
    "description": "Each line is validated on its own: `kind` from GET /templates, `unit` exactly as listed (never converted), a\nnumeric `value` within the accepted bounds (integer where required), `observed_at` RFC 3339 with an offset, not\nin the future. Unknown fields are refused (`identifier_field_not_accepted` for names such as `email` or\n`patient_id`). A refused line is never stored, not even in part; the valid lines are stored together and the\naffected layers are recomputed before the answer. An observation with the same kind and time as a stored one is\nrefused (`duplicate_observation`), never overwritten. 200 when at least one line was accepted, 422 when none.\n",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "observations"
        ],
        "additionalProperties": false,
        "properties": {
         "observations": {
          "type": "array",
          "minItems": 1,
          "maxItems": 500,
          "items": {
           "$ref": "#/components/schemas/ObservationLine"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Batch result.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BatchResult"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "413": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "description": "No line accepted (same body as 200), or the batch itself is malformed (error envelope).",
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "$ref": "#/components/schemas/BatchResult"
          },
          {
           "$ref": "#/components/schemas/Error"
          }
         ]
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/layers/{layer}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    },
    {
     "name": "layer",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "enum": [
       "wellness",
       "biomarkers"
      ]
     }
    }
   ],
   "get": {
    "tags": [
     "Twins"
    ],
    "summary": "Descriptive values of a layer (scope read)",
    "responses": {
     "200": {
      "description": "Layer.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Layer"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/export": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    }
   ],
   "get": {
    "tags": [
     "Twins"
    ],
    "summary": "Export a twin as one JSON document with its SHA-256 (scope read)",
    "responses": {
     "200": {
      "description": "The export; `X-Content-SHA256` is the SHA-256 of exactly the body bytes.",
      "headers": {
       "X-Content-SHA256": {
        "schema": {
         "type": "string",
         "pattern": "^[0-9a-f]{64}$"
        }
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "format",
          "operator",
          "project_id",
          "twin",
          "layers",
          "observations"
         ],
         "properties": {
          "format": {
           "const": "starco-dev-export/v1"
          },
          "operator": {
           "type": "string"
          },
          "project_id": {
           "type": "string",
           "format": "uuid"
          },
          "twin": {
           "$ref": "#/components/schemas/Twin"
          },
          "layers": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Layer"
           }
          },
          "observations": {
           "type": "array",
           "items": {
            "type": "object"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/audit": {
   "get": {
    "tags": [
     "Audit"
    ],
    "summary": "The project's audit chain (scope read)",
    "description": "`row_hash` = SHA-256 of `\"starco-dev-audit/v1\\n\" + project_id + \"\\n\" + seq + \"\\n\" + prev_hash + \"\\n\"` followed by\none line per field (`seq, actor_type, actor_ref, action, resource_type, resource_id, http_status, detail,\ncreated_at`) written `field=<byte length>:<value>`, or `field=~` when null, joined by `\\n`. The first row's\n`prev_hash` is the genesis (64 zeros). The row of the current request is appended after the answer.\n",
    "parameters": [
     {
      "name": "after_seq",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 0,
       "default": 0
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 1000,
       "default": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Rows in chain order.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "project_id": {
           "type": "string",
           "format": "uuid"
          },
          "algorithm": {
           "const": "sha256"
          },
          "hash_input": {
           "type": "string"
          },
          "genesis": {
           "type": "string"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/AuditEvent"
           }
          },
          "next_after_seq": {
           "type": [
            "integer",
            "null"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/audit/verify": {
   "get": {
    "tags": [
     "Audit"
    ],
    "summary": "Verify the project's audit chain on the server (scope read)",
    "responses": {
     "200": {
      "description": "Result of walking the chain.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "ok",
          "events",
          "head_seq",
          "head_hash",
          "first_broken_seq",
          "reason"
         ],
         "properties": {
          "project_id": {
           "type": "string",
           "format": "uuid"
          },
          "ok": {
           "type": "boolean"
          },
          "events": {
           "type": "integer"
          },
          "head_seq": {
           "type": "integer"
          },
          "head_hash": {
           "type": "string"
          },
          "first_broken_seq": {
           "type": [
            "integer",
            "null"
           ]
          },
          "reason": {
           "type": [
            "string",
            "null"
           ],
           "enum": [
            "missing_or_reordered_event",
            "broken_link",
            "content_changed",
            "head_mismatch",
            null
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/schemas": {
   "get": {
    "tags": [
     "Layer schemas"
    ],
    "summary": "Layer schemas of the project, every version (scope read)",
    "parameters": [
     {
      "name": "layer",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Versions, oldest first per layer (without their measures).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/LayerSchema"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Layer schemas"
    ],
    "summary": "Define a custom layer and its measures; posting the same layer again creates its next version (scope write)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "layer",
         "measures"
        ],
        "additionalProperties": false,
        "properties": {
         "layer": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{1,15}$",
          "examples": [
           "study"
          ],
          "description": "Not wellness, biomarkers or another reserved name."
         },
         "description": {
          "type": [
           "string",
           "null"
          ],
          "maxLength": 280
         },
         "measures": {
          "type": "array",
          "minItems": 1,
          "maxItems": 100,
          "items": {
           "$ref": "#/components/schemas/MeasureDefinition"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "The new version (never changed afterwards).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "schema": {
           "$ref": "#/components/schemas/LayerSchema"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "description": "validation_failed with errors [{index?, reason, field}]: layer_invalid, layer_reserved, measures_missing, too_many_measures, measure_name_invalid, measure_duplicate, type_invalid, unit_invalid, bounds_invalid, bound_invalid, enum_invalid, identifier_not_accepted, unknown_field…",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/schemas/{schema}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/SchemaId"
    }
   ],
   "get": {
    "tags": [
     "Layer schemas"
    ],
    "summary": "One layer schema version with its measures (scope read)",
    "responses": {
     "200": {
      "description": "The version.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "schema": {
           "$ref": "#/components/schemas/LayerSchema"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/measures": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    }
   ],
   "get": {
    "tags": [
     "State"
    ],
    "summary": "Every typed measure of the twin, built-in and custom layers (scope read)",
    "responses": {
     "200": {
      "description": "Measures, addressed as <layer>.<measure>.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "twin_id": {
           "type": "string",
           "format": "uuid"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Measure"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/state": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    }
   ],
   "get": {
    "tags": [
     "State"
    ],
    "summary": "The current state of the twin, every measure with a value (scope read)",
    "responses": {
     "200": {
      "description": "Measures without a value are absent (no default, no zero).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "twin_id": {
           "type": "string",
           "format": "uuid"
          },
          "state": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/StateValue"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "State"
    ],
    "summary": "Set several measures at once, all or nothing, with an optional watch (scope write)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "values"
        ],
        "additionalProperties": false,
        "properties": {
         "values": {
          "type": "object",
          "additionalProperties": true,
          "examples": [
           {
            "study.phase": "baseline",
            "study.sessions_done": 3
           }
          ]
         },
         "watch": {
          "$ref": "#/components/schemas/Watch"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "$ref": "#/components/responses/WriteResult"
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "413": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/state/{measure}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    },
    {
     "$ref": "#/components/parameters/Measure"
    }
   ],
   "get": {
    "tags": [
     "State"
    ],
    "summary": "The current value of one measure, with its version as ETag (scope read)",
    "responses": {
     "200": {
      "description": "has_value false and value null when it has none (version 0 if it never had one).",
      "headers": {
       "ETag": {
        "schema": {
         "type": "string"
        },
        "description": "The version, quoted: send it back as If-Match."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StateValue"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "put": {
    "tags": [
     "State"
    ],
    "summary": "Set one measure; with if_version (or If-Match) only if it is still at that version (scope write)",
    "parameters": [
     {
      "name": "If-Match",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "The ETag of a read; same as if_version."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "value"
        ],
        "additionalProperties": false,
        "properties": {
         "value": {
          "description": "Checked against the measure type, unit bounds and enum."
         },
         "if_version": {
          "type": "integer",
          "minimum": 0,
          "description": "0 = only if the measure has no value; n = only if it is at version n."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "$ref": "#/components/responses/StateWrite"
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "description": "version_conflict: current_version and has_value tell what is there now; nothing was changed.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "State"
    ],
    "summary": "Remove the value of one measure (its version still grows; scope write)",
    "parameters": [
     {
      "name": "if_version",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0
      }
     },
     {
      "name": "If-Match",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "examples": [
        "\"3\""
       ]
      },
      "description": "Strong ETag of a read; the same as if_version (both must agree)."
     }
    ],
    "responses": {
     "200": {
      "$ref": "#/components/responses/StateWrite"
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/state/{measure}/incr": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    },
    {
     "$ref": "#/components/parameters/Measure"
    }
   ],
   "post": {
    "tags": [
     "State"
    ],
    "summary": "Add to a number or integer measure within its accepted bounds (scope write)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "by"
        ],
        "additionalProperties": false,
        "properties": {
         "by": {
          "type": "number",
          "description": "A whole number for integer measures; may be negative."
         },
         "if_version": {
          "type": "integer",
          "minimum": 0
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "$ref": "#/components/responses/StateWrite"
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "description": "measure_has_no_value (set one first: no value is never taken as 0) or version_conflict.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/tx": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    }
   ],
   "post": {
    "tags": [
     "State"
    ],
    "summary": "A transaction on the twin, ordered operations applied all or nothing after an optional watch (scope write)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "ops"
        ],
        "additionalProperties": false,
        "properties": {
         "watch": {
          "$ref": "#/components/schemas/Watch"
         },
         "ops": {
          "type": "array",
          "minItems": 1,
          "maxItems": 100,
          "items": {
           "type": "object",
           "required": [
            "op",
            "measure"
           ],
           "properties": {
            "op": {
             "type": "string",
             "enum": [
              "set",
              "incr",
              "del",
              "append"
             ]
            },
            "measure": {
             "type": "string"
            },
            "value": {
             "description": "set"
            },
            "by": {
             "type": "number",
             "description": "incr"
            },
            "if_version": {
             "type": "integer",
             "minimum": 0,
             "description": "set, incr, del"
            },
            "points": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/Point"
             },
             "description": "append: every point must be accepted"
            }
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "$ref": "#/components/responses/WriteResult"
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "description": "watch_failed (conflicts) or version_conflict (op_index): nothing was applied.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "description": "An operation was refused (op_index and reason): nothing was applied.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/history/{measure}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    },
    {
     "$ref": "#/components/parameters/Measure"
    }
   ],
   "get": {
    "tags": [
     "State"
    ],
    "summary": "Every change of one measure, oldest first (scope read)",
    "parameters": [
     {
      "name": "after_version",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0
      }
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The last 1000 changes of each measure are kept.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "twin_id": {
           "type": "string",
           "format": "uuid"
          },
          "measure": {
           "type": "string"
          },
          "data": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "version": {
              "type": "integer"
             },
             "op": {
              "type": "string",
              "enum": [
               "set",
               "incr",
               "del"
              ]
             },
             "old_value": {},
             "new_value": {},
             "actor": {
              "type": [
               "string",
               "null"
              ],
              "description": "Prefix of the key that made the change."
             },
             "transaction_id": {
              "type": "string",
              "format": "uuid"
             },
             "changed_at": {
              "type": "string",
              "format": "date-time"
             }
            }
           }
          },
          "next_after_version": {
           "type": [
            "integer",
            "null"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/series/{measure}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    },
    {
     "$ref": "#/components/parameters/Measure"
    }
   ],
   "get": {
    "tags": [
     "Series"
    ],
    "summary": "The observation series of a numeric measure, raw or in UTC buckets (scope read)",
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "format": "date-time"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "format": "date-time"
      }
     },
     {
      "name": "bucket",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "1m",
        "5m",
        "15m",
        "1h",
        "6h",
        "1d",
        "7d"
       ]
      }
     },
     {
      "name": "agg",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "avg",
        "min",
        "max",
        "sum",
        "count",
        "first",
        "last"
       ]
      }
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 10000
      }
     },
     {
      "name": "fill",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "null"
       ]
      },
      "description": "With bucket, from and to: list empty buckets too, with v null and n 0."
     }
    ],
    "responses": {
     "200": {
      "description": "Points [{t, v}] or buckets [{t, v, n}]; a bucket without points is absent (or v null with fill=null), never 0. n = points read; buckets_expected and buckets_missing with a bucket and both ends.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "twin_id": {
           "type": "string",
           "format": "uuid"
          },
          "measure": {
           "type": "string"
          },
          "unit": {
           "type": "string"
          },
          "bucket": {
           "type": [
            "string",
            "null"
           ]
          },
          "agg": {
           "type": [
            "string",
            "null"
           ]
          },
          "n": {
           "type": "integer"
          },
          "buckets_expected": {
           "type": [
            "integer",
            "null"
           ]
          },
          "buckets_missing": {
           "type": [
            "integer",
            "null"
           ]
          },
          "points": {
           "type": "array",
           "items": {
            "type": "object"
           }
          },
          "truncated": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Series"
    ],
    "summary": "Append points to the series of a numeric measure; they are observations of the twin (scope write)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "points"
        ],
        "additionalProperties": false,
        "properties": {
         "points": {
          "type": "array",
          "minItems": 1,
          "maxItems": 500,
          "items": {
           "$ref": "#/components/schemas/Point"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted and refused points (index, reason); the same reasons as POST /observations.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "twin_id": {
           "type": "string",
           "format": "uuid"
          },
          "measure": {
           "type": "string"
          },
          "batch_id": {
           "type": "string",
           "format": "uuid"
          },
          "accepted": {
           "type": "integer"
          },
          "rejected": {
           "type": "array",
           "items": {
            "type": "object"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "413": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/scenarios/{measure}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    },
    {
     "$ref": "#/components/parameters/Measure"
    }
   ],
   "get": {
    "tags": [
     "Scenarios"
    ],
    "summary": "Experimental: the illustrative scenario of a numeric measure, the twin's own days shifted by a change you declare (scope read)",
    "x-experimental": true,
    "description": "**Experimental**, over synthetic data, computed on the server; it stores nothing. Label of every answer:\n\"Illustrative scenario, not a prediction\".\n\nWhat it does: it takes the days of this twin that have a value of the measure inside a window of UTC days (a\nday's value is the mean of its observations), describes them (`baseline`: mean, min, max, P25, median, P75) and\nmoves their middle half by `declared_change` (`scenario`: `band.low`, `center`, `band.high`), kept inside the\naccepted bounds of the measure (`clamped_to_accepted_bounds` says when that happened). The same series and the\nsame change always give the same answer. The answer carries this summary in words (`method`).\n\nWhat it does not do: it does not predict, it reads no other twin, it uses no reference range and it gives no\nscore, interpretation or health outcome. With fewer than `minimum_days` (7) days with a value in the window,\n`baseline` and `scenario` are `null` and `reason` is `not_enough_days`: never 0, never a typical value.\n\n`input_sha256` and `result_sha256` are the fingerprints of what was read and of what was answered (schema\n`ComputedFingerprints`); the audit row of the call holds `result_sha256`.\n",
    "parameters": [
     {
      "name": "declared_change",
      "in": "query",
      "required": true,
      "schema": {
       "type": "number",
       "examples": [
        0.5
       ]
      },
      "description": "The change you declare, in the unit of the measure; negative to lower, 0 for the band as observed. Plain decimal, at most 6 decimals."
     },
     {
      "name": "window_days",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 14,
       "maximum": 90,
       "default": 28
      },
      "description": "Days of the window."
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "Last UTC day of the window (default: today)."
     }
    ],
    "responses": {
     "200": {
      "description": "The scenario, or baseline and scenario null with reason not_enough_days.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Scenario"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/fits/{measure}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    },
    {
     "$ref": "#/components/parameters/Measure"
    }
   ],
   "get": {
    "tags": [
     "Fits"
    ],
    "summary": "Experimental: statistical fits of a numeric measure, regression curves over the twin's own daily series, side by side and never ranked (scope read)",
    "x-experimental": true,
    "description": "**Experimental**, over synthetic data, computed on the server; it stores nothing. Label of every answer:\n\"Experimental. A statistical fit of this twin's own series: an extrapolation, not a health prediction.\"\n\nWhat it does: it takes the days of this twin that have a value of the measure inside a window of UTC days (a\nday's value is the mean of its observations) and fits each model asked for by ordinary least squares. The\npredictor is time (`x` = the day number in the window, 1 for its first day) unless `x` names another numeric\nmeasure of the same twin, or up to three of them with `model=linear` (multiple linear regression); then a point\nis a day on which every measure involved has a value. Each fit carries its `form`, `coefficients`,\n`statistics` (n, parameters, degrees of freedom, R², adjusted R², residual standard error and the root mean\nsquared error in the unit of the measure), the `fitted` value of every point, and `estimates`: the\n`horizon_days` days after the window (time), or the predictor values listed in `at`, each with a 95 %\nprediction interval for one new value (`interval.t_quantile` and `interval.degrees_of_freedom` say which\nStudent t was used). Exponential and power are fitted to ln y (`fitted_in: ln_y`): their R², adjusted R² and\nresidual standard error refer to ln y, their fitted values and estimates are the exponential of the fitted\nln y, and their interval is the interval of ln y with its ends exponentiated. The same series and the same\nparameters always give the same answer. The answer carries this summary in words (`method`).\n\nWhat it does not do: it does not choose. With `model=all` the six fits come in a fixed order (linear,\nquadratic, cubic, exponential, logarithmic, power), which is not a ranking, and no field marks one as\npreferable: comparing them and choosing is yours. It reads no other twin, uses no reference range and gives no\nscore, interpretation or health outcome. An estimate is an extrapolation of the series and is never clamped:\n`outside_accepted_bounds` says when it leaves the accepted bounds of the measure. The intervals assume the\nlinear model (independent errors of constant variance, normally distributed) and that is not checked.\n\nNull with a reason, never 0 and never a typical value: with fewer than `minimum_days` (7) days, `points` and\n`fits` are `null` and `reason` is `not_enough_days`. A model that is not defined for the series has every\nfigure `null` and its own `reason`: `values_not_positive` (exponential and power need every value above 0),\n`predictor_not_positive` (logarithmic and power need every predictor value above 0), `constant_series`,\n`singular_system` (a constant or collinear predictor, or too few distinct predictor values for the degree),\n`not_enough_points` or `not_finite`.\n\n`input_sha256` and `result_sha256` are the fingerprints of what was read and of what was answered (schema\n`ComputedFingerprints`); the audit row of the call holds `result_sha256`.\n",
    "parameters": [
     {
      "name": "model",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "linear",
        "quadratic",
        "cubic",
        "exponential",
        "logarithmic",
        "power",
        "all"
       ],
       "examples": [
        "linear"
       ]
      },
      "description": "The model to fit, or `all` for the six side by side in that fixed order."
     },
     {
      "name": "x",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "examples": [
        "wellness.steps"
       ]
      },
      "description": "Predictor: one numeric measure of the same twin, or up to three separated by commas with `model=linear`. Left out: time."
     },
     {
      "name": "window_days",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 14,
       "maximum": 90,
       "default": 28
      },
      "description": "Days of the window."
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "Last UTC day of the window (default: today)."
     },
     {
      "name": "horizon_days",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0,
       "maximum": 45,
       "default": 0
      },
      "description": "Future days to estimate, at most half the window. Only with time as the predictor."
     },
     {
      "name": "at",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "examples": [
        "6000;9500"
       ]
      },
      "description": "Only with `x`: up to 10 points to estimate at, separated by semicolons; a point is one plain decimal number per predictor, separated by commas."
     }
    ],
    "responses": {
     "200": {
      "description": "The fits, or points and fits null with reason not_enough_days.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fits"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/cohort/{measure}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/Measure"
    }
   ],
   "get": {
    "tags": [
     "Cohort"
    ],
    "summary": "Experimental: the cohort summary of a numeric measure, the per-twin means of the twins of the project and their distribution, never ranked (scope read)",
    "x-experimental": true,
    "description": "**Experimental**, over synthetic data, computed on the server; it stores nothing. Label of every answer:\n\"Experimental. A description of the twins of this project, in the order they were created: not a ranking, not a\nreference range and not a health assessment.\"\n\nWhat it reads: the twins of the project of the key and no twin of any other project. With `origin`, only the\ntwins created that way (`api`: through `POST /twins`; `synthetic_cohort`: the sample twins a project comes\nwith). At most 200 twins in a call, the largest page of `GET /twins`: a selection of more than 200 is refused\nwith `422 cohort_too_large`, never cut short. This is the one experimental operation that reads several twins;\nscenarios and fits read one.\n\nWhat it does: for each twin, in the order the twins were created, `days_observed` counts the days of the window\nof UTC days that have a value of the measure (a day's value is the mean of its observations) and `mean` is the\nmean of those daily values, to two decimals. For the cohort, `distribution` describes the means of the twins\nthat have one, as the answer shows them: minimum, P25, median, P75, maximum and mean. `histogram.bins` splits\nthe span from that minimum to that maximum into `bins` bins of equal width, with the count of twins in each: a\ntwin is counted in bin floor((mean − min) ÷ (max − min) × bins), counted from 0, computed in double precision,\nand the maximum falls in the last bin; the edges are shown to two decimals; when every mean is the same there\nis one bin. Because the cohort figures are computed from the rows of `twins` as shown, whoever holds the answer\ncan compute them again. The same data and the same parameters always give the same answer. The answer carries\nthis summary in words (`method`).\n\nWhat it does not do: it does not rank the twins, flag any of them or compare one with the rest, and the\ndistribution is this project's own data: it is not a reference range. No score, no interpretation, no health\noutcome, no prediction.\n\nNull with a reason, never 0 and never a typical value: a twin with fewer than `minimum_days` (7) days has a\n`null` mean and the reason `not_enough_days`; a twin without the measure has `null` days and mean and the\nreason `measure_not_in_twin`; a twin whose layer schema defines the measure with another unit or without a\nseries has the reason `measure_differs` (the unit is the one of the first twin that has the measure with a\nseries). When no twin has a mean, `distribution` and `histogram` are `null` and `reason` is\n`no_twin_with_a_value`. When no twin of the selection has the measure at all the answer is `404\nunknown_measure`.\n\n`input_sha256` and `result_sha256` are the fingerprints of what was read and of what was answered (schema\n`ComputedFingerprints`); neither covers a twin id, and the audit row of the call holds `result_sha256`.\n",
    "parameters": [
     {
      "name": "window_days",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 14,
       "maximum": 90,
       "default": 28
      },
      "description": "Days of the window."
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "Last UTC day of the window (default: today)."
     },
     {
      "name": "bins",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 20,
       "default": 8
      },
      "description": "Bins of the histogram."
     },
     {
      "name": "origin",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "api",
        "synthetic_cohort"
       ]
      },
      "description": "Only the twins with this origin (as `GET /twins` shows it). Left out: every twin of the project."
     }
    ],
    "responses": {
     "200": {
      "description": "The summary; distribution and histogram null with reason no_twin_with_a_value when no twin has a mean.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/CohortSummary"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/twins/{twin}/cmd": {
   "parameters": [
    {
     "$ref": "#/components/parameters/TwinId"
    }
   ],
   "post": {
    "tags": [
     "State"
    ],
    "summary": "Command mode, optional terminal sugar over the same operations (scope read; write commands need scope write)",
    "description": "GET, SET [IFVERSION n], MSET, DEL [IFVERSION n], INCRBY, EXISTS, MEASURES [glob], STATE, SERIES.ADD, SERIES.RANGE, HISTORY.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "cmd"
        ],
        "additionalProperties": false,
        "properties": {
         "cmd": {
          "type": "string",
          "examples": [
           "SET"
          ]
         },
         "args": {
          "type": "array",
          "examples": [
           [
            "study.phase",
            "baseline"
           ]
          ]
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "{cmd, result}",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "cmd": {
           "type": "string"
          },
          "result": {}
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/events": {
   "get": {
    "tags": [
     "Events"
    ],
    "summary": "Events of the project after a cursor, with an optional long-poll (scope read)",
    "parameters": [
     {
      "name": "after",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0
      },
      "description": "The seq of the last event received (0 to start); then next_after."
     },
     {
      "name": "wait",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0,
       "maximum": 10
      },
      "description": "Seconds to wait for an event when there is none yet."
     },
     {
      "name": "types",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Comma-separated event types."
     },
     {
      "name": "twin_id",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Events in commit order; a cursor never skips one. Kept 30 days (oldest_seq).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "project_id": {
           "type": "string",
           "format": "uuid"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Event"
           }
          },
          "next_after": {
           "type": "integer"
          },
          "head_seq": {
           "type": "integer"
          },
          "oldest_seq": {
           "type": [
            "integer",
            "null"
           ]
          },
          "retention_days": {
           "type": "integer"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/webhooks": {
   "get": {
    "tags": [
     "Events"
    ],
    "summary": "Webhooks of the project (scope read)",
    "responses": {
     "200": {
      "description": "Webhooks, active and disabled.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Webhook"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Events"
    ],
    "summary": "Add a webhook, an https endpoint that receives the events signed (scope write)",
    "description": "Only https:// on port 443 to a host name whose every address is public (no IP literals, local names,\nprivate, loopback, link-local or metadata addresses); checked now and before every delivery, the connection pinned\nto the checked address, redirects never followed. Each delivery carries X-Starco-Event, X-Starco-Delivery,\nX-Starco-Timestamp and X-Starco-Signature: t=<unix>,v1=hex(HMAC-SHA256(secret, \"<t>.<raw body>\")). Retries after\n30 s, 2 min, 10 min, 1 h and 6 h; then failed.\n",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "url"
        ],
        "additionalProperties": false,
        "properties": {
         "url": {
          "type": "string",
          "format": "uri",
          "examples": [
           "https://hooks.example.com/starco"
          ]
         },
         "event_types": {
          "type": "array",
          "items": {
           "type": "string",
           "enum": [
            "twin.created",
            "twin.deleted",
            "schema.created",
            "state.changed",
            "series.appended"
           ]
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "The webhook and its secret (shown only now).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "webhook": {
           "$ref": "#/components/schemas/Webhook"
          },
          "secret": {
           "type": "string",
           "examples": [
            "whsec_…"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "description": "url_not_https, url_port_not_accepted, url_host_is_an_address, url_host_local, url_host_not_resolvable, url_resolves_to_a_private_address…",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/webhooks/{webhook}": {
   "parameters": [
    {
     "$ref": "#/components/parameters/WebhookId"
    }
   ],
   "get": {
    "tags": [
     "Events"
    ],
    "summary": "One webhook of the project, without its secret (scope read)",
    "responses": {
     "200": {
      "description": "The webhook.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "webhook": {
           "$ref": "#/components/schemas/Webhook"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Events"
    ],
    "summary": "Disable a webhook and cancel its pending deliveries (scope write)",
    "responses": {
     "200": {
      "description": "The webhook, disabled.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "webhook": {
           "$ref": "#/components/schemas/Webhook"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/webhooks/{webhook}/secret/rotate": {
   "parameters": [
    {
     "$ref": "#/components/parameters/WebhookId"
    }
   ],
   "post": {
    "tags": [
     "Events"
    ],
    "summary": "Replace the signing secret of a webhook (scope write)",
    "description": "No body. The new secret is shown only in this answer. The previous secret stops signing for every send that starts after the rotation (a request already on the wire still carries the old signature): there is no\nperiod in which both are valid. Every attempt made from now on is signed with the new secret, including the\nretries of deliveries that were already waiting, so a receiver that rejects a delivery while it still holds the\nold secret gets it again on the retry schedule (30 s, 2 min, 10 min, 1 h, 6 h) and accepts it once it holds the\nnew one. The webhook keeps its id, URL, event types and delivery log. A disabled webhook is refused\n(409 webhook_disabled). If this answer is lost, rotate again: the secret cannot be read back. Always allowed,\nwhatever the plan of the account.\n",
    "responses": {
     "200": {
      "description": "The webhook and its new secret (shown only now).",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "webhook": {
           "$ref": "#/components/schemas/Webhook"
          },
          "secret": {
           "type": "string",
           "examples": [
            "whsec_…"
           ]
          },
          "note": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "403": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     },
     "422": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/webhooks/{webhook}/deliveries": {
   "parameters": [
    {
     "$ref": "#/components/parameters/WebhookId"
    }
   ],
   "get": {
    "tags": [
     "Events"
    ],
    "summary": "Delivery log of a webhook, newest first (scope read)",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 200
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Status, attempts, last HTTP status and stable error code; never the response body.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "webhook_id": {
           "type": "string",
           "format": "uuid"
          },
          "data": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "id": {
              "type": "string",
              "format": "uuid"
             },
             "event_seq": {
              "type": "integer"
             },
             "event_type": {
              "type": "string"
             },
             "status": {
              "type": "string",
              "enum": [
               "pending",
               "sending",
               "retrying",
               "delivered",
               "failed",
               "blocked",
               "cancelled"
              ]
             },
             "attempts": {
              "type": "integer"
             },
             "last_http_status": {
              "type": [
               "integer",
               "null"
              ]
             },
             "last_error": {
              "type": [
               "string",
               "null"
              ]
             },
             "next_attempt_at": {
              "type": [
               "string",
               "null"
              ],
              "format": "date-time"
             },
             "delivered_at": {
              "type": [
               "string",
               "null"
              ],
              "format": "date-time"
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/projects/{project}/mcp-tokens": {
   "parameters": [
    {
     "name": "project",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "format": "uuid"
     }
    }
   ],
   "post": {
    "tags": [
     "Projects"
    ],
    "summary": "Issue a one-hour read-only project MCP token",
    "security": [
     {
      "consoleToken": []
     }
    ],
    "description": "Synthetic projects only. No configurable TTL or scopes. Shown once; list/revoke through project keys. Does not authorize REST or personal MCP.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "One-time secret; Cache-Control no-store",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "key",
          "secret"
         ],
         "properties": {
          "key": {
           "type": "object"
          },
          "secret": {
           "type": "string",
           "pattern": "^starco_dm_[0-9a-f]{8}_[A-Za-z0-9_-]{43}$"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Invalid console token"
     },
     "403": {
      "description": "Requires an owned synthetic project or Origin not allowed"
     },
     "404": {
      "description": "Project not found or API disabled"
     },
     "409": {
      "description": "Active credential quota reached"
     },
     "422": {
      "description": "Parameters are not configurable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/mcp": {
   "get": {
    "summary": "MCP SSE is not offered",
    "security": [
     {
      "projectMcpToken": []
     }
    ],
    "responses": {
     "400": {
      "description": "query_not_allowed: query strings are refused"
     },
     "401": {
      "description": "Invalid MCP token"
     },
     "404": {
      "description": "API disabled"
     },
     "405": {
      "description": "Stateless JSON POST transport only; Allow POST"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "summary": "Read-only synthetic project MCP JSON-RPC",
    "security": [
     {
      "projectMcpToken": []
     }
    ],
    "description": "Streamable HTTP JSON response subset, protocol 2025-06-18. Accept must include application/json and text/event-stream.\nMethods initialize, ping, tools/list and tools/call; initialized/cancelled notifications return empty202.\nTools twins.list, twin.get, layer.get, series.range, history.get, audit.verify. No writes or batches.\nOrigin absent for CLI or exactly allowlisted by operator. Query strings refused.64KiB request bound.\nTool data returned as content and structuredContent; domain errors set isError. Large response errors are explicit.\nNo OAuth discovery, SSE, resumability or server sessions. Do not claim automatic compatibility with every MCP client.\n",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "jsonrpc",
         "method"
        ],
        "properties": {
         "jsonrpc": {
          "const": "2.0"
         },
         "id": {
          "type": [
           "string",
           "integer"
          ]
         },
         "method": {
          "type": "string"
         },
         "params": {
          "type": "object"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "JSON-RPC result or error; application/json"
     },
     "202": {
      "description": "Accepted notification; empty body"
     },
     "400": {
      "description": "Malformed JSON-RPC or unsupported protocol"
     },
     "401": {
      "description": "Invalid, expired or revoked MCP token"
     },
     "403": {
      "description": "Origin not allowlisted"
     },
     "404": {
      "description": "API disabled"
     },
     "406": {
      "description": "Required response types not accepted"
     },
     "413": {
      "description": "Request exceeds64KiB"
     },
     "415": {
      "description": "Requires application/json"
     },
     "429": {
      "description": "Project rate limit"
     }
    }
   }
  }
 },
 "components": {
  "x-error-codes": {
   "conflict": {
    "status": [
     409
    ],
    "meaning": "The requested Cloud link conflicts with the current state. Refresh both sides and review before retrying; no intent is consumed by a refused confirmation."
   },
   "forbidden": {
    "status": [
     403
    ],
    "meaning": "The current account or Cloud intent creator no longer has the authority required for this operation. Check current membership; changing token type does not grant access."
   },
   "validation_failed": {
    "status": [
     422
    ],
    "meaning": "Some fields or parameters are not valid; `errors` says which."
   },
   "unknown_field": {
    "status": [
     422
    ],
    "meaning": "A field the operation does not accept; `field` names it."
   },
   "identifier_field_not_accepted": {
    "status": [
     422
    ],
    "meaning": "A field named like a real identifier (email, phone, ssn…); synthetic data only."
   },
   "identifier_not_accepted": {
    "status": [
     422
    ],
    "meaning": "A text that looks like a real identifier; `looks_like` says what kind."
   },
   "terms_version_mismatch": {
    "status": [
     422
    ],
    "meaning": "accept_terms_version is not the version of GET /terms; `expected` has it."
   },
   "link_invalid": {
    "status": [
     422
    ],
    "meaning": "The verification or recovery link or token is unknown, already used or expired."
   },
   "invalid_credentials": {
    "status": [
     401
    ],
    "meaning": "Wrong address or password, or the address is not verified yet."
   },
   "too_many_sign_in_attempts": {
    "status": [
     429
    ],
    "meaning": "Too many failed sign-ins for this address, whatever the client address; wait Retry-After seconds."
   },
   "auth_rate_limited": {
    "status": [
     429
    ],
    "meaning": "Too many failed authentications (unknown, revoked or expired key or console token) from this address or for this key; wait Retry-After seconds."
   },
   "email_not_verified": {
    "status": [
     403
    ],
    "meaning": "The address of the account must be verified before subscribing."
   },
   "billing_not_configured": {
    "status": [
     503
    ],
    "meaning": "Billing is on but a setting is missing on the server; `missing` names it. Nothing is charged."
   },
   "billing_provider_error": {
    "status": [
     502
    ],
    "meaning": "Stripe did not accept or did not answer the request; nothing changed."
   },
   "billing_cancel_failed": {
    "status": [
     502
    ],
    "meaning": "The subscription or an open checkout could not be closed in Stripe, so the account was not erased."
   },
   "plan_unknown": {
    "status": [
     422
    ],
    "meaning": "No such paid plan or period; `plans` and `periods` list them."
   },
   "plan_not_available": {
    "status": [
     409
    ],
    "meaning": "The price of the plan cannot be read from Stripe or does not fit; `reason` says which."
   },
   "already_subscribed": {
    "status": [
     409
    ],
    "meaning": "The account has a subscription; change or cancel it in the portal."
   },
   "no_billing_customer": {
    "status": [
     404
    ],
    "meaning": "The account has never subscribed: there is no portal for it."
   },
   "no_subscription": {
    "status": [
     404
    ],
    "meaning": "The account has no subscription to cancel."
   },
   "plan_limit_read_only": {
    "status": [
     403
    ],
    "meaning": "The project or twin is over the limits of the account's plan: readable, exportable and erasable, not writable; `over` and `limit` say why."
   },
   "invalid_signature": {
    "status": [
     400
    ],
    "meaning": "Stripe webhook: the Stripe-Signature header does not verify the payload or is too old."
   },
   "malformed_event": {
    "status": [
     400
    ],
    "meaning": "Stripe webhook: the payload is not a Stripe event."
   },
   "password_required": {
    "status": [
     403
    ],
    "meaning": "Erasing the account or a project needs the account password."
   },
   "invalid_token": {
    "status": [
     401
    ],
    "meaning": "Missing or unknown console token."
   },
   "token_revoked": {
    "status": [
     401
    ],
    "meaning": "The console token was revoked."
   },
   "token_expired": {
    "status": [
     401
    ],
    "meaning": "The console token expired; sign in again."
   },
   "invalid_key": {
    "status": [
     401
    ],
    "meaning": "Missing or unknown project key."
   },
   "key_revoked": {
    "status": [
     401
    ],
    "meaning": "The project key was revoked."
   },
   "key_expired": {
    "status": [
     401
    ],
    "meaning": "The project key expired."
   },
   "insufficient_scope": {
    "status": [
     403
    ],
    "meaning": "The key lacks the scope the operation (or the command) needs; `needs` names it."
   },
   "not_found": {
    "status": [
     404
    ],
    "meaning": "No such resource in this account or project (another project's id is also not_found)."
   },
   "project_limit_reached": {
    "status": [
     409
    ],
    "meaning": "The account has the maximum number of projects."
   },
   "project_has_study": {
    "status": [
     409
    ],
    "meaning": "A Studio study is built on the project; it is not erased from the Dev API."
   },
   "key_limit_reached": {
    "status": [
     409
    ],
    "meaning": "The project has the maximum number of active keys and MCP tokens."
   },
   "twin_limit_reached": {
    "status": [
     409
    ],
    "meaning": "The project has the maximum number of twins."
   },
   "schema_limit_reached": {
    "status": [
     409
    ],
    "meaning": "The project has the maximum number of layer schema versions."
   },
   "webhook_limit_reached": {
    "status": [
     409
    ],
    "meaning": "The project has the maximum number of active webhooks."
   },
   "webhook_disabled": {
    "status": [
     409
    ],
    "meaning": "The webhook is disabled: it is never called, so its secret cannot be rotated."
   },
   "unknown_template": {
    "status": [
     422
    ],
    "meaning": "Unknown template; `expected` lists them."
   },
   "template_missing": {
    "status": [
     422
    ],
    "meaning": "Built-in layers need a template."
   },
   "unknown_schema": {
    "status": [
     422
    ],
    "meaning": "No such layer schema in this project."
   },
   "schema_layer_duplicate": {
    "status": [
     422
    ],
    "meaning": "Two schemas of the same layer for one twin."
   },
   "layer_not_enabled": {
    "status": [
     404
    ],
    "meaning": "The twin does not have this layer."
   },
   "unknown_kind": {
    "status": [
     422
    ],
    "meaning": "Unknown observation kind."
   },
   "batch_too_large": {
    "status": [
     413
    ],
    "meaning": "Too many observations or points in one request; `limit` says how many."
   },
   "unknown_measure": {
    "status": [
     404
    ],
    "meaning": "The twin has no such measure (GET /twins/{twin}/measures). Cohort summaries (experimental): no twin of the selection has it."
   },
   "measure_is_derived": {
    "status": [
     422
    ],
    "meaning": "A derived measure is computed, never written."
   },
   "measure_has_no_series": {
    "status": [
     422
    ],
    "meaning": "Only number and integer measures have a series."
   },
   "measure_has_no_value": {
    "status": [
     409
    ],
    "meaning": "incr on a measure without a value."
   },
   "measure_not_numeric": {
    "status": [
     422
    ],
    "meaning": "incr on a measure that is not a number or an integer."
   },
   "increment_not_a_number": {
    "status": [
     422
    ],
    "meaning": "\"by\" is not a number."
   },
   "increment_not_an_integer": {
    "status": [
     422
    ],
    "meaning": "\"by\" is not a whole number for an integer measure."
   },
   "value_missing": {
    "status": [
     422
    ],
    "meaning": "PUT without \"value\"."
   },
   "values_missing": {
    "status": [
     422
    ],
    "meaning": "PATCH /state without \"values\"."
   },
   "value_not_a_number": {
    "status": [
     422
    ],
    "meaning": "The value is not a number."
   },
   "value_not_an_integer": {
    "status": [
     422
    ],
    "meaning": "The value is not a whole number."
   },
   "value_not_a_boolean": {
    "status": [
     422
    ],
    "meaning": "The value is not true or false."
   },
   "value_not_a_string": {
    "status": [
     422
    ],
    "meaning": "The value is not a string."
   },
   "value_not_in_enum": {
    "status": [
     422
    ],
    "meaning": "The value is not one of the measure's values."
   },
   "value_not_json_object_or_array": {
    "status": [
     422
    ],
    "meaning": "A json measure takes an object or an array."
   },
   "value_out_of_accepted_bounds": {
    "status": [
     422
    ],
    "meaning": "Outside the accepted bounds of the measure (what is recordable, never a reference range)."
   },
   "value_too_long": {
    "status": [
     422
    ],
    "meaning": "A string longer than allowed."
   },
   "value_too_large": {
    "status": [
     422
    ],
    "meaning": "A json value larger than allowed once encoded."
   },
   "value_too_deep": {
    "status": [
     422
    ],
    "meaning": "A json value nested deeper than allowed."
   },
   "version_invalid": {
    "status": [
     422
    ],
    "meaning": "if_version or If-Match is not a strong version (e.g. \"3\"), or the two disagree."
   },
   "version_conflict": {
    "status": [
     409
    ],
    "meaning": "The measure is not at the version you sent; `current_version` has it."
   },
   "watch_invalid": {
    "status": [
     422
    ],
    "meaning": "\"watch\" is not an object {\"<layer>.<measure>\": version}."
   },
   "watch_failed": {
    "status": [
     409
    ],
    "meaning": "A watched measure changed; nothing was written."
   },
   "ops_missing": {
    "status": [
     422
    ],
    "meaning": "A transaction without \"ops\"."
   },
   "op_invalid": {
    "status": [
     422
    ],
    "meaning": "An operation that is not an object {op, measure, …}."
   },
   "op_unknown": {
    "status": [
     422
    ],
    "meaning": "An operation other than set, incr, del or append."
   },
   "too_many_operations": {
    "status": [
     413
    ],
    "meaning": "More operations or measures than one transaction takes."
   },
   "points_missing": {
    "status": [
     422
    ],
    "meaning": "An append without points."
   },
   "points_rejected": {
    "status": [
     422
    ],
    "meaning": "Every point of an append was rejected; the reasons come per point."
   },
   "timestamp_invalid": {
    "status": [
     422
    ],
    "meaning": "A time that is not RFC 3339 or a date."
   },
   "range_invalid": {
    "status": [
     422
    ],
    "meaning": "from is not before to."
   },
   "range_too_many_buckets": {
    "status": [
     422
    ],
    "meaning": "The range asks for more buckets than one answer gives."
   },
   "bucket_invalid": {
    "status": [
     422
    ],
    "meaning": "Unknown bucket; `expected` lists them."
   },
   "agg_invalid": {
    "status": [
     422
    ],
    "meaning": "Unknown aggregation; `expected` lists them."
   },
   "agg_needs_bucket": {
    "status": [
     422
    ],
    "meaning": "An aggregation needs a bucket."
   },
   "fill_invalid": {
    "status": [
     422
    ],
    "meaning": "fill=null needs a bucket, from and to."
   },
   "limit_invalid": {
    "status": [
     422
    ],
    "meaning": "limit out of its range."
   },
   "declared_change_invalid": {
    "status": [
     422
    ],
    "meaning": "Scenarios (experimental): declared_change is missing or is not a plain decimal number."
   },
   "window_days_invalid": {
    "status": [
     422
    ],
    "meaning": "Scenarios, fits and cohort summaries (experimental): window_days is not a whole number of days in its range; `expected` has the range."
   },
   "model_invalid": {
    "status": [
     422
    ],
    "meaning": "Fits (experimental): model is missing or is not one of the models; `expected` lists them."
   },
   "predictors_invalid": {
    "status": [
     422
    ],
    "meaning": "Fits (experimental): x is not one to three distinct measure names other than the measure fitted, or names more than one with a model other than linear."
   },
   "horizon_days_invalid": {
    "status": [
     422
    ],
    "meaning": "Fits (experimental): horizon_days is not a whole number of days from 0 to half the window, or was sent with x; `expected` has the range."
   },
   "at_invalid": {
    "status": [
     422
    ],
    "meaning": "Fits (experimental): at was sent without x, or is not up to 10 points of one plain decimal number per predictor."
   },
   "bins_invalid": {
    "status": [
     422
    ],
    "meaning": "Cohort summaries (experimental): bins is not a whole number from 1 to 20; `expected` has the range."
   },
   "origin_invalid": {
    "status": [
     422
    ],
    "meaning": "Cohort summaries (experimental): origin is not one of the origins of a twin; `expected` lists them."
   },
   "cohort_too_large": {
    "status": [
     422
    ],
    "meaning": "Cohort summaries (experimental): the selection has more than 200 twins; `limit` has the number. Nothing is computed over part of a selection."
   },
   "command_unknown": {
    "status": [
     422
    ],
    "meaning": "Unknown command (POST /twins/{twin}/cmd)."
   },
   "command_args_invalid": {
    "status": [
     422
    ],
    "meaning": "Wrong arguments for the command."
   },
   "cursor_invalid": {
    "status": [
     422
    ],
    "meaning": "\"after\" is not the seq of an event."
   },
   "wait_invalid": {
    "status": [
     422
    ],
    "meaning": "\"wait\" out of its range of seconds."
   },
   "types_invalid": {
    "status": [
     422
    ],
    "meaning": "Unknown event type."
   },
   "twin_id_invalid": {
    "status": [
     422
    ],
    "meaning": "twin_id is not a twin id."
   },
   "event_types_invalid": {
    "status": [
     422
    ],
    "meaning": "event_types is not a list of event types."
   },
   "url_invalid": {
    "status": [
     422
    ],
    "meaning": "The webhook URL is missing or not a URL."
   },
   "url_not_https": {
    "status": [
     422
    ],
    "meaning": "Webhooks only go to https URLs."
   },
   "url_port_not_accepted": {
    "status": [
     422
    ],
    "meaning": "Webhooks only go to port 443."
   },
   "url_credentials_not_accepted": {
    "status": [
     422
    ],
    "meaning": "A webhook URL with user or password."
   },
   "url_fragment_not_accepted": {
    "status": [
     422
    ],
    "meaning": "A webhook URL with a #fragment."
   },
   "url_host_invalid": {
    "status": [
     422
    ],
    "meaning": "The host of the webhook URL is not valid."
   },
   "url_host_is_an_address": {
    "status": [
     422
    ],
    "meaning": "IP literals are not accepted; use a host name."
   },
   "url_host_local": {
    "status": [
     422
    ],
    "meaning": "Local host names are not accepted."
   },
   "url_host_not_resolvable": {
    "status": [
     422
    ],
    "meaning": "The host name does not resolve."
   },
   "url_resolves_to_a_private_address": {
    "status": [
     422
    ],
    "meaning": "Some address of the host is not public."
   },
   "synthetic_project_required": {
    "status": [
     403
    ],
    "meaning": "MCP tokens only for a synthetic project."
   },
   "invalid_mcp_token": {
    "status": [
     401
    ],
    "meaning": "Missing, unknown, expired or revoked MCP token."
   },
   "origin_not_allowed": {
    "status": [
     403
    ],
    "meaning": "MCP: an Origin that is not allowlisted."
   },
   "query_not_allowed": {
    "status": [
     400
    ],
    "meaning": "MCP: query strings are refused."
   },
   "request_too_large": {
    "status": [
     413
    ],
    "meaning": "MCP: the request is larger than 64 KiB."
   },
   "mcp_auth_rate_limited": {
    "status": [
     429
    ],
    "meaning": "MCP: too many attempts with unknown tokens."
   },
   "too_many_attempts": {
    "status": [
     429
    ],
    "meaning": "Rate limit of the bucket reached; wait Retry-After seconds."
   },
   "service_unavailable": {
    "status": [
     503
    ],
    "meaning": "GET /status: the database did not reply."
   }
  },
  "securitySchemes": {
   "projectMcpToken": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "starco_dm prefix, one-hour project token"
   },
   "projectKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "Project key: starco_dk_<8 hex>_<43 base64url>. Scopes read and/or write."
   },
   "consoleToken": {
    "type": "http",
    "scheme": "bearer",
    "description": "Console token from POST /sessions: starco_dc_<8 hex>_<43 base64url>, 12 hours."
   }
  },
  "parameters": {
   "ProjectId": {
    "name": "project",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid"
    }
   },
   "SchemaId": {
    "name": "schema",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid"
    }
   },
   "WebhookId": {
    "name": "webhook",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid"
    }
   },
   "Measure": {
    "name": "measure",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "pattern": "^[a-z][a-z0-9_]{1,15}\\.[a-z][a-z0-9_]{0,31}$",
     "examples": [
      "study.phase"
     ]
    },
    "description": "<layer>.<measure>, e.g. wellness.steps or study.phase."
   },
   "TwinId": {
    "name": "twin",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid"
    }
   }
  },
  "headers": {
   "RateLimitLimit": {
    "description": "Requests allowed per minute in this bucket (per IP for the open operations, per account for the console, per project for a key).",
    "schema": {
     "type": "integer"
    }
   },
   "RateLimitRemaining": {
    "description": "Requests left in the current minute.",
    "schema": {
     "type": "integer"
    }
   },
   "RetryAfter": {
    "description": "Seconds to wait before the next request.",
    "schema": {
     "type": "integer"
    }
   }
  },
  "responses": {
   "RateLimited": {
    "description": "too_many_attempts: rate limit of the bucket reached. Wait Retry-After seconds.",
    "headers": {
     "Retry-After": {
      "$ref": "#/components/headers/RetryAfter"
     },
     "X-RateLimit-Limit": {
      "$ref": "#/components/headers/RateLimitLimit"
     },
     "X-RateLimit-Remaining": {
      "$ref": "#/components/headers/RateLimitRemaining"
     }
    },
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "StateWrite": {
    "description": "The new value and version (also as ETag), and the transaction id.",
    "content": {
     "application/json": {
      "schema": {
       "type": "object",
       "properties": {
        "op": {
         "type": "string"
        },
        "measure": {
         "type": "string"
        },
        "value": {},
        "version": {
         "type": "integer"
        },
        "deleted": {
         "type": "boolean"
        },
        "updated_at": {
         "type": "string",
         "format": "date-time"
        },
        "transaction_id": {
         "type": "string",
         "format": "uuid"
        }
       }
      }
     }
    }
   },
   "WriteResult": {
    "description": "Committed, with the result of each operation in order.",
    "content": {
     "application/json": {
      "schema": {
       "type": "object",
       "properties": {
        "twin_id": {
         "type": "string",
         "format": "uuid"
        },
        "committed": {
         "const": true
        },
        "transaction_id": {
         "type": "string",
         "format": "uuid"
        },
        "results": {
         "type": "array",
         "items": {
          "type": "object"
         }
        }
       }
      }
     }
    }
   },
   "Error": {
    "description": "Error envelope.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  },
  "schemas": {
   "CloudAssociationCode": {
    "type": "string",
    "pattern": "^[a-f0-9]{32}$",
    "minLength": 32,
    "maxLength": 32,
    "writeOnly": true,
    "description": "One-use bearer authorization shared by a Cloud organization manager, valid for ten minutes. Never a URL parameter or session token."
   },
   "CloudProjectLink": {
    "type": "object",
    "required": [
     "id",
     "alias",
     "organization",
     "instance",
     "linked_at"
    ],
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "alias": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
     },
     "organization": {
      "type": "string"
     },
     "instance": {
      "type": "string"
     },
     "linked_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "LayerSchema": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "layer": {
      "type": "string"
     },
     "version": {
      "type": "integer"
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "measure_count": {
      "type": "integer"
     },
     "measures": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/MeasureDefinition"
      }
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "MeasureDefinition": {
    "type": "object",
    "required": [
     "name",
     "type"
    ],
    "additionalProperties": false,
    "properties": {
     "name": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]{0,22}$",
      "examples": [
       "phase"
      ]
     },
     "type": {
      "type": "string",
      "enum": [
       "number",
       "integer",
       "boolean",
       "string",
       "enum",
       "json"
      ]
     },
     "unit": {
      "type": [
       "string",
       "null"
      ],
      "description": "Required for number and integer; refused for the others."
     },
     "min": {
      "type": [
       "number",
       "null"
      ],
      "description": "Accepted bounds (validation of what is recordable, never a reference range)."
     },
     "max": {
      "type": [
       "number",
       "null"
      ]
     },
     "enum": {
      "type": [
       "array",
       "null"
      ],
      "items": {
       "type": "string"
      }
     },
     "description": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 280
     },
     "expression": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 200,
      "examples": [
       "round(water_ml / weight_kg, 1)"
      ],
      "description": "Derived (calculated) measure: type number, a unit, no bounds. Numbers, + - * / ( ), min, max, abs, round(x[, 0-6]) and the bare names of stored number/integer measures of the same layer. Recomputed in the same transaction when an input changes; no value when an input has none or on division by zero."
     }
    }
   },
   "Measure": {
    "type": "object",
    "properties": {
     "measure": {
      "type": "string",
      "examples": [
       "study.phase"
      ]
     },
     "layer": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "type": {
      "type": "string"
     },
     "unit": {
      "type": [
       "string",
       "null"
      ]
     },
     "accepted_min": {
      "type": [
       "number",
       "null"
      ]
     },
     "accepted_max": {
      "type": [
       "number",
       "null"
      ]
     },
     "enum": {
      "type": [
       "array",
       "null"
      ],
      "items": {
       "type": "string"
      }
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "builtin": {
      "type": "boolean"
     },
     "has_series": {
      "type": "boolean"
     },
     "derived": {
      "type": "boolean"
     },
     "expression": {
      "type": [
       "string",
       "null"
      ]
     },
     "inputs": {
      "type": "array",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "StateValue": {
    "type": "object",
    "properties": {
     "measure": {
      "type": "string"
     },
     "value": {
      "description": "null = no data"
     },
     "has_value": {
      "type": "boolean"
     },
     "version": {
      "type": "integer"
     },
     "updated_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "updated_by": {
      "type": [
       "string",
       "null"
      ],
      "description": "Prefix of the key that set it."
     }
    }
   },
   "Watch": {
    "type": "object",
    "additionalProperties": {
     "type": "integer",
     "minimum": 0
    },
    "description": "{\"<layer>.<measure>\": version}; 0 = must have no value. Any difference refuses the whole write (409 watch_failed)."
   },
   "Point": {
    "type": "object",
    "required": [
     "t",
     "v"
    ],
    "additionalProperties": false,
    "properties": {
     "t": {
      "type": "string",
      "format": "date-time",
      "examples": [
       "2026-11-18T21:00:00Z"
      ]
     },
     "v": {
      "type": "number"
     }
    }
   },
   "Scenario": {
    "type": "object",
    "description": "Experimental. An illustrative scenario, not a prediction: the twin's own days shifted by a declared change. Null means no data.",
    "properties": {
     "twin_id": {
      "type": "string",
      "format": "uuid"
     },
     "measure": {
      "type": "string",
      "examples": [
       "wellness.sleep_hours"
      ]
     },
     "unit": {
      "type": [
       "string",
       "null"
      ]
     },
     "experimental": {
      "const": true
     },
     "kind": {
      "const": "illustrative_scenario"
     },
     "label": {
      "const": "Illustrative scenario, not a prediction"
     },
     "data_class": {
      "const": "synthetic"
     },
     "window": {
      "type": "object",
      "properties": {
       "from": {
        "type": "string",
        "format": "date"
       },
       "to": {
        "type": "string",
        "format": "date"
       },
       "days": {
        "type": "integer"
       }
      }
     },
     "minimum_days": {
      "type": "integer",
      "description": "Days with a value needed before any figure is given (7)."
     },
     "days_observed": {
      "type": "integer",
      "description": "Days of the window with at least one observation of the measure."
     },
     "days_without_value": {
      "type": "integer"
     },
     "accepted_min": {
      "type": [
       "number",
       "null"
      ],
      "description": "Accepted bounds of the measure: what is recordable, never a reference range."
     },
     "accepted_max": {
      "type": [
       "number",
       "null"
      ]
     },
     "reason": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "not_enough_days",
       null
      ],
      "description": "Why baseline and scenario are null; null when they are given."
     },
     "baseline": {
      "type": [
       "object",
       "null"
      ],
      "description": "The twin's own days with a value in the window, rounded to 2 decimals.",
      "properties": {
       "mean": {
        "type": "number"
       },
       "min": {
        "type": "number"
       },
       "max": {
        "type": "number"
       },
       "p25": {
        "type": "number"
       },
       "median": {
        "type": "number"
       },
       "p75": {
        "type": "number"
       }
      }
     },
     "scenario": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "declared_change": {
        "type": "number"
       },
       "center": {
        "type": "number",
        "description": "The median moved by the declared change."
       },
       "band": {
        "type": "object",
        "properties": {
         "low": {
          "type": "number",
          "description": "P25 moved by the declared change."
         },
         "high": {
          "type": "number",
          "description": "P75 moved by the declared change."
         }
        }
       },
       "clamped_to_accepted_bounds": {
        "type": "boolean"
       }
      }
     },
     "method": {
      "type": "string",
      "description": "What the operation does, in words."
     },
     "input_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 of the canonical text of what the computation read and was asked. See ComputedFingerprints."
     },
     "result_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 of the canonical text of the result. The audit row of the call holds it. See ComputedFingerprints."
     }
    }
   },
   "Fits": {
    "type": "object",
    "description": "Experimental. Statistical fits of a twin's own daily series: an extrapolation, not a health prediction. The fits are in a fixed order and none is ranked. Null means not defined.",
    "properties": {
     "twin_id": {
      "type": "string",
      "format": "uuid"
     },
     "measure": {
      "type": "string",
      "examples": [
       "wellness.sleep_hours"
      ]
     },
     "unit": {
      "type": [
       "string",
       "null"
      ]
     },
     "experimental": {
      "const": true
     },
     "kind": {
      "const": "statistical_fit"
     },
     "label": {
      "const": "Experimental. A statistical fit of this twin's own series: an extrapolation, not a health prediction."
     },
     "data_class": {
      "const": "synthetic"
     },
     "window": {
      "type": "object",
      "properties": {
       "from": {
        "type": "string",
        "format": "date"
       },
       "to": {
        "type": "string",
        "format": "date"
       },
       "days": {
        "type": "integer"
       }
      }
     },
     "predictors": {
      "type": "array",
      "description": "What x is, in order: time (the day number in the window, 1 for its first day) or the measures named in `x`.",
      "items": {
       "type": "object",
       "properties": {
        "kind": {
         "type": "string",
         "enum": [
          "time",
          "measure"
         ]
        },
        "measure": {
         "type": [
          "string",
          "null"
         ]
        },
        "unit": {
         "type": [
          "string",
          "null"
         ]
        }
       }
      }
     },
     "model": {
      "type": "string",
      "enum": [
       "linear",
       "quadratic",
       "cubic",
       "exponential",
       "logarithmic",
       "power",
       "all"
      ],
      "description": "The model asked for."
     },
     "horizon_days": {
      "type": "integer"
     },
     "minimum_days": {
      "type": "integer",
      "description": "Days needed before anything is fitted (7)."
     },
     "days_observed": {
      "type": "integer",
      "description": "Days of the window on which the measure, and every predictor measure, has at least one observation: the n of the fits."
     },
     "days_without_value": {
      "type": "integer"
     },
     "accepted_min": {
      "type": [
       "number",
       "null"
      ],
      "description": "Accepted bounds of the measure: what is recordable, never a reference range."
     },
     "accepted_max": {
      "type": [
       "number",
       "null"
      ]
     },
     "reason": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "not_enough_days",
       null
      ],
      "description": "Why points and fits are null; null when they are given."
     },
     "points": {
      "type": [
       "array",
       "null"
      ],
      "description": "The days fitted, oldest first, to 6 significant digits.",
      "items": {
       "type": "object",
       "properties": {
        "day": {
         "type": "string",
         "format": "date"
        },
        "x": {
         "type": "array",
         "items": {
          "type": "number"
         },
         "description": "One value per predictor."
        },
        "y": {
         "type": "number",
         "description": "The value of the day: the mean of its observations."
        }
       }
      }
     },
     "fits": {
      "type": [
       "array",
       "null"
      ],
      "description": "One per model, in the fixed order linear, quadratic, cubic, exponential, logarithmic, power. The order is not a ranking.",
      "items": {
       "type": "object",
       "properties": {
        "model": {
         "type": "string",
         "enum": [
          "linear",
          "quadratic",
          "cubic",
          "exponential",
          "logarithmic",
          "power"
         ]
        },
        "form": {
         "type": "string",
         "examples": [
          "y = b0 + b1 * x"
         ]
        },
        "fitted_in": {
         "type": "string",
         "enum": [
          "y",
          "ln_y"
         ],
         "description": "The space of the least squares: r_squared, adjusted_r_squared and residual_standard_error refer to it."
        },
        "reason": {
         "type": [
          "string",
          "null"
         ],
         "enum": [
          "not_enough_points",
          "values_not_positive",
          "predictor_not_positive",
          "constant_series",
          "singular_system",
          "not_finite",
          null
         ],
         "description": "Why this model has no figures; null when it has them."
        },
        "coefficients": {
         "type": [
          "object",
          "null"
         ],
         "additionalProperties": {
          "type": "number"
         },
         "description": "The coefficients of `form`, in the units of x and y, to 6 significant digits."
        },
        "statistics": {
         "type": [
          "object",
          "null"
         ],
         "properties": {
          "n": {
           "type": "integer"
          },
          "parameters": {
           "type": "integer",
           "description": "Fitted parameters, the intercept included."
          },
          "degrees_of_freedom": {
           "type": "integer",
           "description": "n minus parameters."
          },
          "r_squared": {
           "type": "number",
           "description": "1 − SSE / SST in the space of `fitted_in`."
          },
          "adjusted_r_squared": {
           "type": "number"
          },
          "residual_standard_error": {
           "type": "number",
           "description": "√(SSE / degrees of freedom) in the space of `fitted_in`."
          },
          "rmse_original_scale": {
           "type": "number",
           "description": "Root mean squared difference between the values and the fitted values, in the unit of the measure, for every model."
          }
         }
        },
        "interval": {
         "type": [
          "object",
          "null"
         ],
         "description": "How the prediction intervals of the estimates were computed.",
         "properties": {
          "level": {
           "const": 0.95
          },
          "t_quantile": {
           "type": "number",
           "description": "The 0.975 quantile of Student's t with these degrees of freedom."
          },
          "degrees_of_freedom": {
           "type": "integer"
          }
         }
        },
        "fitted": {
         "type": [
          "array",
          "null"
         ],
         "items": {
          "type": "number"
         },
         "description": "The fitted value of each point, in the order of `points` and in the unit of the measure."
        },
        "estimates": {
         "type": [
          "array",
          "null"
         ],
         "items": {
          "type": "object",
          "properties": {
           "day": {
            "type": [
             "string",
             "null"
            ],
            "format": "date",
            "description": "The future day (time as the predictor); null for a point of `at`."
           },
           "x": {
            "type": "array",
            "items": {
             "type": "number"
            }
           },
           "estimate": {
            "type": [
             "number",
             "null"
            ],
            "description": "As computed: never clamped to the accepted bounds."
           },
           "interval": {
            "type": [
             "object",
             "null"
            ],
            "properties": {
             "lower": {
              "type": "number"
             },
             "upper": {
              "type": "number"
             }
            }
           },
           "reason": {
            "type": [
             "string",
             "null"
            ],
            "enum": [
             "predictor_not_positive",
             "not_finite",
             null
            ],
            "description": "Why this estimate is null."
           },
           "extrapolated": {
            "type": "boolean",
            "description": "A predictor value is outside the values observed in the window."
           },
           "outside_accepted_bounds": {
            "type": [
             "boolean",
             "null"
            ],
            "description": "The estimate is outside the accepted bounds of the measure."
           }
          }
         }
        }
       }
      }
     },
     "method": {
      "type": "string",
      "description": "What the operation does, in words."
     },
     "input_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 of the canonical text of what the computation read and was asked. See ComputedFingerprints."
     },
     "result_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 of the canonical text of the result. The audit row of the call holds it. See ComputedFingerprints."
     }
    }
   },
   "CohortSummary": {
    "type": "object",
    "description": "Experimental. The per-twin means of a numeric measure over the twins of the project and their distribution: a description, never a ranking and not a reference range. Null means no data.",
    "properties": {
     "project_id": {
      "type": "string",
      "format": "uuid"
     },
     "measure": {
      "type": "string",
      "examples": [
       "wellness.steps"
      ]
     },
     "unit": {
      "type": [
       "string",
       "null"
      ]
     },
     "experimental": {
      "const": true
     },
     "kind": {
      "const": "cohort_summary"
     },
     "label": {
      "const": "Experimental. A description of the twins of this project, in the order they were created: not a ranking, not a reference range and not a health assessment."
     },
     "data_class": {
      "const": "synthetic"
     },
     "window": {
      "type": "object",
      "properties": {
       "from": {
        "type": "string",
        "format": "date"
       },
       "to": {
        "type": "string",
        "format": "date"
       },
       "days": {
        "type": "integer"
       }
      }
     },
     "minimum_days": {
      "type": "integer",
      "description": "Days with a value a twin needs before its mean is given (7)."
     },
     "selection": {
      "type": "object",
      "description": "Which twins were read.",
      "properties": {
       "origin": {
        "type": [
         "string",
         "null"
        ],
        "enum": [
         "api",
         "synthetic_cohort",
         null
        ],
        "description": "The origin asked for; null for every twin of the project."
       },
       "twins": {
        "type": "integer",
        "description": "Twins read."
       },
       "max_twins": {
        "const": 200,
        "description": "The most a call reads. A larger selection is refused."
       }
      }
     },
     "twins": {
      "type": "array",
      "description": "One row per twin read, in the order the twins were created. The order is not a ranking.",
      "items": {
       "type": "object",
       "properties": {
        "twin_id": {
         "type": "string",
         "format": "uuid"
        },
        "label": {
         "type": [
          "string",
          "null"
         ]
        },
        "days_observed": {
         "type": [
          "integer",
          "null"
         ],
         "description": "Days of the window with at least one observation of the measure; null when the twin does not have the measure as the cohort has it."
        },
        "mean": {
         "type": [
          "number",
          "null"
         ],
         "description": "The mean of the daily values, to 2 decimals; null with fewer than minimum_days days."
        },
        "reason": {
         "type": [
          "string",
          "null"
         ],
         "enum": [
          "not_enough_days",
          "measure_not_in_twin",
          "measure_differs",
          null
         ],
         "description": "Why the mean is null; null when it is given."
        }
       }
      }
     },
     "twins_with_value": {
      "type": "integer",
      "description": "Twins with a mean: the n of the distribution."
     },
     "reason": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "no_twin_with_a_value",
       null
      ],
      "description": "Why distribution and histogram are null; null when they are given."
     },
     "distribution": {
      "type": [
       "object",
       "null"
      ],
      "description": "The means of the twins that have one, as shown in `twins`, to 2 decimals. The project's own data: not a reference range.",
      "properties": {
       "min": {
        "type": "number"
       },
       "p25": {
        "type": "number"
       },
       "median": {
        "type": "number"
       },
       "p75": {
        "type": "number"
       },
       "max": {
        "type": "number"
       },
       "mean": {
        "type": "number"
       }
      }
     },
     "histogram": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "bins": {
        "type": "array",
        "description": "Bins of equal width from the minimum to the maximum of the distribution, in order. One bin when every mean is the same.",
        "items": {
         "type": "object",
         "properties": {
          "from": {
           "type": "number",
           "description": "Lower edge, to 2 decimals (the first one is the minimum)."
          },
          "to": {
           "type": "number",
           "description": "Upper edge, to 2 decimals (the last one is the maximum, which is counted in the last bin)."
          },
          "count": {
           "type": "integer",
           "description": "Twins whose mean falls in the bin."
          }
         }
        }
       }
      }
     },
     "method": {
      "type": "string",
      "description": "What the operation does, in words."
     },
     "input_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 of the canonical text of what the computation read and was asked. See ComputedFingerprints."
     },
     "result_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 of the canonical text of the result. The audit row of the call holds it. See ComputedFingerprints."
     }
    }
   },
   "ComputedFingerprints": {
    "type": "object",
    "description": "Experimental. How `input_sha256` and `result_sha256` of a scenario, a fit or a cohort summary are computed, so\nthat whoever holds the same data can compute them again. Both are the SHA-256, in lowercase hexadecimal, of the\nUTF-8 bytes of a **canonical text**.\n\nThe canonical text is JSON written one way only:\n- no whitespace; the keys of an object sorted by their bytes (every key is ASCII); a list in its own order;\n- `null`, `true` and `false` as JSON writes them; a string as JSON writes it, escaping only `\"`, `\\` and the\n  control characters (never `/`, never a non-ASCII character);\n- **a number is never written as a JSON number: it is a string holding its plain decimal expansion**: an\n  optional `-`, the whole part without leading zeros and, only when there is one, `.` and the decimals without\n  trailing zeros. No exponent, no `+`; zero is `\"0\"`. The digits are those of the shortest decimal that reads\n  back as the same IEEE 754 double (what JavaScript's `String(x)` and Python's `repr(x)` print), so 7.0 is\n  `\"7\"`, 0.50 is `\"0.5\"` and 1e-7 is `\"0.0000001\"`.\n\nThe input (`input_sha256`) is the object `{\"format\": \"starco-dev-input/v1\", \"operation\": \"scenario\" | \"fit\" |\n\"cohort\", \"measure\", \"unit\", \"window\": {\"from\", \"to\", \"days\"}, \"parameters\": {…}, …}` with:\n- scenario and fit: `\"accepted_min\"`, `\"accepted_max\"` and `\"series\"`, a list of `{\"measure\", \"days\"}`: the\n  measure itself first and then, for a fit, each predictor measure in the order of `x`. `\"days\"` lists every\n  day of the window with a value, oldest first, as `[\"2026-11-03\", \"7.25\"]`;\n- scenario `\"parameters\"`: `{\"declared_change\"}`; fit: `{\"model\", \"x\", \"horizon_days\", \"at\"}`, where `x` is the\n  list of the predictor names (empty for time) and `at` the list of the points asked for, each a list of numbers;\n- cohort: `\"parameters\": {\"bins\", \"origin\"}` and `\"twins\"`: for each twin read, its `\"days\"` list (or `null`\n  when the twin does not have the measure as the cohort has it), the twins sorted by the bytes of their own\n  canonical text.\nThe value of a day is the mean of its observations in double precision, added in the order of their time\n(`observed_at`, then arrival), **rounded to 6 decimals, half away from zero, on its shortest decimal** (a\ndecimal operation on the digits), and then written by the rule of the numbers.\n\nThe result (`result_sha256`) is the object `{\"format\": \"starco-dev-result/v1\", \"operation\": …}` plus these\nfields of the answer, exactly as the answer has them:\n- scenario: `measure`, `unit`, `window`, `days_observed`, `reason`, `baseline`, `scenario`;\n- fit: `measure`, `unit`, `window`, `predictors`, `model`, `horizon_days`, `days_observed`, `reason`, `points`, `fits`;\n- cohort: `measure`, `unit`, `window`, `twins`, `twins_with_value`, `reason`, `distribution`, `histogram`, with\n  `twin_id` and `label` removed from each row of `twins` and the rows sorted by the bytes of their own\n  canonical text.\n\nNeither text contains the id of a twin or of a project: the same data gives the same fingerprints whatever the\ntwin, and the audit row of the call (`scenarios.show`, `fits.show`, `cohort.show`) says which twin or project,\nwhen, with which key, and holds `result_sha256` in its `detail`. A fingerprint tells whether two inputs or two\nresults are the same. It is not a signature, and it says nothing about whether a result is right.\n",
    "properties": {
     "input_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
     },
     "result_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
     }
    }
   },
   "Event": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "seq": {
      "type": "integer"
     },
     "type": {
      "type": "string",
      "enum": [
       "twin.created",
       "twin.deleted",
       "schema.created",
       "state.changed",
       "series.appended"
      ]
     },
     "project_id": {
      "type": "string",
      "format": "uuid"
     },
     "twin_id": {
      "type": [
       "string",
       "null"
      ],
      "format": "uuid"
     },
     "measure": {
      "type": [
       "string",
       "null"
      ]
     },
     "version": {
      "type": [
       "integer",
       "null"
      ]
     },
     "data": {
      "type": [
       "object",
       "null"
      ]
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Webhook": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "url": {
      "type": "string"
     },
     "event_types": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "secret_prefix": {
      "type": "string"
     },
     "active": {
      "type": "boolean"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "disabled_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "success",
     "code",
     "error"
    ],
    "properties": {
     "success": {
      "const": false
     },
     "code": {
      "type": "string"
     },
     "error": {
      "type": "string"
     }
    }
   },
   "Account": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "email": {
      "type": "string"
     },
     "terms_version": {
      "type": "string"
     },
     "terms_accepted_at": {
      "type": "string",
      "format": "date-time"
     },
     "email_verified_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "plan": {
      "type": "string",
      "description": "The plan in force (GET /billing/plans); `sandbox` is the free one.",
      "examples": [
       "sandbox"
      ]
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "BillingService": {
    "type": "object",
    "description": "What every billing answer says about the service.",
    "properties": {
     "enabled": {
      "type": "boolean"
     },
     "configured": {
      "type": "boolean",
      "description": "False when a setting is missing on the server: nothing can be bought and nothing is charged."
     },
     "missing": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Names of the missing settings, never a value."
     },
     "mode": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "test",
       "live",
       "unknown",
       null
      ],
      "description": "`test` with a key of Stripe's test mode: no real money moves."
     },
     "seller": {
      "type": "string",
      "examples": [
       "STARCO SYSTEMS EUROPE, S.L."
      ]
     },
     "currency": {
      "type": "string",
      "examples": [
       "usd"
      ]
     },
     "tax": {
      "type": "string",
      "enum": [
       "not_computed",
       "stripe_tax"
      ]
     },
     "card_data": {
      "type": "string"
     }
    }
   },
   "PlanLimits": {
    "type": "object",
    "description": "The limits a plan gives; every one is enforced by the server.",
    "properties": {
     "projects_per_account": {
      "type": "integer"
     },
     "active_keys_per_project": {
      "type": "integer"
     },
     "twins_per_project": {
      "type": "integer"
     },
     "observations_per_twin": {
      "type": "integer"
     },
     "webhooks_per_project": {
      "type": "integer"
     },
     "layer_schemas_per_project": {
      "type": "integer"
     },
     "rate_limit_max_per_minute": {
      "type": "integer"
     }
    }
   },
   "PlanPrice": {
    "type": "object",
    "properties": {
     "period": {
      "type": "string",
      "enum": [
       "month",
       "year"
      ]
     },
     "available": {
      "type": "boolean"
     },
     "amount": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Smallest unit of the currency (cents), as Stripe has it. Null when it cannot be read."
     },
     "currency": {
      "type": [
       "string",
       "null"
      ]
     },
     "tax_behavior": {
      "type": [
       "string",
       "null"
      ],
      "description": "Stripe's: inclusive, exclusive or unspecified."
     },
     "reason": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "price_not_configured",
       "billing_not_configured",
       "price_unreadable",
       "price_mismatch",
       null
      ]
     }
    }
   },
   "Plan": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "examples": [
       "sandbox",
       "supporter",
       "builder",
       "team"
      ]
     },
     "free": {
      "type": "boolean"
     },
     "limits": {
      "$ref": "#/components/schemas/PlanLimits"
     },
     "prices": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PlanPrice"
      }
     }
    }
   },
   "Subscription": {
    "type": "object",
    "description": "The subscription as Stripe's signed webhooks confirmed it.",
    "properties": {
     "plan": {
      "type": [
       "string",
       "null"
      ]
     },
     "period": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "month",
       "year",
       null
      ]
     },
     "status": {
      "type": [
       "string",
       "null"
      ],
      "description": "Stripe's: incomplete, incomplete_expired, trialing, active, past_due, canceled, unpaid, paused."
     },
     "cancel_at_period_end": {
      "type": "boolean"
     },
     "current_period_end": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "past_due_since": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "grace_until": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time",
      "description": "While past_due, the plan is kept until this time."
     },
     "ended_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "test_mode": {
      "type": [
       "boolean",
       "null"
      ]
     },
     "confirmed_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time",
      "description": "Time of the last Stripe event applied."
     }
    }
   },
   "Invoice": {
    "type": "object",
    "properties": {
     "id": {
      "type": [
       "string",
       "null"
      ]
     },
     "number": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": [
       "string",
       "null"
      ]
     },
     "currency": {
      "type": [
       "string",
       "null"
      ]
     },
     "amount_due": {
      "type": [
       "integer",
       "null"
      ]
     },
     "amount_paid": {
      "type": [
       "integer",
       "null"
      ]
     },
     "created_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "period_start": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "period_end": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "hosted_invoice_url": {
      "type": [
       "string",
       "null"
      ],
      "description": "The invoice page hosted by Stripe."
     },
     "invoice_pdf": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "Project": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "name": {
      "type": "string"
     },
     "data_class": {
      "type": "string",
      "enum": [
       "synthetic",
       "contracted"
      ],
      "description": "synthetic for every sandbox project; contracted only with a contract and DPA, never through the API."
     },
     "rate_limit_per_minute": {
      "type": "integer"
     },
     "twin_count": {
      "type": "integer"
     },
     "audit_head": {
      "type": "object",
      "properties": {
       "seq": {
        "type": "integer"
       },
       "hash": {
        "type": "string"
       }
      }
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "ConsoleSession": {
    "type": "object",
    "required": [
     "id",
     "current",
     "created_at",
     "last_used_at",
     "expires_at"
    ],
    "properties": {
     "id": {
      "type": "string",
      "pattern": "^starco_dc_[0-9a-f]{8}$",
      "description": "Visible prefix of the console token of the session."
     },
     "current": {
      "type": "boolean",
      "description": "Whether it is the session making this request."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "last_used_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time",
      "description": "null when the token was never used."
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Key": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "name": {
      "type": "string"
     },
     "prefix": {
      "type": "string"
     },
     "scopes": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "read",
        "write"
       ]
      }
     },
     "state": {
      "type": "string",
      "enum": [
       "active",
       "expired",
       "revoked"
      ]
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "revoked_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "last_used_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Twin": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "template": {
      "type": [
       "string",
       "null"
      ],
      "description": "null for a twin made only of custom layers."
     },
     "layers": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Built-in layers."
     },
     "custom_layers": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "layer": {
         "type": "string"
        },
        "schema_id": {
         "type": "string",
         "format": "uuid"
        },
        "version": {
         "type": "integer"
        }
       }
      }
     },
     "label": {
      "type": [
       "string",
       "null"
      ]
     },
     "origin": {
      "type": "string",
      "enum": [
       "api",
       "synthetic_cohort"
      ]
     },
     "data_class": {
      "const": "synthetic"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "ObservationLine": {
    "type": "object",
    "required": [
     "kind",
     "value",
     "unit",
     "observed_at"
    ],
    "additionalProperties": false,
    "properties": {
     "kind": {
      "type": "string",
      "examples": [
       "steps"
      ]
     },
     "value": {
      "type": "number",
      "examples": [
       8432
      ]
     },
     "unit": {
      "type": "string",
      "examples": [
       "steps"
      ]
     },
     "observed_at": {
      "type": "string",
      "format": "date-time",
      "examples": [
       "2026-11-18T21:00:00Z"
      ]
     }
    }
   },
   "BatchResult": {
    "type": "object",
    "required": [
     "batch_id",
     "accepted",
     "rejected",
     "recomputed_layers"
    ],
    "properties": {
     "batch_id": {
      "type": "string",
      "format": "uuid"
     },
     "accepted": {
      "type": "integer"
     },
     "rejected": {
      "type": "array",
      "items": {
       "type": "object",
       "required": [
        "index",
        "reason"
       ],
       "properties": {
        "index": {
         "type": "integer"
        },
        "reason": {
         "type": "string",
         "enum": [
          "line_not_an_object",
          "unknown_field",
          "identifier_field_not_accepted",
          "unknown_kind",
          "layer_not_enabled_on_twin",
          "unit_mismatch",
          "value_not_a_number",
          "value_not_an_integer",
          "value_out_of_accepted_bounds",
          "timestamp_invalid",
          "timestamp_out_of_range",
          "duplicate_in_batch",
          "duplicate_observation",
          "twin_observation_limit_reached"
         ]
        },
        "field": {
         "type": "string"
        },
        "expected": {}
       }
      }
     },
     "recomputed_layers": {
      "type": "array",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "Layer": {
    "type": "object",
    "properties": {
     "twin_id": {
      "type": "string",
      "format": "uuid"
     },
     "layer": {
      "type": "string"
     },
     "template": {
      "type": "string"
     },
     "computed_at": {
      "type": "string",
      "format": "date-time"
     },
     "observation_count": {
      "type": "integer"
     },
     "description": {
      "type": "string"
     },
     "kinds": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "kind": {
         "type": "string"
        },
        "unit": {
         "type": "string"
        },
        "count": {
         "type": "integer"
        },
        "latest": {
         "type": [
          "object",
          "null"
         ],
         "properties": {
          "value": {
           "type": "number"
          },
          "observed_at": {
           "type": "string",
           "format": "date-time"
          }
         }
        },
        "min": {
         "type": [
          "number",
          "null"
         ]
        },
        "max": {
         "type": [
          "number",
          "null"
         ]
        },
        "mean": {
         "type": [
          "number",
          "null"
         ]
        },
        "mean_last_7_days": {
         "type": [
          "number",
          "null"
         ],
         "description": "Mean of the 7 days that end at the latest observation of the kind."
        },
        "first_observed_at": {
         "type": [
          "string",
          "null"
         ],
         "format": "date-time"
        },
        "last_observed_at": {
         "type": [
          "string",
          "null"
         ],
         "format": "date-time"
        }
       }
      }
     }
    }
   },
   "AuditEvent": {
    "type": "object",
    "properties": {
     "seq": {
      "type": "integer"
     },
     "actor_type": {
      "type": "string",
      "enum": [
       "key",
       "console",
       "system",
       "mcp"
      ]
     },
     "actor_ref": {
      "type": [
       "string",
       "null"
      ],
      "description": "Key prefix or account id; never a secret."
     },
     "action": {
      "type": "string"
     },
     "resource_type": {
      "type": [
       "string",
       "null"
      ]
     },
     "resource_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "http_status": {
      "type": [
       "integer",
       "null"
      ]
     },
     "detail": {
      "type": [
       "string",
       "null"
      ],
      "description": "JSON text exactly as hashed."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "prev_hash": {
      "type": "string"
     },
     "row_hash": {
      "type": "string"
     }
    }
   }
  }
 }
}
