{
  "openapi": "3.1.0",
  "info": {
    "title": "Coronium workspace API",
    "version": "0.1.0",
    "description": "Account creation, sign-in, account settings and signed-in account reads on the current origin. A session travels as an HttpOnly cookie. Creating an account needs no details and returns one access code, shown once, that signs the account in. An email address and a password are optional additions. While the operator keeps registration closed, account creation answers registration_closed. Every refusal carries a code, a cause and a fix. The buyer network API, an MCP server and payments are not served here."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/app/api/signup": {
      "post": {
        "operationId": "createAccount",
        "summary": "Create an account with no details",
        "description": "Send an empty JSON object. The reply sets the session cookie and returns the access code and the first proxy credential once. The access code is the only way back into the account unless both an email address and a password are added.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The account, its proxy credential and its access code",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "accountId",
                    "credential",
                    "accessCode"
                  ],
                  "properties": {
                    "accountId": {
                      "type": "string"
                    },
                    "credential": {
                      "type": "string"
                    },
                    "accessCode": {
                      "type": "string",
                      "pattern": "^cr_[A-Za-z0-9_-]{43}$"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "registration_closed: the operator has closed registration"
          },
          "429": {
            "description": "Too many attempts from this address"
          }
        }
      }
    },
    "/app/api/login": {
      "post": {
        "operationId": "signIn",
        "summary": "Sign in with the access code, or with email and password",
        "description": "Send exactly one of the two bodies. A wrong code, a wrong email or password and an account without a password are refused alike. Signing in does not replace the access code.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "required": [
                      "code"
                    ],
                    "properties": {
                      "code": {
                        "type": "string",
                        "pattern": "^cr_[A-Za-z0-9_-]{43}$"
                      }
                    },
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "required": [
                      "email",
                      "password"
                    ],
                    "properties": {
                      "email": {
                        "type": "string",
                        "format": "email",
                        "maxLength": 254
                      },
                      "password": {
                        "type": "string",
                        "maxLength": 256
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in. The reply sets the session cookie."
          },
          "4XX": {
            "description": "The sign-in details were not accepted, or too many attempts came from this address. Read the returned code, cause and fix."
          }
        }
      }
    },
    "/app/api/account/email": {
      "post": {
        "operationId": "addEmail",
        "summary": "Add or change the account's email address",
        "security": [
          {
            "customer": []
          }
        ],
        "description": "The address stays pending until the single-use link mailed to it is confirmed within 30 minutes. The answer is the same whether or not another account uses the address.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "A confirmation link was requested for the address"
          },
          "401": {
            "description": "Sign in to this workspace"
          },
          "503": {
            "description": "email_unavailable: this service has no mail sender, and nothing was stored"
          }
        }
      }
    },
    "/app/api/account/email/confirm": {
      "post": {
        "operationId": "confirmEmail",
        "summary": "Confirm a pending email address",
        "description": "Send the token from the fragment of the mailed link. No session is needed. The page at /confirm-email does this on a button press; opening the link alone confirms nothing.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token"
                ],
                "properties": {
                  "token": {
                    "type": "string",
                    "pattern": "^ce_[A-Za-z0-9_-]{43}$"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "The address is now the account's email"
          },
          "409": {
            "description": "The address can no longer be added to this account"
          },
          "4XX": {
            "description": "The token is unknown, used or expired. Read the returned code, cause and fix."
          }
        }
      }
    },
    "/app/api/account/password": {
      "post": {
        "operationId": "setPassword",
        "summary": "Set or change the account's password",
        "security": [
          {
            "customer": []
          }
        ],
        "description": "currentPassword is required exactly when the account already has a password. Saving a password ends the account's other sessions.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "newPassword"
                ],
                "properties": {
                  "newPassword": {
                    "type": "string",
                    "minLength": 15,
                    "maxLength": 256
                  },
                  "currentPassword": {
                    "type": "string",
                    "maxLength": 256
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "The password was saved"
          },
          "4XX": {
            "description": "No session, or the current password was not accepted. Read the returned code, cause and fix."
          }
        }
      }
    },
    "/app/api/access-code": {
      "post": {
        "operationId": "replaceAccessCode",
        "summary": "Replace the account's access code",
        "security": [
          {
            "customer": []
          }
        ],
        "description": "An account with a password confirms with it. An account without one confirms with the access code it is replacing. The old code stops working, the account's other sessions end and the new one is returned once.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "required": [
                      "confirm",
                      "password"
                    ],
                    "properties": {
                      "confirm": {
                        "const": true
                      },
                      "password": {
                        "type": "string",
                        "maxLength": 256
                      }
                    },
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "required": [
                      "confirm",
                      "code"
                    ],
                    "properties": {
                      "confirm": {
                        "const": true
                      },
                      "code": {
                        "type": "string",
                        "pattern": "^cr_[A-Za-z0-9_-]{43}$"
                      }
                    },
                    "additionalProperties": false
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The new access code",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "accessCode"
                  ],
                  "properties": {
                    "accessCode": {
                      "type": "string",
                      "pattern": "^cr_[A-Za-z0-9_-]{43}$"
                    }
                  }
                }
              }
            }
          },
          "4XX": {
            "description": "No session, or the confirmation was not accepted. Read the returned code, cause and fix."
          }
        }
      }
    },
    "/app/api/dashboard": {
      "get": {
        "summary": "Read your account and network totals",
        "security": [
          {
            "customer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Authenticated response"
          },
          "401": {
            "description": "Sign in to this workspace"
          }
        },
        "description": "The account object carries id, email (or null), pendingEmail (or null) and hasPassword."
      }
    },
    "/app/api/usage/receipts": {
      "get": {
        "summary": "Read your usage receipts",
        "security": [
          {
            "customer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Authenticated response"
          },
          "401": {
            "description": "Sign in to this workspace"
          }
        }
      }
    },
    "/app/api/devices": {
      "get": {
        "summary": "Read your enrolled devices and the traffic they carried",
        "description": "Your enrolled devices and committed edge usage from all buyers on those devices. Counters are exact decimal strings. Follow nextCursor in a new read. Earlier releases omit pageTotals and scope. Earnings stay unpriced until monetary settlement is available.",
        "security": [
          {
            "customer": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 12
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Device statement, earnings status and page cursors",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SupplierStatement"
                }
              }
            }
          },
          "401": {
            "description": "Sign in to the supplier account"
          },
          "400": {
            "description": "Invalid cursor, limits or unknown input. Read the returned code, cause and fix."
          }
        },
        "operationId": "readSupplierDevices"
      }
    },
    "/app/api/assistant": {
      "post": {
        "operationId": "askWorkspace",
        "summary": "Ask a signed-in account question",
        "description": "Read assistant.intents from the customer dashboard to discover commands available on this release. A release advertising supplier accepts /supplier for the first 12 devices. Send the workspace Origin with the authenticated POST.",
        "security": [
          {
            "customer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 512
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Server-sent status, tool, card and done events, or a structured error event.",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "A signed-in customer session is required."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "customer": {
        "type": "apiKey",
        "in": "cookie",
        "name": "coronium_client_session",
        "description": "Set by account creation and by sign-in. The local preview adapter renames it to coronium_workspace_customer."
      }
    },
    "schemas": {
      "ExactCount": {
        "type": "string",
        "pattern": "^(0|[1-9][0-9]*)$",
        "description": "Exact nonnegative integer in decimal."
      },
      "SupplierPageTotals": {
        "type": "object",
        "required": [
          "devices",
          "online",
          "requests",
          "bytesUp",
          "bytesDown"
        ],
        "properties": {
          "devices": {
            "$ref": "#/components/schemas/ExactCount"
          },
          "online": {
            "$ref": "#/components/schemas/ExactCount"
          },
          "requests": {
            "$ref": "#/components/schemas/ExactCount"
          },
          "bytesUp": {
            "$ref": "#/components/schemas/ExactCount"
          },
          "bytesDown": {
            "$ref": "#/components/schemas/ExactCount"
          }
        }
      },
      "SupplierDevice": {
        "type": "object",
        "required": [
          "deviceId",
          "country",
          "network",
          "status",
          "visibility",
          "sharingPaused",
          "sharingRevision",
          "requests",
          "bytesUp",
          "bytesDown"
        ],
        "properties": {
          "deviceId": {
            "type": "string",
            "format": "uuid"
          },
          "country": {
            "type": "string",
            "pattern": "^[a-z]{2}$"
          },
          "network": {
            "enum": [
              "mobile",
              "residential"
            ]
          },
          "status": {
            "enum": [
              "online",
              "offline",
              "paused",
              "withdrawn"
            ]
          },
          "visibility": {
            "enum": [
              "owner-only",
              "shared"
            ]
          },
          "sharingPaused": {
            "type": "boolean"
          },
          "sharingRevision": {
            "$ref": "#/components/schemas/ExactCount"
          },
          "requests": {
            "$ref": "#/components/schemas/ExactCount"
          },
          "bytesUp": {
            "$ref": "#/components/schemas/ExactCount"
          },
          "bytesDown": {
            "$ref": "#/components/schemas/ExactCount"
          }
        }
      },
      "SupplierStatement": {
        "type": "object",
        "required": [
          "devices",
          "previousCursor",
          "nextCursor",
          "earnings"
        ],
        "properties": {
          "scope": {
            "const": "supplier_device_page"
          },
          "devices": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/SupplierDevice"
            }
          },
          "pageTotals": {
            "$ref": "#/components/schemas/SupplierPageTotals"
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "previousCursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "earnings": {
            "type": "object",
            "required": [
              "status",
              "usdMicros"
            ],
            "properties": {
              "status": {
                "const": "unpriced"
              },
              "usdMicros": {
                "type": "null"
              }
            }
          }
        }
      }
    }
  }
}
