openapi: 3.1.0
info:
  title: ComputerWorld Cloud API
  version: 0.1.0
  summary: Hosted, deterministic ComputerWorld environments behind one REST door.
  description: |
    The hosted ComputerWorld API at `/v1/*`, on Computaco's infrastructure. Each environment (one
    running world) runs in a place, Lightning or Heavy, and is kept running while it is used, with its
    last snapshot saved. The web console at `/` calls this API from the same origin with its session cookie.

    **Templates, environments and agents.** An environment boots from a *template* (a world
    definition, built in or the organization's own) or a definition. An *agent* acts in it:
    an *external* agent is a grant (an actor user, machines, action families, observation
    channels) with an *actor token* (`cwa_...`) that can only step, observe, read the scene
    and render through that one agent, never inspect, snapshot or see another; a *simulated*
    agent is one of the people of the environment's *society*, run by the environment itself
    in rounds. A *fork* copies an environment at its current state, society included; the
    parent compares its forks. The organization (signed in with a session cookie, or holding
    an API key) owns its environments and may do anything to them: inspect, snapshot, fork,
    patch a service's state, stage and verify procedures. This is the engine's own
    owner/actor split (`World` vs `Environment`), kept over HTTP.

    **Determinism.** An environment is a pure function of (engine build, definition, seed, the
    actions sent). Every mutating answer carries `state_hash` and `tick`; replaying the same
    requests against an environment booted from the same definition and seed reaches the same
    hashes. The `engine` object in `/v1/health` names the build so a hash is only compared
    within one build.

    **Errors.** Every error is `{ "error": { "code": string, "message": string } }` with an HTTP
    status: 400 `bad_request`, 401 `unauthenticated`, 402 `plan_required` /
    `application_not_purchased`, 403 `forbidden`, 404 `not_found`, 409 `conflict` (e.g. an
    action the engine refused), 413 `too_large`, 422 `invalid_definition` (the engine rejected
    a definition) / `invalid_society` / `invalid_procedure`, 429 `rate_limited` /
    `quota_exceeded` (with `Retry-After`), 500 `engine_error`, 507 `definition_too_large` (the
    environment needs more memory than its place has; fork it to Heavy). A failure on
    our side carries `id`, a support reference, and never the failure's own words.

    **Numbers.** 64-bit integers from the engine (ticks, pids) are JSON numbers when they fit
    in 2^53 and decimal strings otherwise. Hashes are lowercase hex strings.
servers:
  - url: https://computaco.ai
    description: Hosted
  - url: https://dev.computaco.ai
    description: Hosted (the Pages project's own name, an alias of computaco.ai)
security:
  - apiKey: []
  - session: []
tags:
  - name: ingress
    description: Real clients in an environment, as one of its agents - an HTTPS GET of one published service, a stock ssh through cw-ssh-proxy.
  - name: health
  - name: auth
    description: Accounts, sessions and API keys.
  - name: billing
    description: Plans, upgrades through Stripe, and referral codes.
  - name: orgs
    description: Organizations (https://computaco.ai/docs/cloud-api.html § Organizations) — who owns resources and who pays. A session acts in its personal organization unless `x-cw-org` names another; an API key acts in its own.
  - name: templates
    description: The world definitions an environment starts from, built in and the organization's own, and the vocabulary a console offers.
  - name: browser
    description: "A web browser on a simulated Linux machine whose whole screen is the browser (https://computaco.ai/docs/browser.html): one-shot reads of a page, and sessions driven by actions. A session is an environment."
  - name: environments
    description: Running environments (owner calls).
  - name: recordings
    description: Staff recordings of real applications, with the same page and playbar as an environment (https://computaco.ai/docs/cloud-api.html § Recordings).
  - name: topology
    description: What machines an environment or a template has and how they are connected.
  - name: snapshots
  - name: agents
    description: An environment's agents, of three kinds (external grants with actor tokens, hosted agents the platform runs, the society's simulated people), each with a thread; and the actor-facing calls.
  - name: procedures
  - name: society
    description: An environment's simulated people (https://computaco.ai/docs/societies.html), their rounds, and the comparison of its forks.
  - name: harnesses
    description: "What decides an agent's steps (https://computaco.ai/docs/harnesses.html): Computatrum's own harness in three efforts and with each of four quick choosers, the one-call Gemini Flash harness, an organization's scripted harnesses, and research harnesses; each declares what it can do, what it sends and to whom, how slow it is, how long a hosted task may run and the entitlements it requires, and is listed with whether the account may use it and why."
  - name: agent
    description: >
      Computatrum, the desktop computer-use agent: its metered chat and vision calls, the
      device sign-in that gives the app an agent token, its usage windows and pay as you go
      (https://computaco.ai/docs/cloud-api.html § Computatrum).
  - name: perceive
    description: Records read out of pages the caller fetched, read-only (https://computaco.ai/docs/cloud-api.html#perceiving-pages).

paths:
  /v1/health:
    get:
      tags: [health]
      security: []
      summary: Liveness and the engine build.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok: { type: boolean }
                  engine: { $ref: "#/components/schemas/EngineInfo" }
                  outside: { type: boolean, description: "Whether environments may reach the real hosts their definitions name (docs/cloud-api.md § Real hosts)." }

  # ---------------------------------------------------------------- auth
  /v1/auth/signup:
    post:
      tags: [auth]
      security: []
      summary: Create an account (username + password). Sets the session cookie.
      description: |
        Usernames are 3–32 characters of `a-z 0-9 _ -`, case-insensitive. Passwords are 10–200
        characters. The password is stored as PBKDF2-SHA-256 (WebCrypto, 100,000 iterations — the most workerd allows —,
        16-byte random salt). It makes no API key: make one with the session (`POST /v1/keys`),
        as the console does. Rate limited per IP.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/Credentials"
                - type: object
                  properties:
                    email:
                      type: string
                      format: email
                      example: ada@cs.example.edu
                      description: >
                        Optional. Checked before the account is made (a malformed one is a 400 and no account is
                        made), set on the account, and sent a six-digit code (see `POST /v1/me/email`).
                    referral_code:
                      type: string
                      example: FIRST100
                      description: >
                        Optional. A code that exists, is active, has not expired and has places
                        left; it is kept on the account and applied when it upgrades (it is
                        reserved then, not now). Any other code is a 400 `invalid_code`.
      responses:
        "201":
          description: "Created. Sets `cw_session` (HttpOnly; Secure; SameSite=Lax; Path=/)."
          content:
            application/json:
              schema:
                type: object
                required: [user]
                properties:
                  user: { $ref: "#/components/schemas/User" }
                  email:
                    description: With `email` in the request. `sent` is false, with a `message`, when no code could be sent; the account stands.
                    allOf:
                      - $ref: "#/components/schemas/EmailState"
                      - type: object
                        properties:
                          sent: { type: boolean }
                          message: { type: string }
        "400": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/auth/signin:
    post:
      tags: [auth]
      security: []
      summary: Sign in. Sets the session cookie.
      description: Five failures for one username in 15 minutes lock it for the rest of the window (429).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/Credentials" }
      responses:
        "200":
          description: Signed in.
          content:
            application/json:
              schema:
                type: object
                properties:
                  user: { $ref: "#/components/schemas/User" }
        "401": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/auth/signout:
    post:
      tags: [auth]
      security: [{ session: [] }]
      summary: End the session and clear the cookie.
      responses:
        "204": { description: Signed out. }
  /v1/me:
    get:
      tags: [auth]
      summary: The signed-in account, its quotas and its current usage.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  user: { $ref: "#/components/schemas/User" }
                  quotas: { $ref: "#/components/schemas/Quotas" }
                  usage: { $ref: "#/components/schemas/Usage" }
                  billing: { $ref: "#/components/schemas/Billing" }
                  tags: { type: array, items: { $ref: "#/components/schemas/AccountTag" }, description: "The account's tags, each an attestation: who made it, when, the evidence and the expiry." }
                  entitlements: { type: array, items: { $ref: "#/components/schemas/Entitlement" }, description: "What the account's tags that have not expired, and its organization's research program, add up to." }
                  email_verification:
                    type: object
                    properties:
                      pending: { type: [object, "null"], properties: { expires_at: { type: integer } }, description: The code waiting for the account, if any. }
                      free_minutes_blocked: { type: boolean, description: "True while this tier asks free agent minutes for a verified address and the account has none (403 email_verification_required)." }
    patch:
      tags: [auth]
      summary: Set or clear the account's name and date of birth.
      description: >
        Fields left out are kept; null or "" clears one. A name is at most 100 characters
        with no control characters; a date of birth is a real date written yyyy-mm-dd, in the
        past and not before 1900. Any other field is refused with 400, as is an empty object;
        `email` too (the address has its own routes, `POST /v1/me/email`).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ProfilePatch" }
      responses:
        "200":
          description: The account as it is now.
          content:
            application/json:
              schema:
                type: object
                properties:
                  user: { $ref: "#/components/schemas/User" }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
    delete:
      tags: [auth]
      summary: Delete the account and everything it owns.
      description: >
        Deletes the account's environments (with their snapshots, agents, actor tokens and
        societies), its templates and packages, its API keys, its
        sessions, its usage counters and the account itself, at once and for good; the
        username can be taken again. From a session the body must carry the current
        password. With an API key it must carry `confirm`, the account's username, or
        the password. A missing or wrong `confirm` is 400, a wrong password 401. The
        answer clears the session cookie.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                password: { type: string, description: The current password (required from a session). }
                confirm: { type: string, description: "The account's username (with an API key, instead of the password).", example: ada }
      responses:
        "204": { description: Deleted. }
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
  /v1/me/usage:
    get:
      tags: [auth]
      summary: Daily usage, newest first.
      parameters:
        - { name: days, in: query, schema: { type: integer, default: 30, maximum: 90 } }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  days:
                    type: array
                    items:
                      type: object
                      properties:
                        day: { type: string, example: "2026-10-28" }
                        requests: { type: integer }
                        steps: { type: integer }
                        renders: { type: integer }
                        simulations_created: { type: integer }
                        model_calls: { type: integer }
                  professional: { $ref: "#/components/schemas/ProfessionalUsage" }
                  heavy: { $ref: "#/components/schemas/HeavyUsage" }
  /v1/me/email:
    post:
      tags: [auth]
      summary: Set the account's e-mail address and send it a six-digit code.
      description: >
        A different address is unverified at once, and the tags the old one earned are removed. The verified
        address again is a renewal: it stays verified, and its code renews the tag. The code is kept as a
        salted hash, works once, lasts 15 minutes and takes five tries. Limits: one account, one code a
        minute and five an hour; one address, three an hour and six a day; one IP address, ten an hour
        (429 with Retry-After; nothing changes). A send the mail platform refuses is 503 `mail_failed`
        and is not retried. The address is shown to its owner only.
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [email], properties: { email: { type: string, format: email, maxLength: 254 } } }
      responses:
        "202":
          description: The code was sent.
          content:
            application/json:
              schema:
                type: object
                properties:
                  email:
                    allOf:
                      - $ref: "#/components/schemas/EmailState"
                      - type: object
                        properties: { renewal: { type: boolean } }
        "400": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
    delete:
      tags: [auth]
      summary: Remove the address, its code and the tags it earned.
      responses:
        "200":
          description: The account as it is now.
          content:
            application/json:
              schema: { type: object, properties: { user: { $ref: "#/components/schemas/User" }, email: { $ref: "#/components/schemas/EmailState" } } }
  /v1/me/email/verify:
    post:
      tags: [auth]
      summary: Confirm the code. The address is verified, and its domain may give a tag.
      description: >
        A wrong code is 400 `invalid_code` with the tries left; the fifth spends it; a late one is 400
        `code_expired`. An address another account has verified is 409 `email_taken`. At a tier-1
        university's domain the account gets `tier-1-university-student`, at another academic or
        government research domain `academic` (https://computaco.ai/docs/harnesses.html#standing-from-an-e-mail-address),
        attested `by: email`, the domain as evidence, for one year. A tag the operator attested is never replaced.
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [code], properties: { code: { type: string, pattern: "^[0-9]{6}$" } } }
      responses:
        "200":
          description: Verified.
          content:
            application/json:
              schema:
                type: object
                properties:
                  user: { $ref: "#/components/schemas/User" }
                  email: { $ref: "#/components/schemas/EmailState" }
                  standing: { type: [string, "null"], enum: [tier-1, academic, null] }
                  tag: { type: [string, "null"], description: "The tag the address gave, or null." }
        "400": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
  /v1/me/review:
    get:
      tags: [auth]
      summary: The account's review request (the open one, or the last answered) and the standings one may ask for.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  review: { oneOf: [{ $ref: "#/components/schemas/ReviewRequest" }, { type: "null" }] }
                  standings: { type: array, items: { type: object, properties: { tag: { type: string }, meaning: { type: string }, grants: { type: array, items: { $ref: "#/components/schemas/Entitlement" } } } } }
    post:
      tags: [auth]
      summary: Ask ComputaCo for a review of the account's standing. One open request per account.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [standing, statement]
              properties:
                standing: { type: string, enum: [researcher, tier-1-university-faculty, tier-1-university-student, academic] }
                statement: { type: string, minLength: 20, maxLength: 2000, description: "What you are, where, and a public page that shows it." }
      responses:
        "201": { description: Asked., content: { application/json: { schema: { type: object, properties: { review: { $ref: "#/components/schemas/ReviewRequest" } } } } } }
        "400": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
    delete:
      tags: [auth]
      summary: Withdraw the open request.
      responses:
        "204": { description: Withdrawn. }
        "404": { $ref: "#/components/responses/Error" }
  /v1/me/password:
    post:
      tags: [auth]
      security: [{ session: [] }]
      summary: Change the password (signs out every other session).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [current, next]
              properties:
                current: { type: string }
                next: { type: string }
      responses:
        "204": { description: Changed. }
        "401": { $ref: "#/components/responses/Error" }
  /v1/keys:
    get:
      tags: [auth]
      summary: List the account's live API keys (never the secret).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  keys: { type: array, items: { $ref: "#/components/schemas/ApiKey" } }
    post:
      tags: [auth]
      summary: Create an API key with its scopes. The `key` field is shown once.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, maxLength: 60 }
                scopes:
                  type: array
                  minItems: 1
                  items: { $ref: "#/components/schemas/Scope" }
                  description: What the key may reach; every scope when left out. Kept once each, in the order of `Scope`.
      responses:
        "201":
          description: Created.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ApiKeyCreated" }
        "400": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/keys/{key_id}:
    delete:
      tags: [auth]
      summary: Revoke an API key. Takes effect on the next request.
      parameters: [{ $ref: "#/components/parameters/KeyId" }]
      responses:
        "204": { description: Revoked. }
        "404": { $ref: "#/components/responses/Error" }
  /v1/me/invites:
    get:
      tags: [orgs]
      summary: Open invites addressed to the account's verified address, each with the code to accept it.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  invites: { type: array, items: { type: object, properties: { code: { type: string }, org: { $ref: "#/components/schemas/OrgRef" }, role: { $ref: "#/components/schemas/Role" }, expires_at: { type: integer } } } }

  # ---------------------------------------------------------------- organizations
  /v1/orgs:
    get:
      tags: [orgs]
      summary: Every organization the account is in (personal first), and the one this credential acts in.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  orgs: { type: array, items: { $ref: "#/components/schemas/Org" } }
                  current: { type: string }
    post:
      tags: [orgs]
      summary: Make a team organization; the account is its owner. Its personal plan says how many it may create.
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [name], properties: { name: { type: string, minLength: 2, maxLength: 60 } } }
      responses:
        "201": { description: Created., content: { application/json: { schema: { type: object, properties: { org: { $ref: "#/components/schemas/Org" } } } } } }
        "429": { $ref: "#/components/responses/Error" }
  /v1/orgs/join:
    post:
      tags: [orgs]
      summary: Join the organization an invite code names (201; 200 when already a member).
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [code], properties: { code: { type: string, example: cwi_3f2a9c11d4e5b6a7 } } }
      responses:
        "201": { description: Joined., content: { application/json: { schema: { type: object, properties: { org: { $ref: "#/components/schemas/Org" }, already_member: { type: boolean } } } } } }
        "400": { $ref: "#/components/responses/Error" }
        "403": { description: The invite is for another email., content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
  /v1/orgs/invites/{code}:
    get:
      tags: [orgs]
      summary: What an invite code opens, before it is accepted.
      parameters: [{ name: code, in: path, required: true, schema: { type: string } }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { org: { $ref: "#/components/schemas/OrgRef" }, role: { $ref: "#/components/schemas/Role" }, email: { type: [string, "null"] }, expires_at: { type: integer } } } } } }
        "404": { $ref: "#/components/responses/Error" }
  /v1/orgs/{org_id}:
    parameters: [{ $ref: "#/components/parameters/OrgId" }]
    get:
      tags: [orgs]
      summary: The organization, your role, its quotas, billing, usage, bought applications and this month's professional steps (member).
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { org: { $ref: "#/components/schemas/Org" }, role: { $ref: "#/components/schemas/Role" }, quotas: { $ref: "#/components/schemas/Quotas" }, billing: { type: object }, usage: { type: object }, applications: { type: array, items: { $ref: "#/components/schemas/Entitlement" } }, professional: { $ref: "#/components/schemas/ProfessionalUsage" }, heavy: { $ref: "#/components/schemas/HeavyUsage" } } } } } }
        "404": { $ref: "#/components/responses/Error" }
    patch:
      tags: [orgs]
      summary: Rename a team organization (owner).
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [name], properties: { name: { type: string } } } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { org: { $ref: "#/components/schemas/Org" } } } } } }
        "403": { $ref: "#/components/responses/Error" }
    delete:
      tags: [orgs]
      summary: Delete a team organization and everything it owns (owner). The body names it to confirm.
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [confirm], properties: { confirm: { type: string, description: The organization's name. } } } } } }
      responses:
        "204": { description: Deleted. }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
  /v1/orgs/{org_id}/members:
    parameters: [{ $ref: "#/components/parameters/OrgId" }]
    get:
      tags: [orgs]
      summary: The members and their roles (member).
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { members: { type: array, items: { $ref: "#/components/schemas/Member" } } } } } } }
  /v1/orgs/{org_id}/members/{user_id}:
    parameters: [{ $ref: "#/components/parameters/OrgId" }, { name: user_id, in: path, required: true, schema: { type: string } }]
    patch:
      tags: [orgs]
      summary: Change a member's role (owner). The last owner keeps the role (409).
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [role], properties: { role: { $ref: "#/components/schemas/Role" } } } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { members: { type: array, items: { $ref: "#/components/schemas/Member" } } } } } } }
        "409": { $ref: "#/components/responses/Error" }
    delete:
      tags: [orgs]
      summary: Remove a member (admin), or leave (anyone but the last owner).
      responses:
        "204": { description: Removed. }
        "409": { $ref: "#/components/responses/Error" }
  /v1/orgs/{org_id}/invites:
    parameters: [{ $ref: "#/components/parameters/OrgId" }]
    get:
      tags: [orgs]
      summary: The open invites, each with its link (admin).
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { invites: { type: array, items: { $ref: "#/components/schemas/Invite" } } } } } } }
    post:
      tags: [orgs]
      summary: Make an invite (admin). With `email`, only an account with that email accepts it, once.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                role: { type: string, enum: [member, admin], default: member }
                email: { type: string, format: email }
                max_uses: { type: integer, minimum: 1, maximum: 1000 }
                expires_in_days: { type: integer, minimum: 1, maximum: 90, default: 14 }
      responses:
        "201": { description: Created., content: { application/json: { schema: { $ref: "#/components/schemas/Invite" } } } }
        "429": { $ref: "#/components/responses/Error" }
  /v1/orgs/{org_id}/invites/{invite_id}:
    parameters: [{ $ref: "#/components/parameters/OrgId" }, { name: invite_id, in: path, required: true, schema: { type: string } }]
    delete:
      tags: [orgs]
      summary: Revoke an invite (admin).
      responses:
        "204": { description: Revoked. }
        "404": { $ref: "#/components/responses/Error" }
  /v1/orgs/{org_id}/usage:
    parameters: [{ $ref: "#/components/parameters/OrgId" }]
    get:
      tags: [orgs]
      summary: The organization's daily usage, and this month's professional steps.
      parameters: [{ name: days, in: query, schema: { type: integer, minimum: 1, maximum: 90, default: 30 } }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { days: { type: array, items: { type: object } }, professional: { $ref: "#/components/schemas/ProfessionalUsage" }, heavy: { $ref: "#/components/schemas/HeavyUsage" } } } } } }
  /v1/orgs/{org_id}/applications:
    parameters: [{ $ref: "#/components/parameters/OrgId" }]
    get:
      tags: [orgs]
      summary: The professional applications — each with its one-time price and whether this organization has bought it — and whether its plan may buy.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  included: { type: boolean, description: "Staff plan: every application is included; nothing to buy." }
                  can_buy: { type: boolean }
                  plan_required: { type: [string, "null"], example: pro }
                  billing_configured: { type: boolean }
                  applications: { type: array, items: { $ref: "#/components/schemas/Application" } }
                  usage: { $ref: "#/components/schemas/ProfessionalUsage" }
  /v1/orgs/{org_id}/applications/{product}/checkout:
    parameters: [{ $ref: "#/components/parameters/OrgId" }, { name: product, in: path, required: true, schema: { type: string, enum: [kicad, freecad, video] } }]
    post:
      tags: [orgs, billing]
      summary: Buy an application once for the whole organization (admin, paid plan) — a Stripe Checkout URL in payment mode at the catalog's price. The webhook grants it when paid.
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { url: { type: string }, id: { type: string }, product: { type: string }, amount_cents: { type: integer } } } } } }
        "402": { description: plan_required — the organization is on Free., content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "409": { description: Already bought., content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "503": { $ref: "#/components/responses/Error" }
  /v1/orgs/{org_id}/meter:
    parameters: [{ $ref: "#/components/parameters/OrgId" }]
    get:
      tags: [orgs, billing]
      summary: This month's professional steps and the metered-steps settings.
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { professional: { $ref: "#/components/schemas/ProfessionalUsage" }, configured: { type: boolean } } } } } }
    put:
      tags: [orgs, billing]
      summary: Turn metered professional steps on or off and set the monthly cap (admin). The first time on answers `checkout_url` for the payment method.
      requestBody: { content: { application/json: { schema: { type: object, properties: { enabled: { type: boolean }, monthly_cap_usd: { type: number, minimum: 1, maximum: 100000 } } } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { metered: { type: object }, checkout_url: { type: [string, "null"] } } } } } }
        "503": { $ref: "#/components/responses/Error" }

  # ---------------------------------------------------------------- billing
  /v1/plans:
    get:
      tags: [billing]
      security: []
      summary: The plans, their prices and quotas, and whether payment is open.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  billing_configured: { type: boolean, description: "false: upgrades are not open yet (checkout answers 503 billing_not_configured)." }
                  plans: { type: array, items: { $ref: "#/components/schemas/Plan" } }
  /v1/billing/checkout:
    post:
      tags: [billing]
      summary: Start an upgrade — a Stripe Checkout Session for a monthly subscription.
      description: >
        Answers the Checkout URL to send the person to. The account stays on its plan until
        Stripe reports the payment (the webhook's checkout.session.completed). A referral
        code (this body's, or the one kept from sign-up) is checked and one of its places
        reserved for the session's hour; the discount is a Stripe coupon made from it. An
        account already on the plan, or with a subscription, gets 409 (use the portal).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                plan: { type: string, enum: [pro], default: pro }
                referral_code: { type: string, example: FIRST100 }
      responses:
        "200":
          description: The Checkout Session.
          content:
            application/json:
              schema:
                type: object
                properties:
                  url: { type: string, format: uri, example: "https://checkout.stripe.com/c/pay/cs_test_..." }
                  id: { type: string, example: cs_test_a1b2 }
                  discount: { oneOf: [{ $ref: "#/components/schemas/Discount" }, { type: "null" }] }
        "400": { description: "`bad_request` (plan) or `invalid_code` (unknown, inactive, expired, for another plan, used up, or redeemed by this account already).", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "409": { $ref: "#/components/responses/Error" }
        "503": { description: "`billing_error`: the payment service refused the request; or `billing_not_configured`: payment is not open yet; upgrades open soon.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
  /v1/billing/portal:
    post:
      tags: [billing]
      summary: A Stripe Customer Portal session, to change the card, see invoices or cancel.
      responses:
        "200":
          description: The portal session.
          content:
            application/json:
              schema:
                type: object
                properties:
                  url: { type: string, format: uri }
        "409": { description: The account has not been through checkout. }
        "503": { $ref: "#/components/responses/Error" }
  /v1/billing/webhook:
    post:
      tags: [billing]
      security: []
      summary: Stripe's events (configured in Stripe's dashboard, not called by clients).
      description: >
        Verified by `Stripe-Signature` (HMAC-SHA256 of `t.payload` under the endpoint's signing secret,
        timestamp within 300 s); an event id seen before is acknowledged and ignored.
        checkout.session.completed makes the account Pro and redeems its code;
        customer.subscription.updated sets status, renewal and cancel-at-period-end;
        customer.subscription.deleted returns it to Free; invoice.payment_failed marks it
        past due (Pro is kept 7 days, then Free until a payment succeeds);
        checkout.session.expired gives a reserved code's place back.
      parameters:
        - { name: Stripe-Signature, in: header, required: true, schema: { type: string, example: "t=1800000000,v1=5257a8..." } }
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, description: A Stripe Event. }
      responses:
        "200":
          description: Received.
          content:
            application/json:
              schema:
                type: object
                properties:
                  received: { type: boolean }
                  handled: { type: boolean }
                  duplicate: { type: boolean }
        "400": { description: "`bad_signature`." }
        "503": { description: "`billing_not_configured`." }

  /v1/models:
    get:
      tags: [agent]
      security: [{ apiKey: [] }, { session: [] }]
      summary: The agent models, as OpenAI's `GET /v1/models` lists models.
      description: >
        The chat model (`deepseek-flash`: text and tools), the vision model (`glm-5.3-flash`:
        text and images) and the screen model (`gemini-flash`: text and images, the chain of
        Google's Gemini Flash models that reads a screenshot and decides in one call), with
        `served_by` (the model that answers it) and `pricing`: what pay as you
        go charges a million tokens (2.5 times the model's list price). A plan counts
        agent-minutes instead (§ Computatrum).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  object: { type: string, example: list }
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id: { type: string, example: deepseek-flash }
                        object: { type: string, example: model }
                        owned_by: { type: string, example: computaco }
                        served_by: { type: string, example: deepseek-flash }
                        input_modalities: { type: array, items: { type: string, enum: [text, image] } }
                        output_modalities: { type: array, items: { type: string } }
                        tools: { type: boolean }
                        pricing: { type: object, properties: { unit: { type: string }, plan: { type: string }, input: { type: number }, cached_input: { type: number }, output: { type: number } } }
  /v1/chat/completions:
    post:
      tags: [agent]
      security: [{ apiKey: [] }, { session: [] }]
      summary: OpenAI chat completions on any agent model, metered as /v1/agent/chat and /v1/agent/vision are.
      description: >
        An OpenAI client whose base URL is https://computaco.ai calls this unchanged. `model`
        chooses the model (`deepseek-flash` when left out; the providers' own ids are taken too).
        The chat model takes the body /v1/agent/chat takes. The vision model reads `image_url`
        parts given as `data:` URLs of PNG, JPEG or WebP (at most 8, each at most 4 MiB) and
        fetches no URL; `tools`, `tool_choice` and `response_format` are passed on to it. The chat
        model takes `response_format: {type: json_schema}` as DeepSeek can: `json_object`, with the
        schema in a system message first (asked of the model, not enforced). `stream: true` answers
        `text/event-stream`: one `chat.completion.chunk` holding the whole answer as its delta,
        one with `usage` and `metering`, then `[DONE]` (the models are called whole). An unknown
        model is a 404.
      parameters:
        - { $ref: "#/components/parameters/ComputatrumTask" }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [messages]
              properties:
                model: { type: string, enum: [deepseek-flash, glm-5.3-flash, gemini-flash] }
                messages: { type: array, minItems: 1, maxItems: 500, items: { type: object } }
                max_tokens: { type: integer }
                max_completion_tokens: { type: integer }
                temperature: { type: number }
                tools: { type: array, items: { type: object } }
                tool_choice: {}
      responses:
        "200":
          description: The completion, in OpenAI's shape, and what it was charged (`metering`).
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string }
                  object: { type: string, example: chat.completion }
                  model: { type: string }
                  choices: { type: array, items: { type: object } }
                  usage: { type: object, properties: { prompt_tokens: { type: integer }, completion_tokens: { type: integer }, total_tokens: { type: integer }, cached_tokens: { type: integer }, images: { type: integer } } }
                  metering: { $ref: "#/components/schemas/Metering" }
        "400": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /v1/agent/chat:
    post:
      tags: [agent]
      security: [{ apiKey: [] }, { session: [] }, { agentToken: [] }]
      summary: OpenAI-style chat completions for Computatrum's next action, metered.
      description: >
        `model` chooses the chain: `gemini-flash` is the screen model (Google's Gemini Flash), whose messages may hold screenshots as `image_url` parts (data: URLs
        of PNG, JPEG or WebP, at most 8, each at most 4 MiB); anything else is the chat chain
        (DeepSeek's `deepseek-flash`), which reads text only and refuses an image (400).
        DeepSeek's reasoning is off unless `reasoning_effort` asks for it; a call that reasons gets at
        least 2,048 tokens. An empty answer is asked again once with four times the budget and its
        reasoning off; empty again, the answer is a 503 `model_unavailable`.
        `stream: true` is refused. Admitted against the account's 5-hour and weekly windows of
        agent-minutes, or pay as you go when they are used up (or always, in PAYG's `always`
        mode). The windows are charged the call's time plus the gap since its task's previous
        call, up to 15 s (send the task in `X-Computatrum-Task`); pay as you go is charged the
        credits the model reports it used.
      parameters:
        - { $ref: "#/components/parameters/ComputatrumTask" }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [messages]
              properties:
                model: { type: string, enum: [deepseek-flash, gemini-flash], default: deepseek-flash }
                messages: { type: array, minItems: 1, maxItems: 500, items: { type: object, required: [role], properties: { role: { type: string, enum: [system, user, assistant, tool] }, content: { oneOf: [{ type: string }, { type: array, items: { type: object } }, { type: "null" }] } } } }
                max_tokens: { type: integer, minimum: 1, default: 1024, description: More than 8192 is lowered to 8192. }
                temperature: { type: number }
                top_p: { type: number }
                stop: { oneOf: [{ type: string }, { type: array, items: { type: string } }] }
                response_format: { type: object, example: { type: json_object } }
                tools: { type: array, items: { type: object } }
                tool_choice: {}
                reasoning_effort: { type: string, example: low }
                task_id: { type: string, description: The task, if not in X-Computatrum-Task. }
      responses:
        "200":
          description: The completion, in OpenAI's shape, and what it was charged.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string }
                  object: { type: string, example: chat.completion }
                  created: { type: integer }
                  model: { type: string, example: deepseek-flash }
                  choices: { type: array, items: { type: object, properties: { index: { type: integer }, message: { type: object, properties: { role: { type: string }, content: { type: string }, reasoning_content: { type: string } } }, finish_reason: { type: string } } } }
                  usage: { type: object, properties: { prompt_tokens: { type: integer }, completion_tokens: { type: integer }, total_tokens: { type: integer }, cached_tokens: { type: integer } } }
                  metering: { $ref: "#/components/schemas/Metering" }
        "400": { description: "`bad_request`, also when the model refuses the request (nothing is charged).", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "429": { description: "`quota_exceeded`: a window is used up (Retry-After: seconds to its reset) or pay as you go reached its monthly cap; `rate_limited`: requests a minute.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "503": { description: "`model_unavailable` (Retry-After) or `agent_not_configured`.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
  /v1/agent/vision:
    post:
      tags: [agent]
      security: [{ apiKey: [] }, { session: [] }, { agentToken: [] }]
      summary: Ask about a screenshot (what is on it, where a control is), metered.
      description: >
        Answered by the vision model (GLM 5.3 Flash), low reasoning
        effort, temperature 0.1. Coordinates asked for come back in the image's pixels. Admitted
        and charged as chat is.
      parameters:
        - { $ref: "#/components/parameters/ComputatrumTask" }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [image, prompt]
              properties:
                image: { type: string, description: "Base64 PNG, JPEG or WebP (or a data: URL), at most 4 MiB decoded." }
                prompt: { type: string, maxLength: 20000, example: "Give the pixel coordinates (x, y) of the center of the Send button." }
                max_tokens: { type: integer, minimum: 1, default: 512, description: More than 2048 is lowered to 2048. }
                task_id: { type: string, description: The task, if not in X-Computatrum-Task. }
      responses:
        "200":
          description: The answer.
          content:
            application/json:
              schema:
                type: object
                properties:
                  text: { type: string, example: "Send button center: approximately (102, 575)." }
                  model: { type: string, example: "@cf/zai-org/glm-5.3-flash" }
                  usage: { type: object, properties: { prompt_tokens: { type: integer }, completion_tokens: { type: integer }, total_tokens: { type: integer }, images: { type: integer } } }
                  model_ms: { type: integer }
                  metering: { $ref: "#/components/schemas/Metering" }
        "400": { $ref: "#/components/responses/Error" }
        "413": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /v1/agent/decide:
    get:
      tags: [agent]
      security: [{ apiKey: [] }, { session: [] }, { agentToken: [] }]
      summary: The decision models a call without `model` is served by, in the order they are tried, each with whether it is available now.
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { route: { type: array, items: { type: object, properties: { provider: { type: string }, model: { type: string }, configured: { type: boolean } } } } } } } } }
    post:
      tags: [agent]
      security: [{ apiKey: [] }, { session: [] }, { agentToken: [] }]
      summary: Typed choices over a state, with a confidence each, by a decision model, metered.
      description: >
        The quick chooser of Computatrum's harnesses. `model` names one decision model:
        `jev-1.14.0` (TypeSafe), `clef` and `clef-flash` (Cloudflare), `gemini-decision-1`
        (Google). Without `model` the platform chooses (Jev, then Clef). The model writes no text: it picks one option a question and says how sure
        it is. Admitted and charged as chat is.
      parameters:
        - { $ref: "#/components/parameters/ComputatrumTask" }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [state, questions]
              properties:
                model: { type: string, enum: [jev-1.14.0, clef, clef-flash, gemini-decision-1] }
                state: { description: "An object or a string, at most 60,000 characters as JSON: what the decision is about." }
                questions:
                  type: object
                  description: "1 to 8 of {<name>: {type: choice, instructions, criteria: {<option>: <meaning>}}}, 2 to 255 options each, named in letters, digits, space, _ . or -."
                  additionalProperties: { type: object, properties: { type: { type: string, enum: [choice] }, instructions: { type: string, maxLength: 4000 }, criteria: { type: object, additionalProperties: { type: string } } } }
      responses:
        "200":
          description: The picks, the model that made them, and what it was charged.
          content:
            application/json:
              schema:
                type: object
                properties:
                  model: { type: string, example: gemini-decision-1 }
                  provider: { type: string, enum: [typesafe, workers-ai, openrouter, google] }
                  answers: { type: object, additionalProperties: { type: object, properties: { type: { type: string }, choice: { type: string }, confidence: { type: number }, probabilities: { type: object, additionalProperties: { type: number } } } } }
                  usage: { type: object, properties: { prompt_tokens: { type: integer }, completion_tokens: { type: integer }, total_tokens: { type: integer } } }
                  model_ms: { type: integer }
                  metering: { $ref: "#/components/schemas/Metering" }
        "400": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /v1/perceive:
    post:
      tags: [perceive]
      security: [{ apiKey: [] }, { session: [] }]
      summary: Records read out of a page the caller fetched, with the place each value was read from; read-only.
      description: >
        The page is laid out from the HTML sent (its own style sheets, no script, nothing fetched) and read into an
        outline of regions over its words and links; a record is a region that repeats, and the schema's fields are
        matched to what each holds by type and by meaning. When two or more families of regions fit, the chat model is
        asked which hold the schema's records; it writes no value. `budget.max_cost` (US dollars) is never exceeded: a
        read whose model call could cost more is refused with 402. Under the `models` scope; admitted as a model call.
        The contract is seams/contracts/perceive.schema.json (https://computaco.ai/docs/cloud-api.html#perceiving-pages).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/PerceiveRequest" }
      responses:
        "200": { description: The records, in the page's reading order, and their evidence., content: { application/json: { schema: { $ref: "#/components/schemas/PerceiveAnswer" } } } }
        "400": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "408": { $ref: "#/components/responses/Error" }
        "413": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/perceive/batch:
    post:
      tags: [perceive]
      security: [{ apiKey: [] }, { session: [] }]
      summary: Up to 20 page reads, each its own request and budget; a refusal in its place.
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [requests], properties: { requests: { type: array, minItems: 1, maxItems: 20, items: { $ref: "#/components/schemas/PerceiveRequest" } } } }
      responses:
        "200":
          description: One answer a request, in order.
          content:
            application/json:
              schema: { type: object, properties: { answers: { type: array, items: { oneOf: [{ $ref: "#/components/schemas/PerceiveAnswer" }, { type: object, properties: { error: { type: object, properties: { code: { type: string }, message: { type: string } } } } }] } } } }
        "400": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/agent/usage:
    get:
      tags: [agent]
      security: [{ apiKey: [] }, { session: [] }, { agentToken: [] }]
      summary: The 5-hour and weekly windows, pay as you go this month, and the last 30 days by model.
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/AgentUsage" } } } }
  /v1/agent/device:
    post:
      tags: [agent]
      security: []
      summary: Start a device sign-in for the Computatrum app.
      description: Counts against the address's sign-up and sign-in attempts (ten a minute).
      requestBody:
        content:
          application/json:
            schema: { type: object, properties: { client_name: { type: string, maxLength: 60, example: Computatrum on ada-mbp } } }
      responses:
        "200":
          description: The codes. The app shows `user_code`, opens `verification_url`, and polls /v1/agent/device/token every `interval` seconds.
          content:
            application/json:
              schema:
                type: object
                properties:
                  device_code: { type: string, example: "cwd_9f…" }
                  user_code: { type: string, example: BCDF-GHJK }
                  verification_url: { type: string, format: uri, example: "https://computaco.ai/console/#/device?code=BCDF-GHJK" }
                  verification_uri: { type: string, format: uri, example: "https://computaco.ai/console/#/device" }
                  expires_in: { type: integer, example: 900 }
                  interval: { type: integer, example: 5 }
                  client_name: { type: string }
        "429": { $ref: "#/components/responses/Error" }
  /v1/agent/device/token:
    post:
      tags: [agent]
      security: []
      summary: Poll a device sign-in; once approved, the agent token (exactly once).
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [device_code], properties: { device_code: { type: string } } }
      responses:
        "200":
          description: Approved.
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token: { type: string, example: "cwt_4b…" }
                  token_type: { type: string, example: bearer }
                  scope: { type: string, example: agent }
                  token_id: { type: string, example: agt_1a2b3c4d5e6f }
                  user: { type: object, properties: { id: { type: string }, username: { type: string }, plan: { type: string } } }
        "400": { description: "`authorization_pending` (keep polling), `slow_down` (poll less often), `access_denied` (declined), `expired_token` (15 minutes passed), `invalid_grant` (unknown or used), `bad_request`.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
  /v1/agent/device/{user_code}:
    get:
      tags: [agent]
      security: [{ session: [] }]
      summary: A pending sign-in, for the console to show before the person approves it.
      parameters: [{ $ref: "#/components/parameters/UserCode" }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { user_code: { type: string }, client_name: { type: string }, created_at: { type: integer }, expires_at: { type: integer } } } } } }
        "403": { description: Not a console session (a device is never approved with a key). }
        "404": { description: Unknown, expired, or already decided. }
  /v1/agent/device/{user_code}/approve:
    post:
      tags: [agent]
      security: [{ session: [] }]
      summary: Approve a sign-in; the app's next poll gets an agent token for this account.
      parameters: [{ $ref: "#/components/parameters/UserCode" }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { user_code: { type: string }, status: { type: string, enum: [approved] } } } } } }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
  /v1/agent/device/{user_code}/deny:
    post:
      tags: [agent]
      security: [{ session: [] }]
      summary: Decline a sign-in; the app's next poll gets access_denied.
      parameters: [{ $ref: "#/components/parameters/UserCode" }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { user_code: { type: string }, status: { type: string, enum: [denied] } } } } } }
        "404": { $ref: "#/components/responses/Error" }
  /v1/agent/tokens:
    get:
      tags: [agent]
      summary: The apps signed in to this account.
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { tokens: { type: array, items: { type: object, properties: { id: { type: string }, name: { type: string }, created_at: { type: integer }, last_used_at: { type: [integer, "null"] } } } } } } } } }
  /v1/agent/tokens/{token_id}:
    delete:
      tags: [agent]
      summary: Sign an app out; its token stops working at once.
      parameters: [{ name: token_id, in: path, required: true, schema: { type: string }, example: agt_1a2b3c4d5e6f }]
      responses:
        "204": { description: Revoked. }
        "404": { $ref: "#/components/responses/Error" }
  /v1/billing/payg:
    get:
      tags: [billing, agent]
      summary: Computatrum pay-as-you-go settings and this month's spend.
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { payg: { $ref: "#/components/schemas/Payg" }, configured: { type: boolean } } } } } }
    put:
      tags: [billing, agent]
      summary: Turn pay as you go on or off, or set its cap and mode.
      description: >
        Turning it on the first time answers a Stripe Checkout URL for a subscription to the
        metered price (credits at $0.0025, reported to a Billing Meter); it is on once Stripe's
        webhook reports the subscription. Off, cap and mode take effect at once.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled: { type: boolean }
                mode: { type: string, enum: [overflow, always], description: "overflow: after the plan's windows; always: every call." }
                monthly_cap_usd: { type: number, minimum: 1, maximum: 10000, example: 20 }
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { payg: { $ref: "#/components/schemas/Payg" }, checkout_url: { type: [string, "null"], format: uri } } } } } }
        "400": { $ref: "#/components/responses/Error" }
        "503": { description: "`billing_not_configured`." }

  # ---------------------------------------------------------------- templates
  /v1/templates:
    get:
      tags: [templates]
      summary: The templates an environment can start from, built in and the organization's own, in one list.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  templates: { type: array, items: { $ref: "#/components/schemas/Template" } }
    post:
      tags: [templates]
      summary: Save a definition as one of the organization's templates (counts against `templates_max`).
      description: To save a running environment, post its definition (`GET /v1/simulations/{id}/definition`).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [definition]
              properties:
                name: { type: string }
                definition: { $ref: "#/components/schemas/Definition" }
      responses:
        "201":
          description: Saved (validated by the engine first).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Template" }
        "422": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/templates/{template_id}:
    parameters: [{ $ref: "#/components/parameters/TemplateId" }]
    get:
      tags: [templates]
      summary: The template's definition (the world schema, https://computaco.ai/docs/world-schema.html).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Definition" }
    put:
      tags: [templates]
      summary: Replace an own template's definition and/or name (validated by the engine first). A built-in one answers 403.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                definition: { $ref: "#/components/schemas/Definition" }
      responses:
        "200":
          description: Saved.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Template" }
        "403": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
    delete:
      tags: [templates]
      summary: Delete an own template (environments booted from it keep running). A built-in one answers 403.
      responses:
        "204": { description: Deleted. }
        "403": { $ref: "#/components/responses/Error" }
  /v1/templates/{template_id}/topology:
    parameters: [{ $ref: "#/components/parameters/TemplateId" }]
    get:
      tags: [templates, topology]
      summary: The template's topology as a graph (machines, nodes, links, services, themes).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Topology" }
    post:
      tags: [templates, topology]
      summary: Apply topology edits to an own template in order, validate, and save (all or nothing).
      description: |
        The topology editor sends these. The edits apply to the definition in order; the result
        is validated by the engine (booted and dropped); on any error nothing is saved and the
        answer says which edit failed. A built-in template answers 403: save a copy first.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [edits]
              properties:
                edits: { type: array, items: { $ref: "#/components/schemas/TopologyEdit" } }
      responses:
        "200":
          description: Saved; the new topology.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Topology" }
        "403": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /v1/templates/{template_id}/procedures:
    parameters: [{ $ref: "#/components/parameters/TemplateId" }]
    get:
      tags: [templates, procedures]
      summary: The expert procedures shipped with a built-in template (https://computaco.ai/docs/expert-procedures.html).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  procedures:
                    type: array
                    items:
                      type: object
                      properties:
                        template: { type: string }
                        id: { type: string }
                        domain: { type: string }
                        instruction: { type: string }
                        roles: { type: array, items: { type: string } }
                        phases: { type: integer }
                        app_modules: { type: array, items: { type: string }, description: The application modules its phases launch. }
                        host: { type: [string, "null"], description: The Lightning place an environment booted for it runs in; null when none carries its applications (`unhosted` names them). }
                        unhosted: { type: array, items: { type: string } }
  /v1/templates/{template_id}/procedures/{procedure_id}:
    parameters: [{ $ref: "#/components/parameters/TemplateId" }, { name: procedure_id, in: path, required: true, schema: { type: string } }]
    get:
      tags: [templates, procedures]
      summary: One shipped procedure, whole.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Procedure" }
  /v1/templates/{template_id}/procedures/{procedure_id}/instantiate:
    parameters: [{ $ref: "#/components/parameters/TemplateId" }, { name: procedure_id, in: path, required: true, schema: { type: string } }]
    post:
      tags: [procedures]
      summary: Draw a shipped procedure's parameters from a seed (stateless).
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                seed: { type: integer, default: 1 }
                overrides: { type: object }
      responses:
        "200":
          description: The instance.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ProcedureInstance" }
  /v1/templates/{template_id}/societies:
    parameters: [{ $ref: "#/components/parameters/TemplateId" }]
    get:
      tags: [templates, society]
      summary: The society specs shipped with a built-in template (https://computaco.ai/docs/societies.html).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  societies:
                    type: array
                    items:
                      type: object
                      properties:
                        template: { type: string }
                        id: { type: string }
                        people: { type: integer, description: Named people plus population counts. }
                        rounds: { type: integer }
                        arms: { type: array, items: { type: string }, description: "The spec's arms: each one's `ops` is what a fork's `society_ops` takes." }
                        journal: { type: [string, "null"], description: "The journal of model replies recorded beside it (`journal: builtin` at boot replays it)." }
  /v1/templates/{template_id}/societies/{society_id}:
    parameters: [{ $ref: "#/components/parameters/TemplateId" }, { name: society_id, in: path, required: true, schema: { type: string } }]
    get:
      tags: [templates, society]
      summary: One shipped society spec, whole.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SocietySpec" }
  /v1/vocabulary:
    get:
      tags: [templates]
      security: []
      summary: The closed vocabularies a console's pickers offer (no credential needed).
      description: Platforms (desktop themes), presentations, service kinds, action families, observation channels, link fields, applications and the professional products, the places deployed (`places`), and the hosts with the application modules each carries.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  platforms: { type: array, items: { type: string }, example: [macos, windows, ubuntu, ios, android] }
                  platforms_available: { type: array, items: { type: string }, description: The platforms the hosted API draws; a definition naming another platform is refused at boot. }
                  presentations: { type: array, items: { type: string }, example: [desktop, laptop, phone, server] }
                  service_kinds: { type: array, items: { type: string } }
                  action_families: { type: array, items: { type: string } }
                  observation_channels: { type: array, items: { type: string } }
                  link_fields: { type: object }
                  zones: { type: array, items: { type: string }, example: [local, internet, host] }
                  internet_attachments: { type: array, items: { type: string } }
                  applications: { type: array, items: { type: string }, description: Application kinds `application.v1 launch` takes. }
                  applications_detail: { type: array, items: { type: object } }
                  products: { type: array, items: { type: object } }
                  places: { type: array, items: { $ref: "#/components/schemas/Place" }, description: "The places deployed with this API (https://computaco.ai/docs/cloud-api.html § Places): what `place` may name." }
                  hosts: { type: object, description: "Each place's application modules, and whether it is deployed." }
  /v1/validate:
    post:
      tags: [templates]
      summary: Validate a definition, and compile a society over it, without keeping either.
      description: |
        Size-checked (quota `definition_bytes`), schema-checked, then booted by the engine with
        seed 0 and dropped. With `society`, the spec is compiled over the definition (or the
        template's) first, as a boot would, and the answer adds the people count and the
        compiled definition's size; a society over `society_people_max` is a 429, a spec that
        does not compile a 422 `invalid_society`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                definition: { $ref: "#/components/schemas/Definition" }
                template: { type: string, description: With `society`, in place of `definition`. }
                society: { $ref: "#/components/schemas/SocietyBoot" }
                seed: { type: integer }
      responses:
        "200":
          description: The verdict.
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok: { type: boolean }
                  errors: { type: array, items: { type: string } }
                  machines: { type: integer }
                  services: { type: integer }
                  boot_ms: { type: number }
                  people: { type: integer, description: With `society`. }
                  seed: { type: integer, description: With `society`. }
                  definition_bytes: { type: integer, description: With `society`, the compiled definition's size. }

  # ---------------------------------------------------------------- environments
  /v1/simulations:
    get:
      tags: [environments]
      summary: The organization's environments.
      description: Each row names its `place`.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  simulations: { type: array, items: { $ref: "#/components/schemas/SimulationSummary" } }
    post:
      tags: [environments]
      summary: Boot an environment from a template or a definition, optionally with a society.
      description: |
        Exactly one of `template` (a built-in template's name or an own template's id) and
        `definition`. `platform` redraws every machine as that desktop (it sets
        `metadata.desktop_themes`). `procedure` boots the environment for that procedure: its
        machines get the desktops it names (as `Procedure::prepare` does), and the environment
        goes to a place carrying the applications it launches. `place` names where it runs
        (https://computaco.ai/docs/cloud-api.html § Places): `lightning` or `heavy`, a Lightning
        place's id, or a list tried in order. Left out, Lightning comes first (the place carrying
        most of what the machines can launch, core on a tie) and then Heavy; Heavy comes first
        only for a stated reason. A refusal that is the
        place's own (402 `plan_required`, 429 `quota_exceeded`, 507 `definition_too_large`)
        moves to the next place, and the last place's refusal is the answer. The answer's
        `place` says where it runs and why, and `refused` what was passed over. With `society`, the spec is
        compiled into the definition (its people's devices and accounts) and its runner starts
        in the environment. A person whose policy is `{kind: "harness", harness}` is checked as a
        hosted agent's harness is: 400 for an id of the wrong form, 404 `harness_not_found`, 403
        `harness_access_required` when the caller may not use it. Counts against `simulations_max`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                template: { type: string, example: agent-desktop }
                definition: { $ref: "#/components/schemas/Definition" }
                seed: { type: integer, default: 1 }
                platform: { type: string, enum: [macos, windows, ubuntu, ios, android] }
                procedure:
                  description: A procedure to boot the environment for, `{template, id}` (shipped with a built-in template) or inline.
                  oneOf: [{ type: object, properties: { template: { type: string }, id: { type: string } } }, { $ref: "#/components/schemas/Procedure" }]
                place: { $ref: "#/components/schemas/PlaceChoice" }
                idle_ttl:
                  type: integer
                  minimum: 60
                  maximum: 86400
                  description: >
                    Seconds with no request to the environment after which it deletes itself, as
                    DELETE /v1/simulations/{id} does, and gives its place under `simulations_max`
                    back. Any request that reaches it (an owner's or an actor token's) starts the
                    time again. Left out, it is kept until it is deleted.
                society: { $ref: "#/components/schemas/SocietyBoot" }
      responses:
        "201":
          description: Booted.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SimulationPlaced" }
        "400": { $ref: "#/components/responses/Error" }
        "402": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
        "507": { $ref: "#/components/responses/Error" }
  /v1/simulations/import:
    post:
      tags: [environments, snapshots]
      summary: Boot a new environment from an export. Its external agents come back with new tokens.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              description: "The form `GET /v1/simulations/{id}/export` returns (`bundle` and `snapshot`), and optionally `options`."
              required: [bundle, snapshot]
              properties:
                bundle: { type: object, description: "The bundle part of the export, as JSON." }
                snapshot: { type: string, format: binary, description: The engine's portable snapshot (application/octet-stream). }
                options:
                  type: object
                  description: What to boot it as, as JSON.
                  properties:
                    name: { type: string }
                    place: { $ref: "#/components/schemas/PlaceChoice" }
                    idle_ttl: { type: integer }
      responses:
        "201":
          description: Imported.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SimulationPlaced"
                  - type: object
                    properties:
                      agents: { type: array, items: { $ref: "#/components/schemas/AgentCreated" } }
  /v1/simulations/{simulation_id}:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [environments]
      summary: An environment's summary, with its place, its head, its forks and the environment it was forked from.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Simulation" }
    patch:
      tags: [environments]
      summary: Rename the environment.
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [name], properties: { name: { type: string, maxLength: 200 } } }
      responses:
        "200":
          description: Renamed.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Simulation" }
    delete:
      tags: [environments]
      summary: Delete the environment, its snapshots, its agents (their tokens stop working) and its society. Its forks keep running.
      responses:
        "204": { description: Deleted. }
  /v1/simulations/{simulation_id}/history:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [snapshots]
      summary: The history of the environment's family, read without waking any environment.
      description: |
        The family is the furthest ancestor still here and every fork below it. Each
        environment comes with its place, its parent, where it left its parent (`origin`), its
        head and its snapshots; a snapshot names its `parent`, so the answer is the whole
        graph. A deleted environment leaves it.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/History" }
  /v1/simulations/{simulation_id}/state_hash:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [environments]
      summary: The environment's state hash and tick.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Clock" }
  /v1/simulations/{simulation_id}/advance:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [environments]
      summary: Move the environment's clock forward (timers, settlement windows, queues fire).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ticks: { type: integer, minimum: 0, description: Logical microseconds. }
                duration: { type: string, example: 1h, description: "Alternative to `ticks`: `500ms`, `30s`, `5m`, `2h`, `1d`." }
      responses:
        "200":
          description: Advanced.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Clock" }
  /v1/simulations/{simulation_id}/reset:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [environments]
      summary: Reset to the definition with a (new) seed. External agents are dropped.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                seed: { type: integer }
      responses:
        "200":
          description: Reset.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Clock" }
  /v1/simulations/{simulation_id}/files:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { name: path, in: query, required: true, schema: { type: string, example: /home/ada/notes.txt }, description: An absolute path on the machine. }
      - { name: machine, in: query, schema: { type: string, example: workstation }, description: The machine; may be left out when the environment has one. }
    get:
      tags: [environments]
      summary: The owner reads a file on a machine.
      description: >
        Read through the owner's file session on the machine: a session of the machine's
        user granted only `filesystem.v1`, made on the first file call and kept in the environment's
        state (a fork carries it, a reset drops it). No actor token reaches this route. A path
        that is not a readable file (absent, or a directory) is a 404: the engine does not say
        which. At most 4 MiB.
      responses:
        "200":
          description: The file.
          content:
            application/json:
              schema:
                type: object
                properties:
                  machine: { type: string }
                  path: { type: string }
                  content: { type: string, description: The bytes as UTF-8 (lossy). }
                  base64: { type: string, format: byte, description: The exact bytes. }
                  bytes: { type: integer }
        "400": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "413": { $ref: "#/components/responses/Error" }
    put:
      tags: [environments]
      summary: The owner writes a file onto a machine.
      description: Exactly one of `content` (text) or `base64` (bytes); at most 4 MiB. Recorded in the environment's trajectory like any action.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                content: { type: string }
                base64: { type: string, format: byte }
      responses:
        "200":
          description: Written.
          content:
            application/json:
              schema:
                allOf:
                  - { $ref: "#/components/schemas/Clock" }
                  - type: object
                    properties:
                      machine: { type: string }
                      path: { type: string }
                      bytes: { type: integer }
        "400": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "413": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/inspect:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [environments]
      summary: The owner's view of the whole state (`World.inspect()`).
      parameters:
        - { name: pointer, in: query, schema: { type: string }, description: "A JSON Pointer into the answer (`/state/services/mail/state`); only that value is returned." }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { type: object }
  /v1/simulations/{simulation_id}/definition:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [environments]
      summary: The definition the environment was booted from (with live machine additions); what `POST /v1/templates` saves.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Definition" }
  /v1/simulations/{simulation_id}/trajectory:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [environments]
      summary: Every action the environment has taken, in order (the replay journal).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { type: object }
  /v1/simulations/{simulation_id}/services/{service_id}/state:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { name: service_id, in: path, required: true, schema: { type: string } }
    get:
      tags: [environments]
      summary: One service's state.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { type: object }
    patch:
      tags: [environments]
      summary: An owner write to a service's state (JSON merge patch), recorded so a replay repeats it.
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object }
      responses:
        "200":
          description: Patched.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Clock" }
  /v1/simulations/{simulation_id}/perform:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [environments, procedures]
      summary: Perform one grounded gesture through an external agent's session (`World.perform`).
      description: The engine finds the target on the session's screen the way a procedure does and sends the steps; the answer lists them.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [agent, gesture]
              properties:
                agent: { type: string, example: agent_1 }
                gesture: { $ref: "#/components/schemas/Gesture" }
                options:
                  type: object
                  properties:
                    width: { type: integer, default: 1280 }
                    height: { type: integer, default: 800 }
      responses:
        "200":
          description: Performed.
          content:
            application/json:
              schema:
                type: object
                properties:
                  steps: { type: array, items: { type: object } }
                  state_hash: { type: string }
                  tick: { type: integer }

  # ---------------------------------------------------------------- recordings (staff)
  /v1/recordings:
    get:
      tags: [recordings]
      summary: The recordings of real applications, for staff. For anyone else the list is empty.
      description: |
        Each recording has ids `r~<run>~<job>` and is read-only
        (https://computaco.ai/docs/cloud-api.html § Recordings).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  recordings: { type: array, items: { $ref: "#/components/schemas/Recording" } }
  /v1/recordings/{recording_id}:
    parameters: [{ $ref: "#/components/parameters/RecordingId" }]
    get:
      tags: [recordings]
      summary: A recording's summary, for staff (404 for anyone else).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RecordingDetail" }
  /v1/recordings/{recording_id}/topology:
    parameters: [{ $ref: "#/components/parameters/RecordingId" }]
    get:
      tags: [recordings, topology]
      summary: The recording's machines, each with its kind and interfaces.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Topology" }
  /v1/recordings/{recording_id}/history:
    parameters: [{ $ref: "#/components/parameters/RecordingId" }]
    get:
      tags: [recordings]
      summary: The steps of the recording, one moment for each.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RecordingHistory" }

  # ---------------------------------------------------------------- topology (running environment)
  /v1/simulations/{simulation_id}/topology:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [topology]
      summary: The running environment's topology (machines, each with its kind and interfaces; nodes, links, services, themes).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Topology" }
  /v1/simulations/{simulation_id}/machines:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [topology]
      summary: Add a machine to the running environment, wired explicitly (`World.addComputer`).
      description: |
        The only topology change a running environment takes live. Its links, services and
        themes are fixed at boot: save it as a template (`POST /v1/templates`), edit that
        (`POST /v1/templates/{id}/topology`) and boot it.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [computer]
              properties:
                computer: { $ref: "#/components/schemas/Computer" }
                node: { $ref: "#/components/schemas/Node" }
                links: { type: array, items: { $ref: "#/components/schemas/Link" } }
                theme: { type: string, enum: [macos, windows, ubuntu, ios, android] }
      responses:
        "201":
          description: Added; the new topology.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Topology" }
        "409": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/machines/{machine_id}:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { name: machine_id, in: path, required: true, schema: { type: string } }
    delete:
      tags: [topology]
      summary: Remove a machine from the running environment (`World.removeComputer`).
      responses:
        "200":
          description: Removed; the new topology.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Topology" }

  # ---------------------------------------------------------------- snapshots
  /v1/simulations/{simulation_id}/snapshots:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [snapshots]
      summary: The environment's kept snapshots, oldest first, and its head.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Snapshots" }
    post:
      tags: [snapshots]
      summary: Take a snapshot (kept in the environment's storage; counts against `snapshots_per_simulation`).
      description: Its `parent` is the head, and it becomes the head. A picture of each machine an agent is connected to is kept with it (`frames`).
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                label: { type: string }
      responses:
        "201":
          description: Taken.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Snapshot"
                  - type: object
                    properties:
                      head: { type: string, description: Its own id. }
                      elapsed_ms: { type: number }
  /v1/simulations/{simulation_id}/snapshots/{snapshot_id}:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/SnapshotId" }
    delete:
      tags: [snapshots]
      summary: Drop a snapshot. Its children hang from its parent, and a head on it moves there.
      responses:
        "200":
          description: Dropped; the snapshots that remain.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Snapshots" }
  /v1/simulations/{simulation_id}/snapshots/{snapshot_id}/frames/{machine_id}:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/SnapshotId" }
      - { name: machine_id, in: path, required: true, schema: { type: string }, description: One of the snapshot's `frames`. }
    get:
      tags: [snapshots]
      summary: The machine's screen when the snapshot was taken, as a PNG.
      responses:
        "200":
          description: OK
          content:
            image/png:
              schema: { type: string, format: binary }
        "404": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/snapshots/{snapshot_id}/restore:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/SnapshotId" }
    post:
      tags: [snapshots]
      summary: Restore the environment to a snapshot, which becomes the head, with the agents and their conversations as it kept them.
      description: |
        The agents, their connections (`config.machines`) and their threads become the
        snapshot's: the messages after it leave the threads, an agent made after it is removed
        (its token stops working), and an agent removed after it comes back with a new token,
        answered once in `agents`. An external agent still here keeps its token. A hosted
        agent that was working at the snapshot does not go on with that task: its thread ends
        with a `stopped` status marked `interrupted`, and the prompts that waited are dropped.
        A thread's numbers go on past the highest one used before, so a reader's `after` stays
        good. A snapshot kept before snapshots held conversations restores the agents it named
        with empty threads (`conversations_kept: false`).
      responses:
        "200":
          description: Restored.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/Clock"
                  - type: object
                    properties:
                      head: { type: string }
                      elapsed_ms: { type: number }
                      conversations_kept: { type: boolean }
                      agents:
                        type: array
                        description: The agents now. One that came back after it was removed carries `token`, shown once.
                        items: { allOf: [{ oneOf: [{ $ref: "#/components/schemas/Agent" }, { $ref: "#/components/schemas/HostedAgent" }] }, { type: object, properties: { token: { type: string } } }] }
  /v1/simulations/{simulation_id}/snapshots/{snapshot_id}/agents:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/SnapshotId" }
    get:
      tags: [snapshots]
      summary: The agents a snapshot kept, each with its state then.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  agents: { type: array, items: { oneOf: [{ $ref: "#/components/schemas/Agent" }, { $ref: "#/components/schemas/HostedAgent" }] } }
                  conversations_kept: { type: boolean, description: False for a snapshot kept before snapshots held conversations. }
        "404": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/snapshots/{snapshot_id}/agents/{agent_id}/messages:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/SnapshotId" }
      - { $ref: "#/components/parameters/AgentId" }
    get:
      tags: [snapshots]
      summary: One agent's thread as a snapshot kept it. At most 500 messages an answer.
      parameters:
        - { name: after, in: query, schema: { type: integer, minimum: 0, default: 0 }, description: The seq of the last message you hold. }
      responses:
        "200":
          description: The messages after `after`, and the thread's state then.
          content:
            application/json:
              schema:
                type: object
                properties:
                  messages: { type: array, items: { $ref: "#/components/schemas/Message" } }
                  state: { $ref: "#/components/schemas/ThreadState" }
        "404": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/publications:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [ingress]
      summary: The environment's publications, never their credentials.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { type: object, properties: { grants: { type: array, items: { $ref: "#/components/schemas/IngressGrant" } } } }
    post:
      tags: [ingress]
      summary: Publish one declared service to real HTTP clients, as one external agent from one machine it controls.
      description: |
        Each GET of `url` + a path with the answer's `header` is the agent's `http.v1 / request` from its
        machine to the service at `host:port`, recorded as its step. The agent needs `http.v1`. The credential
        is in this answer only. 503 `ingress_closed` while publications are off.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [agent, host, port]
              properties:
                agent: { type: string, example: agent_1 }
                host: { type: string, description: "A domain a service of the world declares.", example: html.example }
                port: { type: integer, example: 8090 }
                machine: { type: string, description: "Needed when the agent controls more than one machine." }
                methods: { type: array, items: { type: string, enum: [GET] } }
                ttl_s: { type: integer, minimum: 60, maximum: 86400, default: 3600 }
      responses:
        "201":
          description: The publication, with its credential (shown once).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/IngressGrant" }
        "400": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/publications/{handle}:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }, { $ref: "#/components/parameters/Handle" }]
    delete:
      tags: [ingress]
      summary: Revoke a publication; the next request with it fails.
      responses:
        "200":
          description: The publication, revoked.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/IngressGrant" }
  /v1/simulations/{simulation_id}/ssh:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [ingress]
      summary: The environment's SSH grants, never their credentials.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { type: object, properties: { grants: { type: array, items: { $ref: "#/components/schemas/IngressGrant" } } } }
    post:
      tags: [ingress]
      summary: Let a stock OpenSSH client holding `public_key` act as one external agent, through cw-ssh-proxy.
      description: |
        Each ssh command is the agent's `terminal.v1 / execute` on the machine (`exec`, the default; the agent needs
        `terminal.v1`). `forward` also allows `ssh -L` to that one declared service (the agent needs `http.v1`).
        503 `ingress_closed` where SSH is not offered.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [agent, public_key]
              properties:
                agent: { type: string, example: agent_1 }
                public_key: { type: string, description: "An OpenSSH public key line.", example: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI…" }
                machine: { type: string }
                exec: { type: boolean, default: true }
                forward: { type: object, required: [host, port], properties: { host: { type: string }, port: { type: integer } } }
                ttl_s: { type: integer, minimum: 60, maximum: 86400, default: 3600 }
      responses:
        "201":
          description: The grant, with its credential (shown once), the host key to pin and a copyable ssh command.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/IngressGrant" }
        "400": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/ssh/{handle}:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }, { $ref: "#/components/parameters/Handle" }]
    delete:
      tags: [ingress]
      summary: Revoke an SSH grant; its next command, on a connection open now too, fails.
      responses:
        "200":
          description: The grant, revoked.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/IngressGrant" }
  /v1/publications/{handle}/{path}:
    parameters:
      - { $ref: "#/components/parameters/Handle" }
      - { name: path, in: path, required: true, schema: { type: string }, description: "The path (and query) on the service, at most 2048 bytes.", example: api/records/probe }
    get:
      tags: [ingress]
      security: [{ ingressCredential: [] }]
      summary: One GET on the published service, answered by the world.
      description: |
        The service's status, body and safe content headers; `Cache-Control: private, no-store`. An active type
        (HTML, SVG, XML, script) is a sandboxed attachment. Cookies and redirect targets do not pass. A failure
        inside the world is 503 `in_world_failure` (no Retry-After); 503 with Retry-After is `ingress_closed`.
      responses:
        "200":
          description: The service's answer (any status it gave is passed).
          headers:
            X-CW-Tick: { schema: { type: string } }
            X-CW-State-Hash: { schema: { type: string } }
          content:
            "*/*": { schema: { type: string, format: binary } }
        "401": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "405": { $ref: "#/components/responses/Error" }
        "414": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /v1/ssh/{handle}:
    parameters: [{ $ref: "#/components/parameters/Handle" }]
    get:
      tags: [ingress]
      security: [{ ingressCredential: [] }]
      summary: The SSH transport, a WebSocket (subprotocol cw-ssh.v1) carrying ssh's bytes; cw-ssh-proxy opens it.
      parameters:
        - { name: Upgrade, in: header, required: true, schema: { type: string, enum: [websocket] } }
        - { name: Sec-WebSocket-Protocol, in: header, required: true, schema: { type: string, enum: [cw-ssh.v1] } }
      responses:
        "101": { description: Switching to cw-ssh.v1 (docs § SSH transport). }
        "401": { $ref: "#/components/responses/Error" }
        "426": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/fork:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [environments, snapshots]
      summary: Fork into a new environment (now, or from a kept snapshot), with its society and the agents connected to a machine.
      description: |
        The agents connected to a machine then are carried over under their ids with their
        threads (from a snapshot: as it kept them), the external ones with new tokens; a
        hosted one's task that was running does not go on, and its thread says so. `place` is as for a new environment; left out, the fork runs where its
        parent does. The family's history (`GET …/history`) names where the fork left its
        parent. An environment with a society forks at its current state (a `snapshot` is refused, 409):
        the runner's state is copied, and `society_ops` (a spec arm's rule ops: `append_rule`,
        `set_policy`, `set_state`) are applied to the fork's people. The fork's `name` labels
        its runner and salts the draws of its ops' `select`. The parent lists the fork in
        `forks` and compares it in `GET …/society/summary`. The fork's harness people (and a
        harness an op sets) are the forking caller's choice from then on, checked for it with
        the codes a boot gives.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                snapshot: { type: string, description: A snapshot id; omitted, the environment as it is now. }
                place: { $ref: "#/components/schemas/PlaceChoice" }
                idle_ttl: { type: integer }
                society_ops: { type: array, items: { type: object }, description: Rule ops applied to the fork's society (409 without one). }
      responses:
        "201":
          description: Forked; the new environment, whose `state_hash` equals the parent's at the fork point.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SimulationPlaced"
                  - type: object
                    properties:
                      agents: { type: array, items: { $ref: "#/components/schemas/AgentCreated" } }
                      forked_from: { type: string, description: The parent's id. }
                      forked_at: { type: object, properties: { snapshot: { type: [string, "null"] }, state_hash: { type: string } } }
                      fork_ms: { type: object, properties: { export: { type: number }, total: { type: number } } }
        "402": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/export:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [snapshots]
      summary: The environment as a portable snapshot (`exportSnapshot`), with its definition, seed and external agents.
      responses:
        "200":
          description: OK
          content:
            multipart/form-data:
              schema:
                type: object
                description: "Two parts: `bundle`, the JSON below, and `snapshot`, the engine's portable snapshot as bytes (`exportSnapshot`). POST /v1/simulations/import takes the same form, with what to boot it as in a JSON part `options`."
                properties:
                  bundle:
                    type: object
                    properties:
                      format: { type: string, const: computerworld-cloud-export/2 }
                      engine: { $ref: "#/components/schemas/EngineInfo" }
                      name: { type: string }
                      definition: { $ref: "#/components/schemas/Definition" }
                      seed: { type: integer }
                      state_hash: { type: string }
                      agents: { type: array, items: { type: object, properties: { id: { type: string }, session: { type: string }, label: { type: string }, config: { $ref: "#/components/schemas/AgentConfig" } } } }
                      packages: { type: array, items: { type: object } }
                  snapshot: { type: string, format: binary, description: The engine's portable snapshot (application/octet-stream). }

  # ---------------------------------------------------------------- agents
  /v1/simulations/{simulation_id}/agents:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [agents]
      summary: The environment's agents, external (grants; never their tokens) and hosted, then simulated (the society's people).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  agents: { type: array, items: { oneOf: [{ $ref: "#/components/schemas/Agent" }, { $ref: "#/components/schemas/HostedAgent" }, { $ref: "#/components/schemas/SimulatedAgent" }] } }
    post:
      tags: [agents]
      summary: Grant an external agent (its actor token, once), or make a hosted agent the platform runs (`kind`). Counts against `agents_per_simulation`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: "#/components/schemas/AgentConfig"
                - $ref: "#/components/schemas/HostedAgentCreate"
      responses:
        "201":
          description: Granted, or made.
          content:
            application/json:
              schema: { oneOf: [{ $ref: "#/components/schemas/AgentCreated" }, { $ref: "#/components/schemas/HostedAgent" }] }
        "400": { $ref: "#/components/responses/Error" }
        "403": { description: "`harness_access_required`: the hosted agent's harness is not open to the account; the message says who it is for.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "404": { description: "`harness_not_found`, or no such environment.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "409": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/agents/{agent_id}:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
    get:
      tags: [agents]
      security: [{ apiKey: [] }, { session: [] }, { actorToken: [] }]
      summary: One external agent's grant (its own actor token reads it too), or a hosted agent.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { oneOf: [{ $ref: "#/components/schemas/Agent" }, { $ref: "#/components/schemas/HostedAgent" }] }
    patch:
      tags: [agents]
      summary: Change what the agent is called, its standing instructions and whom it may message (owner).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string, maxLength: 200, description: "A hosted agent's `name`; an external agent's `label`." }
                instructions: { type: string, maxLength: 4000 }
                may_message: { $ref: "#/components/schemas/MayMessage" }
              additionalProperties: false
      responses:
        "200":
          description: The agent.
          content:
            application/json:
              schema: { oneOf: [{ $ref: "#/components/schemas/Agent" }, { $ref: "#/components/schemas/HostedAgent" }] }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
    delete:
      tags: [agents]
      summary: Revoke the agent with its thread; an external one's token stops working, a hosted one's loop stops.
      responses:
        "204": { description: Revoked. }
  /v1/simulations/{simulation_id}/agents/{agent_id}/tell:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
    post:
      tags: [agents]
      security: [{ actorToken: [] }]
      summary: An external agent's message to another agent, with its own actor token.
      description: |
        Delivered only along an edge of the communication graph (`may_message`). The other
        agent's thread gets a `peer` message; a hosted agent runs it as a task, and its summary
        comes back to this agent's thread as a `peer` message with `reply: true`. The message
        is kept in this agent's thread as an `agent` message of kind `tell`, delivered or not.
        A hosted agent's loop sends its own messages; the owner prompts instead (403).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [to, text]
              properties:
                to: { type: string, description: The id of the agent it is for. }
                text: { type: string, maxLength: 4000 }
                hops: { type: integer, minimum: 0, default: 0, description: "The `hops` of the message this one acts on (0 when it acts on none). The message sent has `hops + 1`; one over 8 is not delivered." }
      responses:
        "200":
          description: Whether it was delivered, and why not.
          content:
            application/json:
              schema:
                type: object
                required: [delivered]
                properties:
                  delivered: { type: boolean }
                  why: { type: string, description: Why it was not delivered. }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/communication:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
    get:
      tags: [agents]
      summary: "The communication graph: who may send a message to whom."
      responses:
        "200":
          description: The graph.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CommunicationGraph" }
    put:
      tags: [agents]
      summary: Replace every edge of the communication graph at once (owner).
      description: An unknown id, a self-edge or an edge from `person` is a 400, and nothing changes.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [edges]
              properties:
                edges: { type: array, items: { $ref: "#/components/schemas/CommunicationEdge" } }
      responses:
        "200":
          description: The graph now.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CommunicationGraph" }
        "400": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/agents/{agent_id}/machines/{machine_id}:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
      - { name: machine_id, in: path, required: true, schema: { type: string } }
    put:
      tags: [agents]
      summary: Connect the agent to a machine.
      description: |
        The agent keeps its id, token and thread; its session is made again on the machines it
        is now connected to. A hosted agent drives one machine, so connecting it moves it.
        Connecting to a machine it is already connected to changes nothing.
      responses:
        "200":
          description: The agent.
          content:
            application/json:
              schema: { oneOf: [{ $ref: "#/components/schemas/Agent" }, { $ref: "#/components/schemas/HostedAgent" }] }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { description: A hosted agent that is working; stop it first., content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
    delete:
      tags: [agents]
      summary: Disconnect the agent from a machine.
      description: |
        The agent stays, with its id, token and thread. One connected to no machine has
        `config.machines: []` (a hosted one `machine: null`): its step, observe, scene and
        render are a 409, and a prompt to a hosted one is a 409, until it is connected again.
      responses:
        "200":
          description: The agent.
          content:
            application/json:
              schema: { oneOf: [{ $ref: "#/components/schemas/Agent" }, { $ref: "#/components/schemas/HostedAgent" }] }
        "403": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "409": { description: A hosted agent that is working; stop it first., content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
  /v1/simulations/{simulation_id}/agents/{agent_id}/step:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
    post:
      tags: [agents]
      security: [{ apiKey: [] }, { session: [] }, { actorToken: [] }]
      summary: Send actions through the agent's session (`Environment.step`). Each is checked against the grant.
      description: |
        A hosted agent's machine is its loop's: a step for it is a 409.
        `machine` may be omitted when the grant names one machine. An action outside the grant
        comes back as an unsuccessful outcome (not an HTTP error); the HTTP status is 200 whenever
        the batch was taken. Counts against `steps_per_minute` (each action is one).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [actions]
              properties:
                actions: { type: array, maxItems: 64, items: { $ref: "#/components/schemas/Action" } }
                render:
                  type: object
                  description: >
                    Draw the screen the actions left and answer it as `frame`, in the same round trip:
                    what GET …/render would draw for the new state. Counts as one render. With
                    `if_changed`, a step that leaves the state hash as it was draws nothing.
                  properties:
                    width: { type: integer, minimum: 64, maximum: 2560, default: 1280 }
                    height: { type: integer, minimum: 64, maximum: 1600, default: 800 }
                    if_changed: { type: boolean, default: false }
      responses:
        "200":
          description: The outcomes, in order (and `frame`, when `render` was given).
          content:
            application/json:
              schema:
                allOf:
                  - { $ref: "#/components/schemas/StepResult" }
                  - type: object
                    properties:
                      frame:
                        type: object
                        properties:
                          png: { type: string, format: byte, description: The PNG, base64. }
                          width: { type: integer }
                          height: { type: integer }
                          state_hash: { type: string }
        "429": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/agents/{agent_id}/observe:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
    get:
      tags: [agents]
      security: [{ apiKey: [] }, { session: [] }, { actorToken: [] }]
      summary: The agent's observation channels (`Environment.observe`).
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { type: object, properties: { channels: { type: object }, tick: { type: integer } } }
  /v1/simulations/{simulation_id}/agents/{agent_id}/scene:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
      - { $ref: "#/components/parameters/Width" }
      - { $ref: "#/components/parameters/Height" }
      - { name: elements, in: query, schema: { type: boolean }, description: "Also return `elements`: every interactive node with its role, label, interaction id and clipped box in screen pixels, front first." }
    get:
      tags: [agents]
      security: [{ apiKey: [] }, { session: [] }, { actorToken: [] }]
      summary: The screen as a scene graph (`Environment.scene`) — windows, controls, text runs, bounds, roles.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  width: { type: integer }
                  height: { type: integer }
                  digest: { type: string }
                  focus: { type: object }
                  nodes: { type: array, items: { type: object } }
                  elements: { type: array, items: { $ref: "#/components/schemas/Element" } }
  /v1/simulations/{simulation_id}/agents/{agent_id}/render:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
      - { $ref: "#/components/parameters/Width" }
      - { $ref: "#/components/parameters/RenderHeight" }
      - { name: format, in: query, schema: { type: string, enum: [png, rgba], default: png } }
      - { name: If-None-Match, in: header, schema: { type: string }, description: "The ETag of a frame already held: an unchanged screen answers 304 and is not counted against renders_per_minute." }
    get:
      tags: [agents]
      security: [{ apiKey: [] }, { session: [] }, { actorToken: [] }]
      summary: The screen as pixels. Counts against `renders_per_minute`.
      responses:
        "200":
          description: "A PNG (or raw RGBA bytes, row-major, with `X-Width`/`X-Height`). `X-State-Hash` and `X-Tick` name the state drawn; `ETag` is the state hash, agent, size and format. The screen shown is the agent's focused machine: a grant with several machines draws the one it acts on (a `machine` parameter needs engine support; grant one agent per machine)."
          content:
            image/png: { schema: { type: string, format: binary } }
            application/octet-stream: { schema: { type: string, format: binary } }
        "304": { description: The screen is the one the ETag names. }
  /v1/simulations/{simulation_id}/agents/{agent_id}/screens/{digest}:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
      - { name: digest, in: path, required: true, schema: { type: string }, description: "A thought's `screen`, or an action's `screen` or `after`." }
    get:
      tags: [agents]
      security: [{ apiKey: [] }, { session: [] }, { actorToken: [] }]
      summary: A screen a hosted agent saw, kept for its trajectory (the newest 400 of an agent).
      responses:
        "200":
          description: "The screen as a PNG. The same digest is always the same picture, so it may be cached for good."
          content:
            image/png: { schema: { type: string, format: binary } }
        "404": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/agents/{agent_id}/messages:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
    get:
      tags: [agents]
      security: [{ apiKey: [] }, { session: [] }, { actorToken: [] }]
      summary: The agent's thread after `after`, waiting up to `wait` seconds for a message when there is none (long-polling).
      description: |
        Every kind of agent has a thread. An external agent's actor token reads its own. A
        simulated agent's thread is its activity in the society (its turns, decisions and
        gestures), read from the trace; its `at` is null (the trace keeps the environment's
        clock, `tick`). At most 500 messages an answer: ask again after the last one's `seq`.
        To stream, read in a loop with `after` set to the last `seq` you hold and `wait=25`:
        a message added meanwhile answers at once.
      parameters:
        - { name: after, in: query, schema: { type: integer, minimum: 0, default: 0 }, description: The seq of the last message you hold. }
        - { name: wait, in: query, schema: { type: number, minimum: 0, maximum: 25, default: 0 }, description: Seconds to wait for a message after `after` when there is none yet. }
      responses:
        "200":
          description: The messages after `after`, and the thread's state now.
          content:
            application/json:
              schema:
                type: object
                properties:
                  messages: { type: array, items: { $ref: "#/components/schemas/Message" } }
                  state: { $ref: "#/components/schemas/ThreadState" }
        "404": { $ref: "#/components/responses/Error" }
    post:
      tags: [agents]
      security: [{ apiKey: [] }, { session: [] }, { actorToken: [] }]
      summary: Add a message. The owner prompts (`{text}`, role `person`); an external agent's actor token writes `agent`, `action` or `status` messages.
      description: |
        A prompt to a hosted agent starts a task. One sent while a task runs is heard by that
        task at its next step (`heard`); a harness that does not hear (a scripted one) takes it
        as its next task (`queued`). The first prompt after an open question is its answer
        (`answers`), and continues a parked run. A simulated agent takes no prompt (409).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  description: The owner's prompt.
                  required: [text]
                  properties: { text: { type: string, maxLength: 4000 } }
                  additionalProperties: false
                - type: object
                  description: An external agent's message (its actor token). Other fields (an action's `action`, say) are kept with it, up to 8 KiB of JSON.
                  required: [role, text]
                  properties:
                    role: { type: string, enum: [agent, action, status] }
                    text: { type: string }
                    status: { type: string, enum: [started, finished, stopped, failed, waiting], description: A status message's status. }
                    kind: { type: string, enum: [thought, question, said], default: said, description: "An agent message's kind. A `tell` is written by POST …/tell." }
                    options: { type: array, maxItems: 4, items: { type: string, maxLength: 60 }, description: A question's choices. }
                  additionalProperties: true
      responses:
        "201":
          description: Added.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message: { $ref: "#/components/schemas/Message" }
                  state: { $ref: "#/components/schemas/ThreadState" }
        "400": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
  /v1/simulations/{simulation_id}/agents/{agent_id}/stop:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { $ref: "#/components/parameters/AgentId" }
    post:
      tags: [agents]
      summary: Stop the agent (owner). A hosted agent's task is cut short, and a parked run and the prompts that wait are dropped; an external agent's thread gets a `stopped` status for it to read. A simulated agent is a 409.
      responses:
        "200":
          description: Stopped.
          content:
            application/json:
              schema: { type: object, properties: { state: { $ref: "#/components/schemas/ThreadState" } } }
        "409": { $ref: "#/components/responses/Error" }

  # ---------------------------------------------------------------- procedures
  /v1/simulations/{simulation_id}/procedures/stage:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [procedures]
      summary: Write an instance's setup files into the environment (owner).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [instance]
              properties:
                instance: { $ref: "#/components/schemas/ProcedureInstance" }
      responses:
        "200":
          description: Staged.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Clock" }
  /v1/simulations/{simulation_id}/procedures/project:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [procedures]
      summary: Perform an instance through external agents' sessions and return the demonstration.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [instance, agent]
              properties:
                instance: { $ref: "#/components/schemas/ProcedureInstance" }
                agent:
                  description: "One external agent's id, or `{role: agent id}` for a team procedure."
                  oneOf: [{ type: string }, { type: object, additionalProperties: { type: string } }]
                options: { $ref: "#/components/schemas/ProjectOptions" }
      responses:
        "200":
          description: The demonstration.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Demonstration" }
  /v1/simulations/{simulation_id}/procedures/verify:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [procedures]
      summary: Judge the environment against an instance's checks.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [instance]
              properties:
                instance: { $ref: "#/components/schemas/ProcedureInstance" }
                captures: { type: object, additionalProperties: { type: string }, description: "A demonstration's `captures`: fills the checks that name a captured `{{@name}}`." }
      responses:
        "200":
          description: The verification.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Verification" }
  /v1/simulations/{simulation_id}/procedures/run:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [procedures]
      summary: Instantiate, stage, project and verify in one call.
      description: |
        Grants the session(s) itself (the procedure's machine and user, or each role's) with
        pointer, keyboard, application, browser and filesystem, unless `agent` names existing
        external agents. `fork: true` runs it in a throwaway in-memory fork and leaves this
        environment untouched (`simulation` is then null); use `POST /fork` first to keep the
        result. The environment must run in a place carrying every application the procedure
        launches (409 otherwise, naming the place to fork to), and must have been booted with the
        desktops the procedure names (409 otherwise: boot one with `procedure`).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/ProcedureRef"
                - type: object
                  properties:
                    agent: { oneOf: [{ type: string }, { type: object, additionalProperties: { type: string } }] }
                    options: { $ref: "#/components/schemas/ProjectOptions" }
                    fork: { type: boolean, default: false }
                    include_steps: { type: boolean, default: false }
      responses:
        "200":
          description: The run.
          content:
            application/json:
              schema:
                type: object
                properties:
                  instance: { $ref: "#/components/schemas/ProcedureInstance" }
                  demonstration: { $ref: "#/components/schemas/Demonstration" }
                  verification: { $ref: "#/components/schemas/Verification" }
                  simulation: { type: [string, "null"], description: "The environment it ran in; null with `fork: true`." }
                  state_hash: { type: string }
                  timings_ms: { type: object }
                  host: { type: string, description: The id of the place it ran in. }
                  memory: { $ref: "#/components/schemas/Memory" }
        "409": { $ref: "#/components/responses/Error" }

  # ---------------------------------------------------------------- society
  /v1/simulations/{simulation_id}/society:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [society]
      summary: The environment's society now.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Society" }
        "404": { description: The environment was booted without a society. }
  /v1/simulations/{simulation_id}/society/rounds:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    post:
      tags: [society]
      summary: Run up to `count` rounds of this environment's society (a fork runs its own).
      description: |
        A round whose people ask a model and whose answers the journal lacks is rolled back and
        comes back `pending`. With `ask_model`, the API asks the model for each pending prompt
        once (counted against `model_calls_per_day`), writes the replies to the journal, and
        runs the round again; without it, post the replies to `…/society/journal` and call
        again. A person whose policy is a harness takes their turn here, during the call: the
        agent loop a hosted agent runs, over their own session, with their persona, rules and
        intent as its task. Whether the account that chose the harness may still use it is read
        at each turn; a turn refused (`harness_access_required`, `harness_not_found`) or failed
        ends that person's turn, not the round. Model calls of a turn are the organization's
        agent-minutes, as a hosted agent's are; `ask_model` does not apply to them.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                count: { type: integer, minimum: 1, maximum: 100, default: 1 }
                ask_model: { type: boolean, default: false }
      responses:
        "200":
          description: The rounds run.
          content:
            application/json:
              schema:
                type: object
                properties:
                  round: { type: integer, description: Rounds completed. }
                  rounds: { type: integer, description: The planned round count. }
                  done: { type: boolean }
                  records: { type: array, items: { $ref: "#/components/schemas/RoundEnd" } }
                  pending: { type: array, items: { $ref: "#/components/schemas/PendingDecision" } }
                  turns:
                    type: array
                    description: The harness turns taken in this call, in order (also in the trace as `turn_end`).
                    items:
                      type: object
                      properties:
                        person: { type: string }
                        round: { type: integer }
                        harness: { type: string, example: computatrum-1.1-normal }
                        status: { type: string, enum: [done, failed, stopped, quota, error], description: How the loop ended. }
                        summary: { type: string, description: What the harness said it did, or why the turn did not run. }
                        steps: { type: integer, description: Decisions the loop took. }
                        code: { type: string, description: "The error code when the turn could not run: harness_access_required, harness_not_found, …" }
                  model: { type: object, properties: { calls: { type: integer }, prompt_tokens: { type: integer }, completion_tokens: { type: integer } } }
                  note: { type: string, description: Why pending decisions were not asked of the model. }
                  wall_ms: { type: number }
  /v1/simulations/{simulation_id}/society/journal:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [society]
      summary: The journal of model replies, as JSON lines.
      responses:
        "200":
          description: OK
          content:
            application/x-ndjson: { schema: { type: string } }
    post:
      tags: [society]
      summary: Add model replies (a pending decision's `key` and its answer).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [entries]
              properties:
                entries: { type: array, items: { type: object, properties: { key: { type: string }, reply: {} } } }
      responses:
        "200":
          description: Kept.
          content:
            application/json:
              schema: { type: object, properties: { entries: { type: integer, description: Replies the journal holds. } } }
  /v1/simulations/{simulation_id}/society/trace:
    parameters:
      - { $ref: "#/components/parameters/SimulationId" }
      - { name: since, in: query, schema: { type: integer, default: -1 }, description: The last record already read. }
    get:
      tags: [society]
      summary: The society's trace (boot, interventions, round starts and ends, activations, decisions, harness turns' ends), as JSON lines.
      responses:
        "200":
          description: OK
          content:
            application/x-ndjson: { schema: { type: string } }
  /v1/simulations/{simulation_id}/society/summary:
    parameters: [{ $ref: "#/components/parameters/SimulationId" }]
    get:
      tags: [society]
      summary: Outcomes per round for this environment and each of its forks, and the matched-fork comparison.
      description: |
        The forks made at the same round are compared together (https://computaco.ai/docs/societies.html § Matched forks):
        this environment's records before that round are the prefix, this environment from it on
        is the control (the first arm), and each fork an arm. Effects are paired against this
        environment; divergence and state hashes are per round. Each environment runs its own
        rounds, so a comparison covers the rounds both have run.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SocietySummary" }
        "404": { description: The environment was booted without a society. }
  /v1/harnesses:
    get:
      tags: [harnesses]
      summary: Every harness, each with whether this account may use it in this organization, and why.
      description: The platform's harnesses and the organization's scripted ones. `simulations` scope; an agent token may read it.
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  default: { type: string, example: computatrum-1.1-normal }
                  harnesses: { type: array, items: { $ref: "#/components/schemas/Harness" } }
                  views: { type: object, additionalProperties: { $ref: "#/components/schemas/StateView" }, description: "The state views a harness's internal state is read in, by name (a decision's `state.view`)." }
  /v1/harnesses/scripted:
    post:
      tags: [harnesses]
      summary: Make a scripted harness, a fixed program of steps, for the organization.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ScriptedHarnessBody" }
      responses:
        "201":
          description: Made. Its id is `scripted-<uuid>`.
          content:
            application/json:
              schema: { type: object, properties: { harness: { $ref: "#/components/schemas/Harness" } } }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/harnesses/{harness_id}:
    parameters: [{ name: harness_id, in: path, required: true, schema: { type: string, example: computatrum-1.1-normal } }]
    get:
      tags: [harnesses]
      summary: One harness; a scripted one with its script.
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Harness" } } } }
        "404": { $ref: "#/components/responses/Error" }
    put:
      tags: [harnesses]
      summary: Replace a scripted harness's name and script; its id stays.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ScriptedHarnessBody" }
      responses:
        "200": { description: Replaced., content: { application/json: { schema: { type: object, properties: { harness: { $ref: "#/components/schemas/Harness" } } } } } }
        "400": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "405": { $ref: "#/components/responses/Error" }
    delete:
      tags: [harnesses]
      summary: Delete a scripted harness.
      responses:
        "204": { description: Deleted. }
        "404": { $ref: "#/components/responses/Error" }
        "405": { $ref: "#/components/responses/Error" }
  /v1/harnesses/{harness_id}/attestation:
    parameters: [{ name: harness_id, in: path, required: true, schema: { type: string, example: tribe-v2-energy-based-navigator-2026-11-10-normal } }]
    post:
      tags: [harnesses]
      summary: Attest that you will use a harness only for noncommercial purposes.
      description: For an account that holds both `commercial` and `noncommercial-research`, once per harness. The record keeps the account, the harness id, the text and the time. A key, a session or the app's agent token. `simulations` scope.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [agree]
              properties:
                agree: { type: boolean, const: true }
      responses:
        "200": { description: Recorded; the harness with `attestation.given` true., content: { application/json: { schema: { type: object, properties: { harness: { $ref: "#/components/schemas/Harness" } } } } } }
        "403": { description: "`harness_access_required`.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "404": { description: "`harness_not_found`.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
  /v1/harnesses/{harness_id}/decide:
    parameters: [{ name: harness_id, in: path, required: true, schema: { type: string, example: tribe-v2-energy-based-navigator-2026-11-10-normal } }]
    post:
      tags: [harnesses]
      summary: Ask a harness that runs on its own model server for one step.
      description: The step is queued and the harness's model answers it; while the model starts the answer is a `wait`. The answer comes at once when it is ready within a few seconds, else `pending` to ask again with. Not metered.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [input]
              properties:
                input: { $ref: "#/components/schemas/HarnessInput" }
      responses:
        "200": { description: Decided., content: { application/json: { schema: { type: object, properties: { decision: { $ref: "#/components/schemas/HarnessDecision" } } } } } }
        "202": { description: Still being decided., content: { application/json: { schema: { $ref: "#/components/schemas/HarnessPending" } } } }
        "400": { $ref: "#/components/responses/Error" }
        "403": { description: "`harness_access_required`.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "409": { description: "`harness_attestation_required`: the account must attest first; the error carries `text` and `why`.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "429": { description: "`harness_busy`: the organization has 8 steps waiting.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "503": { description: "`harness_offline`: this harness's model is not available now; `harness_failed`: the model could not decide; `harness_timeout`.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
  /v1/harnesses/decisions/{decision_id}:
    parameters: [{ name: decision_id, in: path, required: true, schema: { type: string, example: hd_3f9a1c2b4d5e6f708192 } }]
    get:
      tags: [harnesses]
      summary: "A step asked of a research harness: its decision, or pending."
      responses:
        "200": { description: Decided., content: { application/json: { schema: { type: object, properties: { decision: { $ref: "#/components/schemas/HarnessDecision" } } } } } }
        "202": { description: Still being decided., content: { application/json: { schema: { $ref: "#/components/schemas/HarnessPending" } } } }
        "404": { $ref: "#/components/responses/Error" }
        "503": { $ref: "#/components/responses/Error" }

  /v1/browser/screenshot:
    post:
      tags: [browser]
      summary: Open a page in a throwaway browser session and draw it as a PNG. One step and one render; the session is deleted in the call.
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/BrowserOneShot" } } } }
      responses:
        "200":
          description: "The page as a PNG at the viewport (or, with `full_page`, as tall as the page, up to 4,096,000 pixels in all). `X-Width` and `X-Height` give its size, `X-Full-Page-Clipped: true` says a whole page was cut at its foot, and `X-Browser-Ms-Used` how long the call held the browser."
          content: { image/png: { schema: { type: string, format: binary } } }
        "400": { $ref: "#/components/responses/Error" }
        "403": { $ref: "#/components/responses/Error" }
        "422": { description: "`navigation_failed`: the browser could not open the address (a scheme it does not fetch, a host it cannot reach).", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "429": { $ref: "#/components/responses/Error" }
  /v1/browser/content:
    post:
      tags: [browser]
      summary: Open a page in a throwaway session and read its markup after its script ran.
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/BrowserOneShot" } } } }
      responses:
        "200": { description: The page., content: { application/json: { schema: { $ref: "#/components/schemas/PageContent" } } } }
        "400": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /v1/browser/markdown:
    post:
      tags: [browser]
      summary: Open a page in a throwaway session and read it as Markdown.
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/BrowserOneShot" } } } }
      responses:
        "200": { description: The page., content: { application/json: { schema: { $ref: "#/components/schemas/PageMarkdown" } } } }
        "400": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /v1/browser/links:
    post:
      tags: [browser]
      summary: Open a page in a throwaway session and read its links.
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/BrowserOneShot" } } } }
      responses:
        "200": { description: The page's links., content: { application/json: { schema: { $ref: "#/components/schemas/PageLinks" } } } }
        "400": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /v1/browser/snapshot:
    post:
      tags: [browser]
      summary: Open a page in a throwaway session and read its markup and a screenshot in one answer.
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/BrowserOneShot" } } } }
      responses:
        "200":
          description: The page.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/PageContent"
                  - { type: object, properties: { screenshot: { type: string, description: The screen as a base64 PNG. } } }
        "400": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /v1/browser/sessions:
    get:
      tags: [browser]
      summary: The organization's browser sessions.
      responses:
        "200": { description: Sessions., content: { application/json: { schema: { type: object, properties: { sessions: { type: array, items: { $ref: "#/components/schemas/BrowserSession" } } } } } } }
    post:
      tags: [browser]
      summary: Open a browser session, sent to `url` when given. It is an environment (`GET /v1/simulations/{id}` reads it, `POST …/fork` forks it) and counts against `simulations_max`.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                url: { type: string, example: "https://example.com/" }
                viewport: { $ref: "#/components/schemas/Viewport" }
                idle_ttl_s: { type: integer, minimum: 60, maximum: 86400, default: 300, description: The session is deleted after this many seconds with no request to it. }
                place: { type: string, enum: [lightning, heavy], default: lightning, description: "Where the browser runs. A page too large for a Lightning place (128 MB) is answered 422 page_too_large; Heavy holds 6 GB." }
                wait_ms: { type: integer, minimum: 0, maximum: 30000, description: "Milliseconds of the machine's clock to run after the page loads." }
      responses:
        "201": { description: The session., content: { application/json: { schema: { $ref: "#/components/schemas/BrowserSession" } } } }
        "400": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /v1/browser/sessions/{session_id}:
    parameters: [{ $ref: "#/components/parameters/BrowserSessionId" }]
    get:
      tags: [browser]
      summary: The session and the page it shows.
      responses:
        "200": { description: The session., content: { application/json: { schema: { $ref: "#/components/schemas/BrowserSession" } } } }
        "404": { $ref: "#/components/responses/Error" }
    delete:
      tags: [browser]
      summary: Delete the session.
      responses:
        "204": { description: Deleted. }
        "404": { $ref: "#/components/responses/Error" }
  /v1/browser/sessions/{session_id}/actions:
    parameters: [{ $ref: "#/components/parameters/BrowserSessionId" }]
    post:
      tags: [browser]
      summary: Up to 64 `browser.v1`, `keyboard.v1` or `pointer.v1` actions (https://computaco.ai/docs/action-families.html), without `machine`. Each counts as a step. An action of another family is an unsuccessful outcome.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [actions]
              properties:
                actions: { type: array, minItems: 1, maxItems: 64, items: { type: object, required: [family, op], properties: { family: { type: string, enum: [browser.v1, keyboard.v1, pointer.v1] }, op: { type: string }, payload: { type: object } } } }
      responses:
        "200":
          description: Each action's outcome.
          content:
            application/json:
              schema: { type: object, properties: { id: { type: string }, outcomes: { type: array, items: { type: object } }, state_hash: { type: string }, tick: { type: integer } } }
        "400": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
  /v1/browser/sessions/{session_id}/screenshot:
    parameters:
      - { $ref: "#/components/parameters/BrowserSessionId" }
      - { name: full_page, in: query, schema: { type: boolean }, description: Draw the whole page, not only the viewport. }
    get:
      tags: [browser]
      summary: The screen as a PNG at the session's viewport. One render.
      responses:
        "200": { description: "The PNG, with `X-Width`, `X-Height` and `X-Full-Page-Clipped` as for the one-shot screenshot.", content: { image/png: { schema: { type: string, format: binary } } } }
        "404": { $ref: "#/components/responses/Error" }
  /v1/browser/sessions/{session_id}/content:
    parameters: [{ $ref: "#/components/parameters/BrowserSessionId" }]
    get:
      tags: [browser]
      summary: The page's markup as it stands now.
      responses:
        "200": { description: The page., content: { application/json: { schema: { $ref: "#/components/schemas/PageContent" } } } }
        "409": { description: "`no_page`: the session has not been sent to a page.", content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
  /v1/browser/sessions/{session_id}/markdown:
    parameters: [{ $ref: "#/components/parameters/BrowserSessionId" }]
    get:
      tags: [browser]
      summary: The page as Markdown.
      responses:
        "200": { description: The page., content: { application/json: { schema: { $ref: "#/components/schemas/PageMarkdown" } } } }
        "409": { $ref: "#/components/responses/Error" }
  /v1/browser/sessions/{session_id}/links:
    parameters: [{ $ref: "#/components/parameters/BrowserSessionId" }]
    get:
      tags: [browser]
      summary: The page's links.
      responses:
        "200": { description: The links., content: { application/json: { schema: { $ref: "#/components/schemas/PageLinks" } } } }
        "409": { $ref: "#/components/responses/Error" }

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: "An API key: `Authorization: Bearer cw_live_...`. Acts in its organization: owns its environments. Reaches the routes of its scopes (`Scope`); a session has every scope."
    session:
      type: apiKey
      in: cookie
      name: cw_session
      description: The console's HttpOnly session cookie. Mutating calls with a cookie must send `Origin` matching the host.
    actorToken:
      type: http
      scheme: bearer
      description: "An actor token `cwa_...`: GET, step, observe, scene, render of its own external agent only."
    ingressCredential:
      type: http
      scheme: bearer
      description: "A grant's credential `cwi_...` (POST …/publications, POST …/ssh): its own publication or SSH connection only."
    agentToken:
      type: http
      scheme: bearer
      description: "An agent token `cwt_...` from the device sign-in: /v1/agent/chat, /v1/agent/vision, /v1/agent/decide, /v1/agent/usage and the harness routes it may read and ask."
  parameters:
    ComputatrumTask:
      name: X-Computatrum-Task
      in: header
      required: false
      schema: { type: string, pattern: "^[A-Za-z0-9_-]{1,64}$", example: 4f1c2a9e-7b3d-4e8a-9c1f-2d6b8e0a5c3b }
      description: The task the call belongs to (a UUID per task); its gaps to the task's previous call count as agent-minutes, up to 15 s. Without one a call counts its own time only.
    Handle: { name: handle, in: path, required: true, schema: { type: string, pattern: "^cwh_" }, description: "A grant's handle: not secret.", example: cwh_w_5d1e0c7b2a_6c2f0e9a1b3d4c5e }
    KeyId: { name: key_id, in: path, required: true, schema: { type: string }, example: key_8c1f20aa }
    OrgId: { name: org_id, in: path, required: true, schema: { type: string }, description: "An organization's id: org_… for a team, the account's own id for its personal one.", example: org_3f2a9c11d4e5b6a7 }
    TemplateId: { name: template_id, in: path, required: true, schema: { type: string }, description: "A built-in template's name, or an own template's id.", example: agent-desktop }
    RecordingId: { name: recording_id, in: path, required: true, schema: { type: string }, example: "r~run-12~eda-divider-s3" }
    SimulationId: { name: simulation_id, in: path, required: true, schema: { type: string }, example: w_5d1e0c7b2a }
    SnapshotId: { name: snapshot_id, in: path, required: true, schema: { type: string }, example: s_3 }
    AgentId: { name: agent_id, in: path, required: true, schema: { type: string }, description: "An external agent's id, opaque: ids stored before agents were named keep their form.", example: agent_1 }
    UserCode: { name: user_code, in: path, required: true, schema: { type: string }, example: BCDF-GHJK, description: "Case, spaces and the dash do not matter." }
    Width: { name: width, in: query, schema: { type: integer, default: 1280, minimum: 64, maximum: 2560 } }
    Height: { name: height, in: query, schema: { type: integer, default: 800, minimum: 64, maximum: 1600 } }
    RenderHeight: { name: height, in: query, schema: { type: integer, default: 800, minimum: 64, maximum: 16000 }, description: "Up to 1,600, or taller when width × height is at most 4,096,000 pixels (a whole page)." }
    BrowserSessionId: { name: session_id, in: path, required: true, schema: { type: string }, description: "A browser session's id (its environment's).", example: w_5d1e0c7b2a }
  responses:
    Error:
      description: An error.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
  schemas:
    Viewport:
      type: object
      description: The browser's screen in pixels, 1280×800 when left out.
      properties:
        width: { type: integer, minimum: 64, maximum: 2560, default: 1280 }
        height: { type: integer, minimum: 64, maximum: 1600, default: 800 }
    BrowserOneShot:
      type: object
      required: [url]
      properties:
        url: { type: string, description: "The address to open, as typed in an address bar.", example: "https://example.com/" }
        viewport: { $ref: "#/components/schemas/Viewport" }
        wait_ms: { type: integer, minimum: 0, maximum: 30000, description: "Milliseconds of the machine's clock to run after the page loads, so its timers fire." }
        full_page: { type: boolean, description: "Screenshot and snapshot: draw the whole page, not only the viewport." }
        place: { type: string, enum: [lightning, heavy], default: lightning, description: "Where the browser runs. A page too large for a Lightning place (128 MB) is answered 422 page_too_large; Heavy holds 6 GB." }
    PageContent:
      type: object
      properties:
        url: { type: string }
        status: { type: integer, description: The HTTP status the page was answered with. }
        title: { type: string }
        html: { type: string, description: "The page's markup as it stands now, after its script ran, behind its doctype." }
    PageMarkdown:
      type: object
      properties:
        url: { type: string }
        title: { type: string }
        markdown: { type: string, description: "The page's headings, text, links and pictures, in order." }
    PageLinks:
      type: object
      properties:
        url: { type: string }
        links: { type: array, items: { type: object, properties: { href: { type: string, description: Resolved against the page. }, text: { type: string } } } }
    BrowserSession:
      type: object
      properties:
        id: { type: string, description: "The session's id, which is its environment's.", example: w_5d1e0c7b2a }
        url: { type: [string, "null"], description: The page on show; null before the session is sent anywhere. }
        title: { type: [string, "null"] }
        status: { type: [integer, "null"] }
        viewport: { $ref: "#/components/schemas/Viewport" }
        idle_ttl_s: { type: integer }
        expires_at: { type: integer, description: "Milliseconds since the epoch; a request moves it." }
        created_at: { type: integer }
        place: { type: string, enum: [lightning, heavy] }
        state_hash: { type: string }
        tick: { type: integer }
    IngressGrant:
      type: object
      description: A grant for a real client (docs § Real clients). `credential` and `header` are in the answer that made it only.
      properties:
        handle: { type: string }
        kind: { type: string, enum: [http, ssh] }
        agent: { type: string }
        machine: { type: string }
        target: { type: object, properties: { scheme: { type: string }, host: { type: string }, port: { type: integer }, service: { type: string } } }
        url: { type: string, description: "A publication's: GET url + /path." }
        methods: { type: array, items: { type: string } }
        login: { type: string, description: "An SSH grant's ssh user name." }
        exec: { type: boolean }
        websocket_url: { type: string }
        public_key: { type: string }
        host_key: { type: string }
        host_key_alias: { type: string }
        known_hosts: { type: string, description: "The line to put in the known_hosts file ssh checks." }
        ssh_command: { type: string }
        credential: { type: string }
        header: { type: string }
        created_at: { type: integer }
        expires_at: { type: integer }
        revoked_at: { type: integer, nullable: true }
        state: { type: string, enum: [active, expired, revoked, stale] }
        uses: { type: integer }
        bytes: { type: integer }
    PerceiveRequest:
      type: object
      required: [page, schema]
      properties:
        page:
          type: object
          required: [url]
          description: "{url, html} (the HTML as fetched, at most 8 MiB) or {url, graph} (a UX graph the caller made)."
          properties: { url: { type: string }, html: { type: string }, graph: { type: object } }
        schema: { type: object, description: "A JSON Schema of one record: properties of strings, numbers, integers, booleans or null; format uri takes a link's address, format date a date (written as an ISO date)." }
        purpose: { type: string, maxLength: 500 }
        budget: { type: object, properties: { max_cost: { type: number, minimum: 0 }, max_ms: { type: integer, minimum: 1 } } }
        limit: { type: integer, minimum: 1, maximum: 1000 }
    PerceiveAnswer:
      type: object
      properties:
        records: { type: array, items: { type: object } }
        evidence: { type: array, items: { type: object, properties: { record: { type: integer }, nodes: { type: array, items: { type: object, properties: { node: { type: integer }, field: { type: string }, quote: { type: string } } } } } } }
        outline_hash: { type: string, description: "SHA-256 of the page's outline: equal for two fetches that read the same." }
        harness: { type: string, enum: [rules, model] }
        cost: { type: number, description: US dollars. }
        model_calls: { type: integer }
        cpu_ms: { type: number }
        note: { type: string }
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code: { type: string }
            message: { type: string }
    EngineInfo:
      type: object
      properties:
        version: { type: string, description: "engineVersion()" }
        build: { type: string, example: computerworld-web-full }
        wasm_sha256: { type: string }
        lazy: { type: boolean }
    Credentials:
      type: object
      required: [username, password]
      properties:
        username: { type: string, pattern: "^[a-z0-9_-]{3,32}$" }
        password: { type: string, minLength: 10, maxLength: 200 }
    User:
      type: object
      properties:
        id: { type: string, example: u_9a8b7c6d5e4f }
        username: { type: string }
        created_at: { type: integer, description: Unix ms. }
        plan: { type: string, example: free }
        name: { type: [string, "null"], maxLength: 100, example: Ada Lovelace }
        email: { type: [string, "null"], format: email, example: ada@cs.example.edu, description: "The account's address; shown to its owner only." }
        email_verified_at: { type: [integer, "null"], description: "When the address was verified (Unix ms); null while it is not." }
        date_of_birth: { type: [string, "null"], format: date, example: "1990-02-28" }
    EmailState:
      type: object
      properties:
        address: { type: [string, "null"], format: email }
        verified: { type: boolean }
        verified_at: { type: [integer, "null"] }
        pending: { type: [object, "null"], properties: { expires_at: { type: integer } }, description: The code waiting, if any. }
    ReviewRequest:
      type: object
      properties:
        id: { type: string, example: rv_3fa1c2d4e5f60718 }
        standing: { type: string }
        statement: { type: string }
        state: { type: string, enum: [open, granted, declined, withdrawn] }
        created_at: { type: integer }
        resolved_at: { type: [integer, "null"] }
        tag: { type: [string, "null"], description: The tag given, when granted. }
        reason: { type: [string, "null"], description: Why, when declined. }
    ProfilePatch:
      type: object
      additionalProperties: false
      minProperties: 1
      properties:
        name: { type: [string, "null"], maxLength: 100 }
        date_of_birth: { type: [string, "null"], format: date, description: "yyyy-mm-dd, in the past, 1900 or later." }
    Role: { type: string, enum: [owner, admin, member], description: "owner > admin > member." }
    OrgRef:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
    Org:
      type: object
      properties:
        id: { type: string, example: org_3f2a9c11d4e5b6a7 }
        name: { type: string }
        kind: { type: string, enum: [personal, team] }
        plan: { type: string, example: free }
        role: { $ref: "#/components/schemas/Role" }
        created_at: { type: integer }
        members: { type: integer }
    Member:
      type: object
      properties:
        user_id: { type: string }
        username: { type: string }
        name: { type: [string, "null"] }
        role: { $ref: "#/components/schemas/Role" }
        joined_at: { type: integer }
    Invite:
      type: object
      properties:
        id: { type: string, example: inv_8c1f20aa }
        org_id: { type: string }
        code: { type: string, example: cwi_3f2a9c11d4e5b6a7 }
        url: { type: string, description: "The link to send: /console/#/join?code=…" }
        role: { $ref: "#/components/schemas/Role" }
        email: { type: [string, "null"] }
        max_uses: { type: [integer, "null"] }
        uses: { type: integer }
        created_by: { type: string }
        created_at: { type: integer }
        expires_at: { type: integer }
    Entitlement:
      type: object
      properties:
        product: { type: string, example: kicad }
        purchased_at: { type: integer }
        purchased_by: { type: [string, "null"] }
        amount_cents: { type: integer }
        source: { type: string, enum: [stripe, operator] }
    Application:
      type: object
      description: A professional application for sale (core/packages/catalog.json `products`), as one organization sees it.
      properties:
        id: { type: string, example: kicad }
        name: { type: string, example: KiCad }
        description: { type: string }
        price_cents: { type: integer, example: 49000 }
        price: { type: string, example: $490 }
        packages: { type: array, items: { type: string } }
        purchased: { type: boolean }
        purchased_at: { type: [integer, "null"] }
        purchased_by: { type: [string, "null"] }
    ProfessionalUsage:
      type: object
      description: Steps this month in environments running bought applications, against the plan's allowance, and the metered billing beyond it.
      properties:
        period_start: { type: integer }
        period_end: { type: integer }
        steps: { type: integer }
        steps_included: { type: integer }
        steps_left: { type: integer }
        unit: { type: object, properties: { steps_per_credit: { type: integer, example: 100 }, price_usd_per_credit: { type: number, example: 0.0025 }, usd_per_1000_steps: { type: number, example: 0.025 } } }
        metered: { type: object, properties: { enabled: { type: boolean }, requested: { type: boolean }, subscribed: { type: boolean }, status: { type: string }, monthly_cap_usd: { type: number }, credits: { type: number }, spend_usd: { type: number }, unreported_credits: { type: number } } }
    HeavyUsage:
      type: object
      description: Heavy-minutes this month (environments that ran on Heavy), against the plan's.
      properties:
        period_start: { type: integer }
        period_end: { type: integer }
        minutes: { type: number }
        minutes_included: { type: integer }
        minutes_left: { type: number }
    ApiKey:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        org_id: { type: string, description: The organization the key acts in. }
        created_by: { type: string, description: The account that made it. }
        prefix: { type: string, example: cw_live_3f9a }
        created_at: { type: integer }
        last_used_at: { type: [integer, "null"] }
        scopes: { type: array, minItems: 1, items: { $ref: "#/components/schemas/Scope" } }
    Harness:
      type: object
      description: A decider of an agent's steps, as one account sees it, with the facts it declares.
      properties:
        id: { type: string, example: computatrum-1.1-normal, description: "`<family>-<version>-<effort>`, or `scripted-<uuid>`." }
        family: { type: string, example: computatrum }
        version: { type: string, example: "1.0" }
        effort: { type: string, example: normal }
        title: { type: string }
        summary: { type: string }
        runs: { type: string, enum: [local, scripted, remote], description: "Where it decides: `local` (Computatrum's models, called from the loop), `scripted` (a stored program), `remote` (its own model server)." }
        emits:
          type: [array, "null"]
          items: { type: string }
          example: [press, click]
          description: "The action verbs it can answer; null means every verb. The loop's `done`, `fail`, `ask_user` and `wait` are always allowed."
        sends:
          type: array
          description: "What leaves the computer, and to whom: for a model harness, each part of a step and the companies whose models receive it, in the order they are tried. Empty when nothing leaves (a script)."
          items:
            type: object
            properties:
              what: { type: string, example: "the task text, the agent's instructions and the names of the controls on screen" }
              to: { type: string, example: "ComputaCo's own model server, hosted by Hugging Face" }
        latency:
          type: [object, "null"]
          description: How long a step takes when the harness has not seen its input before. Null when it has no wait of its own.
          properties:
            cold_s: { type: number, example: 60 }
            per: { type: string, example: screen of control names it has not read }
        budget_s: { type: integer, example: 600, description: How long one hosted task may run with this harness, in seconds. }
        requires: { type: array, items: { $ref: "#/components/schemas/Entitlement" }, description: "The entitlements it needs; empty means open to everyone." }
        licence:
          type: [object, "null"]
          description: The licence of its model, when that licence binds the use.
          properties:
            name: { type: string, example: CC BY-NC 4.0 }
            of: { type: string, example: TRIBE v2 }
        pixels: { type: boolean, description: Whether a screenshot is sent to it each step. }
        available: { type: boolean, description: Whether this account may use it in this organization. }
        why: { type: string, description: "One sentence saying which rule decided and what would change it." }
        attestation:
          type: [object, "null"]
          description: "Set when the account holds both `commercial` and `noncommercial-research` and the harness requires `noncommercial-research`: the account attests before its first task with it. Null otherwise."
          properties:
            required: { type: boolean }
            given: { type: boolean }
            text: { type: string, example: I will only use the navigator for noncommercial purposes. }
            why: { type: string }
        serving: { type: boolean, description: "For a remote harness: whether its model is available. A model that is asleep still counts: it starts when asked." }
        script: { $ref: "#/components/schemas/HarnessScript" }
    Entitlement:
      type: string
      enum: [noncommercial-research, vetted, commercial]
    AccountTag:
      type: object
      properties:
        tag: { type: string, example: researcher }
        by: { type: string, enum: [operator, email], description: "Who attested it: the operator, or a verified address (`academic`, `tier-1-university-student`)." }
        at: { type: integer, description: Unix ms. }
        evidence: { type: [string, "null"], description: "Free text; for `email`, the address's domain only." }
        expires: { type: [string, "null"], format: date-time }
        expired: { type: boolean, description: An expired tag grants nothing. }
    HarnessScript:
      type: object
      description: "A scripted harness's program (https://computaco.ai/docs/harnesses.html#scripted-harnesses). At most 200 steps and 64 KB."
      required: [steps]
      properties:
        steps:
          type: array
          items:
            type: object
            required: [action]
            properties:
              when: { type: object, description: "What the screen must show first: `text` and `focused` (regular expressions), `element` ({role, name}).", properties: { text: { type: string }, focused: { type: string }, element: { type: object, properties: { role: { type: string }, name: { type: string } } } } }
              action: { type: object, description: "An action of the loop; `element` is an outline id or {role, name}.", required: [verb], properties: { verb: { type: string } }, additionalProperties: true }
              then: { type: array, maxItems: 12, items: { type: object, additionalProperties: true } }
              thought: { type: string }
              now: { type: string }
              step: { type: string }
        done: { type: string, description: The summary when the script runs to its end. }
        patience: { type: integer, minimum: 0, maximum: 120, description: How many looks a step waits for its condition (10 when left out). }
    ScriptedHarnessBody:
      type: object
      required: [name, script]
      properties:
        name: { type: string, minLength: 1, maxLength: 120 }
        script: { $ref: "#/components/schemas/HarnessScript" }
    HarnessInput:
      type: object
      description: One step as the agent loop gives it to a harness.
      required: [task]
      properties:
        task: { type: string }
        taskId: { type: string }
        step: { type: integer }
        maxSteps: { type: integer }
        frame: { type: object, properties: { id: { type: string }, width: { type: integer }, height: { type: integer } } }
        tree: { type: object, properties: { available: { type: boolean }, text: { type: string }, elements: { type: array, items: { type: object, additionalProperties: true } } } }
        focused: { type: [object, "null"], properties: { title: { type: string }, class: { type: string } } }
        said: { type: array, items: { type: string } }
        history: { type: array, items: { type: string } }
        last: { type: object, properties: { worked: { type: boolean } } }
        image: { type: string, description: "The frame as a base64 JPEG; kept only for a harness with `pixels: true`." }
    HarnessDecision:
      type: object
      required: [action]
      properties:
        thought: { type: string }
        now: { type: string }
        step: { type: string }
        plan: { type: array, items: { type: string } }
        action: { type: object, required: [verb], properties: { verb: { type: string } }, additionalProperties: true }
        then: { type: array, items: { type: object, additionalProperties: true } }
        meta: { type: object, additionalProperties: true }
    HarnessPending:
      type: object
      properties:
        pending: { type: string, description: "The id to ask GET /v1/harnesses/decisions/{id} with." }
        retry_ms: { type: integer }
        state: { type: string, enum: [queued, running] }
    StateView:
      type: object
      description: A view a harness's internal state can be read in. A view belongs to no harness; any harness may name one.
      properties:
        title: { type: string, example: Predicted cortex }
        shows: { type: string }
        files: { type: array, items: { type: string }, description: The files a state in this view must hold. }
        optional: { type: array, items: { type: string }, description: The files it may hold. }
    Scope:
      type: string
      enum: [simulations, browser, templates, models, account]
      description: |
        What an API key may reach. `simulations`: /v1/simulations/** and /v1/packages/**. `browser`: /v1/browser/**.
        `templates`: /v1/templates/** and /v1/validate. `models`: /v1/models,
        /v1/chat/completions and /v1/agent/**. `account`: /v1/me/**, /v1/keys/**, /v1/orgs/**,
        /v1/billing/** and /v1/staff/**. A key without a route's scope gets a 403 `scope_missing`.
    ApiKeyCreated:
      allOf:
        - $ref: "#/components/schemas/ApiKey"
        - type: object
          properties:
            key: { type: string, description: The whole key. Shown once. }
    Plan:
      type: object
      properties:
        id: { type: string, enum: [free, pro, enterprise] }
        name: { type: string, example: Pro }
        price:
          description: null for Enterprise (by agreement).
          oneOf:
            - type: object
              properties:
                amount_cents: { type: integer, example: 2900 }
                currency: { type: string, example: usd }
                interval: { type: string, example: month }
            - type: "null"
        self_serve: { type: boolean, description: false for Enterprise. }
        contact: { type: [string, "null"], example: "mailto:sales@computaco.ai" }
        quotas: { $ref: "#/components/schemas/Quotas" }
    Discount:
      type: object
      properties:
        code: { type: string, example: FIRST100 }
        percent_off: { type: integer, example: 20 }
        duration: { type: string, enum: [forever, once, repeating], description: "forever: for the life of the subscription." }
        duration_in_months: { type: [integer, "null"] }
    Billing:
      type: object
      properties:
        plan: { type: string, enum: [free, pro, enterprise, staff], description: "staff: an organization a staff account owns (unlimited; never sold, never stored)." }
        status: { type: string, enum: [none, active, past_due, canceled] }
        renews_at: { type: [integer, "null"], description: Unix ms of the next charge. }
        cancel_at_period_end: { type: boolean }
        grace_until: { type: [integer, "null"], description: "Past due: Pro is kept until then (Unix ms)." }
        discount: { oneOf: [{ $ref: "#/components/schemas/Discount" }, { type: "null" }] }
        referral_code: { type: [string, "null"], description: The code given at sign-up, applied at upgrade. }
        has_customer: { type: boolean, description: The account has been through checkout (the portal works). }
        configured: { type: boolean, description: Payment is open. }
    Quotas:
      type: object
      properties:
        simulations_max: { type: integer, example: 8 }
        agents_per_simulation: { type: integer, example: 16, description: External agents one environment holds. }
        snapshots_per_simulation: { type: integer, example: 16 }
        templates_max: { type: integer, example: 32 }
        society_people_max: { type: integer, example: 32, description: Simulated people one environment's society holds. }
        api_keys_max: { type: integer, example: 10 }
        definition_bytes: { type: integer, example: 4194304 }
        requests_per_minute: { type: integer, example: 600 }
        steps_per_minute: { type: integer, example: 1200 }
        renders_per_minute: { type: integer, example: 120 }
        model_calls_per_day: { type: integer, example: 500, description: Model calls societies make for their LLM people. }
        agent_minutes_5h: { type: number, example: 15, description: "Computatrum agent-minutes (the time the agent works on a task) in a rolling 5-hour window." }
        agent_minutes_week: { type: number, example: 30, description: Computatrum agent-minutes in a rolling week. }
        heavy_minutes_per_month: { type: integer, example: 0, description: "Minutes a month the organization's environments may run on Heavy; none on Free." }
    Usage:
      type: object
      properties:
        simulations: { type: integer }
        templates: { type: integer }
        api_keys: { type: integer }
        this_minute: { type: object, properties: { requests: { type: integer }, steps: { type: integer }, renders: { type: integer } } }
        today: { type: object, properties: { model_calls: { type: integer } } }
        totals: { type: object, properties: { requests: { type: integer }, steps: { type: integer }, renders: { type: integer }, simulations_created: { type: integer }, model_calls: { type: integer } } }
    Template:
      type: object
      description: A template in GET /v1/templates. A built-in one's `id` is its name; an own one's, its stored id.
      properties:
        id: { type: string, example: agent-desktop }
        name: { type: string }
        source: { type: string, enum: [builtin, own] }
        description: { type: string }
        definition_id: { type: string, description: The definition's own id. }
        machines:
          type: array
          items:
            type: object
            properties:
              id: { type: string }
              user: { type: [string, "null"] }
              profile: { type: [string, "null"] }
              theme: { type: [string, "null"] }
              presentation: { type: [string, "null"], description: "desktop | laptop | phone | server (the machine's own, or metadata.device_presentations' kind); null when the definition does not say" }
        services: { type: integer }
        internet: { type: boolean }
        products: { type: array, items: { type: string }, example: [freecad], description: "The professional applications booting it needs (402 plan_required or application_not_purchased until the organization has them)." }
        host: { type: string, description: The Lightning place it boots in when no procedure or place is given. }
        app_modules: { type: array, items: { type: string }, description: The application modules its machines can launch. }
        procedures: { type: integer, description: Procedures shipped with it (built in only). }
        societies: { type: integer, description: Society specs shipped with it (built in only). }
        boots: { type: boolean, description: "Built in: whether it boots here (`boot_error` says why not)." }
        boot_error: { type: [string, "null"] }
        bytes: { type: integer, description: Own templates' definition size. }
        created_at: { type: integer }
        updated_at: { type: integer }
    Definition:
      type: object
      description: The world schema (https://computaco.ai/docs/world-schema.html). `schema_version` must be 1.
      required: [schema_version, id]
      properties:
        schema_version: { type: integer, const: 1 }
        id: { type: string }
        internet: { type: boolean }
        profiles: { type: array, items: { type: object } }
        computers: { type: array, items: { $ref: "#/components/schemas/Computer" } }
        network: { type: object }
        services: { type: array, items: { $ref: "#/components/schemas/Service" } }
        internet_overlays: { type: object }
        metadata: { type: object }
      additionalProperties: true
    Computer:
      type: object
      required: [id, profile, address, user]
      properties:
        id: { type: string }
        profile: { type: string, example: ubuntu }
        address: { type: string, example: 10.0.0.10 }
        user: { type: string }
        node: { type: string }
        presentation: { type: string, enum: [desktop, laptop, phone, server] }
        initial_files: { type: object, additionalProperties: { type: string }, description: "Path → content, seeded on boot." }
        installed_apps: { type: array, items: { type: string } }
        packages: { type: array, items: { type: string } }
      additionalProperties: true
    Node:
      type: object
      properties:
        id: { type: string }
        address: { type: string }
        zone: { type: string, enum: [local, internet, host] }
      additionalProperties: true
    Link:
      type: object
      required: [from, to]
      properties:
        from: { type: string, description: A node id. }
        to: { type: string }
        bidirectional: { type: boolean, default: true }
        latency_us: { type: integer, default: 10 }
        loss_per_million: { type: integer, default: 0 }
      additionalProperties: true
    Service:
      type: object
      required: [id, kind]
      properties:
        id: { type: string }
        kind: { type: string, example: mail }
        node: { type: string }
        domains: { type: array, items: { type: string } }
        port: { type: integer }
        tls: { type: boolean }
        initial_state: { type: object }
      additionalProperties: true
    Topology:
      type: object
      description: A graph view of a definition, for a console to draw. `links[].id` is the link's index in `network.links`.
      properties:
        world: { type: string, description: The definition's id. }
        live: { type: boolean, description: true for a running environment (only machines change live). }
        internet: { type: boolean }
        machines:
          type: array
          items:
            type: object
            properties:
              id: { type: string }
              profile: { type: string }
              user: { type: string }
              address: { type: string }
              node: { type: string }
              theme: { type: [string, "null"] }
              presentation: { type: [string, "null"], description: "desktop | laptop | phone | server (the machine's own, or metadata.device_presentations' kind)" }
              installed_apps: { type: array, items: { type: string } }
              desktop_apps: { type: [array, "null"], description: "metadata.desktop_apps for this machine, when declared." }
              packages: { type: array, items: { type: string } }
              initial_files: { type: array, items: { type: string }, description: The seeded files' paths. }
              kind: { type: string, enum: [simulator, recording], description: "In a topology: what the machine is. A simulator is the engine's; a recording is frames captured somewhere else." }
              interfaces: { type: array, items: { type: string, enum: [screen, input, launch, files, agents] }, description: "In a topology: what the machine can do. A simulator has all five, a recording `screen` only." }
        nodes: { type: array, items: { $ref: "#/components/schemas/Node" } }
        links: { type: array, items: { allOf: [{ $ref: "#/components/schemas/Link" }, { type: object, properties: { id: { type: integer } } }] } }
        services: { type: array, items: { type: object, properties: { id: { type: string }, kind: { type: string }, node: { type: string }, domains: { type: array, items: { type: string } }, port: { type: integer } } } }
        dns: { type: array, items: { type: object } }
        themes: { type: object, additionalProperties: { type: string } }
        implicit_lan: { type: boolean }
    TopologyEdit:
      type: object
      description: |
        One edit. `op` is one of:
        `add_machine {computer, node?, links?, theme?}`, `update_machine {id, set}` (merged into the machine),
        `remove_machine {id}` (also its links, node and theme),
        `add_node {node}`, `remove_node {id}`,
        `add_link {link}`, `update_link {id, set}`, `remove_link {id}`,
        `add_service {service}`, `update_service {id, set}`, `remove_service {id}`,
        `set_theme {machine, theme}` (theme `null` removes it), `set_presentation {machine, presentation}`,
        `set_internet {internet}`, `set_implicit_lan {implicit_lan}`, `set_metadata {key, value}`.
      required: [op]
      properties:
        op: { type: string }
      additionalProperties: true
    Clock:
      type: object
      properties:
        state_hash: { type: string }
        tick: { type: integer, description: The environment's clock, logical microseconds. }
    SimulationSummary:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        source: { type: string, description: "`builtin:agent-desktop`, `template:<id>`, `definition`, `fork:<simulation id>` or `import`." }
        definition_id: { type: string }
        seed: { type: integer }
        created_at: { type: integer }
        machines: { type: array, items: { type: string } }
        forked_from: { type: [string, "null"], description: The environment it was forked from. }
        place: { $ref: "#/components/schemas/Place" }
    Simulation:
      allOf:
        - $ref: "#/components/schemas/SimulationSummary"
        - $ref: "#/components/schemas/Clock"
        - type: object
          properties:
            agents: { type: integer, description: External agents granted. }
            snapshots: { type: integer }
            forks: { type: array, items: { type: string }, description: The environments forked from this one, oldest first. }
            society: { oneOf: [{ $ref: "#/components/schemas/SocietyHeader" }, { type: "null" }] }
            idle_ttl: { type: [integer, "null"], description: "Its idle lifetime in seconds, or null: kept until deleted." }
            expires_at: { type: [integer, "null"], description: "When it deletes itself if nothing reaches it first (ms since the epoch), or null." }
            professional: { type: array, items: { type: string }, description: The professional applications it runs (its steps are metered). }
            boot_ms: { type: number, description: Engine boot (or import) time on this request. }
            resident: { type: boolean, description: Whether the engine instance was in memory (false = rebuilt from storage on this request). }
            head: { type: [string, "null"], description: "The snapshot the environment's state came from last: the newest taken or restored. null before the first." }
            place: { allOf: [{ $ref: "#/components/schemas/Place" }, { type: object, properties: { reason: { type: string, example: it fits Lightning, description: "Why it runs there, in a phrase, as decided when it booted." } } }] }
            memory: { $ref: "#/components/schemas/Memory" }
    Memory:
      type: object
      description: The memory the environment holds (other environments in the same place may share it).
      properties:
        wasm_bytes: { type: integer, description: The engine's. }
        module_bytes: { type: object, additionalProperties: { type: integer }, description: Each application module's instances. }
        total_wasm_bytes: { type: integer }
    SimulationPlaced:
      description: A new environment (booted, imported or forked), with the places that refused it before the one it runs in.
      allOf:
        - $ref: "#/components/schemas/Simulation"
        - type: object
          properties:
            refused: { type: array, items: { $ref: "#/components/schemas/PlaceRefusal" } }
    PlaceChoice:
      description: >
        Where the environment runs (https://computaco.ai/docs/cloud-api.html § Places), on
        Computaco's infrastructure: `lightning` (starts at once; the Lightning place that carries
        most of what it launches), `heavy` (room for big worlds and every application, metered
        in Heavy-minutes), a Lightning place's id, or a list of those tried in order. A place
        moves to the next on its own refusal (402 `plan_required`, 429 `quota_exceeded`, 507
        `definition_too_large`); the last one's refusal is the answer. Left out: Lightning first
        (a fork: its parent's place), then Heavy; Heavy first only for a stated reason. 400 for
        a word that is no place, 503 for a place not deployed.
      oneOf:
        - { type: string, enum: [lightning, heavy, core, office, media] }
        - { type: array, minItems: 1, items: { type: string, enum: [lightning, heavy, core, office, media] } }
      example: [heavy, lightning]
    Place:
      type: object
      description: Where an environment executes.
      properties:
        id: { type: string, example: core, description: "A Lightning place's id (core, office, media), or heavy." }
        kind: { type: string, enum: [lightning, heavy], example: lightning, description: "`lightning` (starts at once, small, no charge) or `heavy` (room for big worlds and every application; starts in seconds)." }
        metered: { type: boolean, description: Whether its time is counted in Heavy-minutes. }
        modules: { type: array, items: { type: string }, description: The application modules it carries. }
    PlaceRefusal:
      type: object
      description: A place that was tried before the one the environment runs in, and its own refusal.
      properties:
        place: { type: string, example: heavy }
        code: { type: string, example: plan_required }
        message: { type: string }
    Snapshot:
      type: object
      properties:
        id: { type: string }
        label: { type: string }
        state_hash: { type: string }
        tick: { type: integer }
        bytes: { type: integer }
        created_at: { type: integer }
        parent: { type: [string, "null"], description: "The snapshot the state came from: the head when this one was taken. null: the environment's start." }
        author: { type: [string, "null"], description: The username that took it. }
        frames: { type: array, items: { type: string }, description: "The machines a picture was kept for (`GET …/snapshots/{id}/frames/{machine}`)." }
    Snapshots:
      type: object
      properties:
        snapshots: { type: array, items: { $ref: "#/components/schemas/Snapshot" } }
        head: { type: [string, "null"] }
    History:
      type: object
      properties:
        simulation: { type: string, description: The environment asked about. }
        simulations:
          type: array
          description: The family, the furthest ancestor first.
          items:
            type: object
            properties:
              id: { type: string }
              name: { type: string }
              source: { type: string }
              created_at: { type: integer }
              parent: { type: [string, "null"], description: The environment it was forked from; null for the ancestor. }
              origin:
                type: [object, "null"]
                description: Where a fork left its parent; null for the ancestor, and for a fork made before 2026-11-12.
                properties:
                  snapshot: { type: [string, "null"], description: "The parent's snapshot it was forked from, or the parent's head then." }
                  tick: { type: [integer, "null"], description: The parent's clock then; null for a fork from a snapshot. }
                  state_hash: { type: string }
              head: { type: [string, "null"] }
              place: { $ref: "#/components/schemas/Place" }
              snapshots: { type: array, items: { $ref: "#/components/schemas/Snapshot" } }
    Recording:
      type: object
      description: A recording of a real application, whose machines are frames captured somewhere else. Nothing executes it, so it has no place, and every write to it is a 409.
      properties:
        id: { type: string, example: "r~run-12~eda-divider-s3", description: "`r~<run>~<job>`." }
        name: { type: string }
        source: { type: string, description: "`recording:<run>`." }
        created_at: { type: integer }
        machines: { type: array, items: { type: string }, example: [reference, simulator] }
        place: { type: "null" }
        recording:
          type: object
          properties:
            run: { type: string }
            job: { type: string }
            label: { type: string }
            iteration: { type: [integer, string, "null"] }
            application: { type: string }
            fidelity: { type: object, properties: { overall: { type: [number, "null"] }, semantic: { type: [number, "null"] }, delivery: { type: [number, "null"] } } }
          additionalProperties: true
    RecordingDetail:
      allOf:
        - $ref: "#/components/schemas/Recording"
        - type: object
          properties:
            computers:
              type: array
              items: { type: object, properties: { id: { type: string }, kind: { type: string, const: recording }, title: { type: string }, interfaces: { type: array, items: { type: string }, example: [screen] } } }
            tick: { type: integer, description: Its last step. }
            agents: { type: integer, const: 0 }
            snapshots: { type: integer, const: 0 }
            forks: { type: array, items: { type: string }, maxItems: 0 }
            forked_from: { type: "null" }
            society: { type: "null" }
    RecordingHistory:
      type: object
      properties:
        recording: { type: string }
        steps:
          type: array
          description: One moment for each step of the recording.
          items:
            type: object
            properties:
              step: { type: integer }
              stimulus: { description: What was done at the step. }
              failed: { type: string, description: Why the step was not delivered. }
              frames: { type: boolean, description: Whether the step's frames were published. }
            additionalProperties: true
    AgentConfig:
      type: object
      description: An external agent's grant. Defaults give a desktop actor on the first machine.
      properties:
        actor: { type: string, description: The machine user the actor acts as (default the machine's user). }
        machines: { type: array, items: { type: string }, description: "The machines the agent is connected to; empty when it was disconnected from each." }
        actions:
          type: array
          items: { type: string }
          default: [pointer.v1, keyboard.v1, application.v1]
          example: [pointer.v1, keyboard.v1, application.v1, browser.v1]
        observations: { type: array, items: { type: string }, default: [semantic.v1] }
        action_budget: { type: integer, default: 100000 }
        label: { type: string }
      additionalProperties: true
    Agent:
      type: object
      description: An external agent.
      properties:
        id: { type: string, example: agent_1 }
        kind: { type: string, const: external }
        session: { type: string, description: "The engine's session id (`session-0`)." }
        label: { type: string }
        instructions: { type: string, maxLength: 4000, description: Its standing instructions. }
        may_message: { $ref: "#/components/schemas/MayMessage" }
        config: { $ref: "#/components/schemas/AgentConfig" }
        created_at: { type: integer }
        token_prefix: { type: string }
        state: { $ref: "#/components/schemas/ThreadState" }
    MayMessage:
      type: array
      items: { type: string }
      example: [person, agent_3]
      description: "Whom the agent may message: `person` (it may ask the person a question) or the ids of other agents of the environment. Its edges of the communication graph. Empty for a new agent."
    CommunicationEdge:
      type: object
      required: [from, to]
      properties:
        from: { type: string, description: An agent's id. }
        to: { type: string, description: "An agent's id, or `person`." }
    CommunicationGraph:
      type: object
      description: "Who may send a message to whom. The owner can always prompt any agent: that is authority, not an edge. An edge to an agent that was removed is not listed."
      properties:
        nodes:
          type: array
          items:
            type: object
            properties:
              id: { type: string, description: "`person`, or an agent's id." }
              kind: { type: string, enum: [person, hosted, external] }
              name: { type: string }
              machine: { type: [string, "null"] }
              harness: { type: string, description: A hosted agent's harness. }
              state: { $ref: "#/components/schemas/ThreadState" }
        edges: { type: array, items: { $ref: "#/components/schemas/CommunicationEdge" } }
    HostedAgentCreate:
      type: object
      required: [kind]
      properties:
        kind: { type: string, const: hosted }
        machine: { type: string, description: The machine it drives (may be left out when the environment has one). }
        name: { type: string, maxLength: 200 }
        harness: { type: string, default: computatrum-1.1-normal, description: "What decides its steps: a harness id from GET /v1/harnesses that the account may use. Checked when the agent is made (404 harness_not_found, 403 harness_access_required) and again when each task starts. A model harness's id of another version names the same family and effort at the version there is." }
        instructions: { type: string, maxLength: 4000, description: "Who it is and what it is for: given to it with every task." }
        may_message: { allOf: [{ $ref: "#/components/schemas/MayMessage" }], description: "Whom it may message. Left out, nobody: it never asks the person and decides for itself." }
    HostedAgent:
      type: object
      description: >
        An agent the platform runs: Computatrum's agent loop, driving one machine as its user,
        with what a person at it may do. A prompt in its thread starts a task (one sent while a
        task runs is heard by that task); what it does is written into the thread. It asks the
        person only when `may_message` holds `person`. Its model calls are billed to the
        environment's organization's agent-minutes. It has no token.
      properties:
        id: { type: string, example: agent_2 }
        kind: { type: string, const: hosted }
        name: { type: string }
        machine: { type: [string, "null"], description: "The machine it drives; null when it is connected to none." }
        harness: { type: string, example: computatrum-1.1-normal, description: The harness that decides its steps. }
        instructions: { type: string, maxLength: 4000, description: Its standing instructions. }
        may_message: { $ref: "#/components/schemas/MayMessage" }
        session: { type: string }
        config:
          allOf:
            - $ref: "#/components/schemas/AgentConfig"
            - type: object
              properties:
                screen: { type: array, items: { type: integer }, minItems: 2, maxItems: 2, description: "The screen it looks at and acts in: [1280, 800] for a desktop, [390, 844] for a phone." }
        created_at: { type: integer }
        state: { $ref: "#/components/schemas/ThreadState" }
    ThreadState:
      type: string
      enum: [idle, working, asking, stopped]
      description: "`asking` while a question is open (the agent asked the person and no prompt came after it: the run waits on it, or is parked), `working` after a `started` status (or while a prompt waits for a hosted agent's loop), `stopped` after a `stopped` status, else `idle`."
    Message:
      type: object
      required: [seq, role, text, at]
      description: "One message of an agent's thread. The role's own fields come with it (https://computaco.ai/docs/cloud-api.html § Agents): a status's `status`, an action's `action` (the action as sent), `ok`, `changed`, `error`, `step`, `step_name`, `batch`, and a hosted agent's `screen` and `after` (GET …/screens/{digest}), an agent message's `kind` and that kind's fields."
      properties:
        seq: { type: integer, minimum: 1, description: Its number in the thread, in order; never reused. }
        role: { type: string, enum: [person, peer, agent, action, status], description: "person: a prompt; peer: a message from another agent; agent: what the agent thinks and says; action: what it did on the machine; status: started, finished, stopped, failed or waiting." }
        text: { type: string }
        at: { type: [integer, "null"], description: Milliseconds since the epoch when it was added; null in a simulated agent's thread. }
        status: { type: string, enum: [started, finished, stopped, failed, waiting], description: "`waiting`: the run is parked on a question (`question`, `options`); the answer continues it, in a `started` status whose `resumes` is this message's seq." }
        kind: { type: string, enum: [thought, question, tell, said], description: "An agent message's kind. thought: why it does the next thing (`step`, `step_name`, `now`, `plan`, a hosted agent's `screen`, and when its harness surfaces them `prefers` and `state`: docs/harnesses.md § The state views); question: a question to the person (`question: true`, `options`, `step`); tell: a message it sent to another agent (`to`, `to_name`, `delivered`, `why`, `step`); said: anything else." }
        options: { type: array, maxItems: 4, items: { type: string }, description: The choices of a question. }
        heard: { type: integer, description: "On a prompt or a peer's reply: the step of the working run that took it." }
        queued: { type: boolean, description: On a prompt that waits to be the next task of a harness that does not hear. }
        answers: { type: integer, description: "On a prompt: the seq of the question it answered." }
        from: { type: string, description: "On a peer's message: the agent that sent it." }
        from_name: { type: string }
        reply: { type: boolean, description: "On a peer's message: it is the summary of the task a message of this agent started there. A reply starts no task." }
        hops: { type: integer, description: "On a peer's message: its place in a chain of messages between agents, at most 8." }
      additionalProperties: true
    AgentCreated:
      allOf:
        - $ref: "#/components/schemas/Agent"
        - type: object
          properties:
            token: { type: string, description: "The actor token (`cwa_<simulation id>_...`). Shown once." }
    SimulatedAgent:
      type: object
      description: One of the society's people. It has no token; the environment runs it.
      properties:
        id: { type: string, description: The person's id in the society. }
        kind: { type: string, const: simulated }
        name: { type: string }
        population: { type: string }
        policy: { type: [string, "null"], description: "Its policy's kind (`scripted`, `llm`, `procedure`, `harness`, `idle`)." }
        harness: { type: [string, "null"], example: computatrum-1.1-normal, description: "The harness that decides its turns, when its policy is `harness`; null otherwise." }
        machines: { type: array, items: { type: string } }
        rules: { type: array, items: { type: string } }
        activations: { type: integer }
        actions: { type: integer }
    Action:
      type: object
      required: [family, op]
      properties:
        family: { type: string, example: pointer.v1 }
        op: { type: string, example: click }
        machine: { type: string }
        payload: { type: object, example: { x: 640, y: 400, width: 1280, height: 800 } }
    StepResult:
      type: object
      properties:
        outcomes:
          type: array
          items:
            type: object
            properties:
              success: { type: boolean }
              value: {}
              error: { type: [object, "null"] }
              effect: { type: object }
        state_hash: { type: string }
        tick: { type: integer }
        elapsed_ms: { type: number }
        outside:
          type: object
          description: "Present when the step reached real hosts (docs/cloud-api.md § Real hosts): the runs it took, the requests sent, the bytes received and the time spent."
          properties:
            rounds: { type: integer }
            requests: { type: integer }
            bytes: { type: integer }
            elapsed_ms: { type: number }
    Element:
      type: object
      properties:
        role: { type: string }
        label: { type: string }
        value: { type: string }
        interaction: { type: string, example: "shell:launch:editor" }
        rect: { type: object, properties: { x: { type: integer }, y: { type: integer }, width: { type: integer }, height: { type: integer } } }
        center: { type: array, items: { type: integer } }
        focused: { type: boolean }
        disabled: { type: boolean }
    Gesture:
      type: object
      description: "A procedure gesture (https://computaco.ai/docs/expert-procedures.html) — `{do: click|double_click|drag|scroll|type|key|click_model, target?, text?, key?, at?}`."
      required: [do]
      properties:
        do: { type: string }
        target: { type: object, properties: { role: { type: string }, label: { type: string }, text: { type: string }, interaction: { type: string }, app: { type: string } } }
      additionalProperties: true
    Procedure:
      type: object
      description: An expert procedure (https://computaco.ai/docs/expert-procedures.html).
      required: [id, phases]
      additionalProperties: true
    ProcedureRef:
      type: object
      description: Exactly one of `procedure` (inline) or `ref` (`{template, id}`, shipped with a built-in template).
      properties:
        procedure: { $ref: "#/components/schemas/Procedure" }
        ref: { type: object, properties: { template: { type: string }, id: { type: string } } }
        seed: { type: integer, default: 1 }
        overrides: { type: object }
    ProcedureInstance:
      type: object
      properties:
        procedure: { $ref: "#/components/schemas/Procedure" }
        seed: { type: integer }
        values: { type: object }
    ProjectOptions:
      type: object
      properties:
        width: { type: integer, default: 1280 }
        height: { type: integer, default: 800 }
        mode: { type: string, enum: [gui, tool], default: gui }
        typing: { type: string, enum: [text, keys], default: text }
    Demonstration:
      type: object
      properties:
        completed: { type: boolean }
        failure: {}
        steps: { type: array, items: { type: object } }
        verification: { $ref: "#/components/schemas/Verification" }
        state_hash: { type: string }
        counts: { type: object }
    Verification:
      type: object
      properties:
        passed: { type: boolean }
        checks: { type: array, items: { type: object, properties: { check: { type: object }, passed: { type: boolean }, detail: {} } } }
    SocietySpec:
      type: object
      description: A society spec (https://computaco.ai/docs/societies.html § The spec).
      additionalProperties: true
    SocietyBoot:
      type: object
      description: A society to boot an environment with. Exactly one of `spec` and `id`.
      properties:
        spec: { $ref: "#/components/schemas/SocietySpec" }
        id: { type: string, description: "A society shipped with the boot's built-in template (GET /v1/templates/{template_id}/societies)." }
        rule: { type: string, description: One extra rule appended to everyone's rules at boot. }
        rounds: { type: integer, minimum: 1, description: The planned round count (the spec's clock otherwise). }
        journal:
          description: "Model replies to replay from: `\"builtin\"` (the journal recorded beside a shipped society, with `id`), the JSON-lines text of a journal file, or a list of `{key, reply}`. A header line is skipped."
          oneOf: [{ type: string }, { type: array, items: { type: object, properties: { key: { type: string }, reply: {} } } }]
    SocietyHeader:
      type: object
      properties:
        spec_id: { type: string }
        people: { type: integer }
        round: { type: integer, description: Rounds completed. }
        rounds: { type: integer, description: The planned round count. }
        forked_at: { type: [integer, "null"], description: The round its parent was at when this environment was forked from it. }
    Society:
      allOf:
        - $ref: "#/components/schemas/SocietyHeader"
        - type: object
          properties:
            metrics: { type: object, additionalProperties: { type: number }, description: The outcomes now (the last round's). }
            journal: { type: integer, description: Model replies held. }
    SocietySummary:
      type: object
      properties:
        simulation: { type: string }
        spec_id: { type: string }
        round: { type: integer }
        rounds: { type: integer }
        forked_at: { type: [integer, "null"] }
        per_round: { type: object, additionalProperties: { type: object, additionalProperties: { type: number } }, description: "round → metric → value, this environment's" }
        state_hashes: { type: array, items: { type: string } }
        forks:
          type: array
          items:
            type: object
            properties:
              id: { type: string }
              forked_at: { type: integer }
              round: { type: integer }
              rounds: { type: integer }
              per_round: { type: object }
              state_hashes: { type: array, items: { type: string } }
        comparisons:
          type: array
          description: One per round forks were made at; its arms are this environment (first, the control) and those forks, keyed by environment id.
          items: { $ref: "#/components/schemas/ForkComparison" }
    ForkComparison:
      type: object
      properties:
        fork_at: { type: integer }
        society: { type: string }
        seed: { type: integer }
        people: { type: integer }
        rounds: { type: integer }
        preregistration: { type: string, description: SHA-256 of the spec's outcomes, checks and arms. }
        uncompiled: { type: array, items: { type: string } }
        prefix: { type: array, items: { type: object, properties: { round: { type: integer }, state_hash: { type: string } } } }
        arms:
          type: object
          additionalProperties:
            type: object
            properties:
              outcomes: { type: object, additionalProperties: { type: number }, description: Each outcome metric at its last round. }
              per_round: { type: object, additionalProperties: { type: object, additionalProperties: { type: number } }, description: "round → metric → value" }
              state_hashes: { type: array, items: { type: string } }
              aligned: { type: boolean, description: Every activation ran at its slot tick. }
              decisions: { type: integer }
              activations: { type: integer }
              actions: { type: integer }
              checks: { type: object, additionalProperties: { type: boolean } }
        effects:
          type: object
          additionalProperties:
            type: object
            properties:
              preregistered: { type: boolean }
              direction: { type: string }
              arms: { type: object, additionalProperties: { type: object, properties: { value: { type: number }, difference: { type: number } } } }
        divergence:
          type: object
          additionalProperties: { type: array, items: { type: object, properties: { round: { type: integer }, same_state: { type: boolean }, screens_differ: { type: integer }, people_reached: { type: integer } } } }
        crn:
          type: object
          additionalProperties: { type: object, properties: { holds: { type: boolean }, same_input: { type: integer }, violations: { type: array, items: { type: object } } } }
      additionalProperties: true
    RoundEnd:
      type: object
      properties:
        arm: { type: string }
        round: { type: integer }
        state_hash: { type: string }
        tick: { type: integer }
        active: { type: array, items: { type: string } }
        decisions: { type: integer }
        metrics: { type: object }
        checks: { type: array, items: { type: object } }
        elapsed_ms: { type: number }
    PendingDecision:
      type: object
      properties:
        arm: { type: string }
        round: { type: integer }
        person: { type: string }
        key: { type: string, description: The journal key the answer must be posted under. }
        messages: { type: array, items: { type: object }, description: The prompt the model would be asked. }
    Metering:
      type: object
      description: >
        What a Computatrum call was charged: its agent-minutes (the plan's windows) and its model
        cost in credits (pay as you go). A credit is $0.001 of model cost at the providers' peak
        list prices.
      properties:
        cost_micro: { type: integer, example: 543, description: Model cost in micro-dollars. }
        credits: { type: number, example: 0.543 }
        billed: { type: string, enum: [plan, payg] }
        ms: { type: integer, example: 2140, description: "The call's own time plus the gap since its task's previous call, at most 15,000 ms (none without a task)." }
        minutes: { type: number, example: 0.04 }
        task: { type: string, description: The task the call was counted in, when it named one. }
        usd: { type: number, example: 0.001358, description: "Pay as you go only: what it adds to the month's spend." }
    AgentWindow:
      type: object
      description: One rolling window, in agent-minutes.
      properties:
        limit: { type: number, example: 120 }
        used: { type: number, example: 31.25 }
        remaining: { type: number, example: 88.75, description: 0 when full. }
        started_at: { type: [integer, "null"], description: "ms; null when no window is running (the next call starts one)." }
        resets_at: { type: [integer, "null"] }
        full: { type: boolean }
        fair_use: { type: boolean, description: "Present (true) when the window is full because its calls' model cost reached the fair-use ceiling, 15 credits for each minute of its limit." }
    Payg:
      type: object
      properties:
        enabled: { type: boolean, description: Requested and its subscription active. }
        requested: { type: boolean }
        subscribed: { type: boolean }
        status: { type: string, enum: [none, active, past_due, canceled] }
        mode: { type: string, enum: [overflow, always] }
        monthly_cap_usd: { type: number, example: 20 }
        period_start: { type: integer, description: The calendar month (UTC) the cap counts. }
        period_end: { type: integer }
        credits: { type: number }
        spend_usd: { type: number }
        unreported_credits: { type: number, description: Not yet sent to Stripe's meter (whole credits are sent each minute). }
    AgentUsage:
      type: object
      properties:
        plan: { type: string }
        unit:
          type: object
          properties:
            name: { type: string, example: minute, description: The windows' unit. }
            task_gap_cap_s: { type: number, example: 15 }
            payg: { type: object, properties: { name: { type: string, example: credit }, model_cost_usd: { type: number, example: 0.001 }, price_usd: { type: number, example: 0.0025 } } }
        windows: { type: object, properties: { five_hour: { $ref: "#/components/schemas/AgentWindow" }, weekly: { $ref: "#/components/schemas/AgentWindow" } } }
        payg: { $ref: "#/components/schemas/Payg" }
        last_30_days:
          type: array
          items:
            type: object
            properties:
              kind: { type: string, enum: [chat, vision] }
              model: { type: string }
              calls: { type: integer }
              tokens_in: { type: integer }
              tokens_cached: { type: integer }
              tokens_out: { type: integer }
              images: { type: integer }
              minutes: { type: number }
              credits: { type: number }
              payg_credits: { type: number }
