{
  "openapi": "3.1.0",
  "info": {
    "title": "ONYX Bot API",
    "version": "1.0.0",
    "description": "Owner-approved device pairing, server-manager channel grants, command polling and text messages. Self-hosted workers. No Discord API compatibility, user OAuth, moderation, voice, arbitrary history access or code hosting. 120 authenticated requests per minute per bot. Revoke access in Settings → Developer."
  },
  "servers": [
    {
      "url": "https://kqalpkxhrsuzdbtyeorb.supabase.co/functions/v1/bot-api"
    }
  ],
  "paths": {
    "/pair/start": {
      "post": {
        "operationId": "startPairing",
        "description": "Run only in your own bot process. The random device code must remain in that process. One start per bot per 30 seconds.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "bot_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "device_code": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "bot_id",
                  "device_code"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pairing"
                }
              }
            }
          },
          "400": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "403": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "429": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          }
        }
      }
    },
    "/pair/poll": {
      "post": {
        "operationId": "pollPairing",
        "description": "Poll every 3 seconds for at most 300 seconds. After approval the token is returned once, only here. Store it only in your bot process; it expires in 30 days. A new pairing revokes the old token.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "device_code": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "device_code"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Approved",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Approved"
                }
              }
            }
          },
          "202": {
            "description": "Awaiting owner approval",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "const": "pending"
                    }
                  },
                  "required": [
                    "status"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "403": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          }
        }
      }
    },
    "/me": {
      "get": {
        "operationId": "getBot",
        "description": "Read your bot identity and current channel-scoped installations.",
        "security": [
          {
            "botToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "installs": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "server_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "channel_ids": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "format": "uuid"
                            }
                          }
                        },
                        "required": [
                          "server_id",
                          "channel_ids"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "installs"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "403": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "429": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          }
        }
      }
    },
    "/commands": {
      "post": {
        "operationId": "registerCommands",
        "description": "Replace the bot command list. At most 20 unique commands. No chat-history subscription.",
        "security": [
          {
            "botToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "commands": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "pattern": "^[a-z0-9_-]{1,32}$"
                        },
                        "description": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        }
                      },
                      "required": [
                        "name",
                        "description"
                      ],
                      "additionalProperties": false
                    }
                  }
                },
                "required": [
                  "commands"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": true
                    }
                  },
                  "required": [
                    "ok"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "403": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "429": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          }
        }
      }
    },
    "/events": {
      "get": {
        "operationId": "pollCommands",
        "description": "Returns at most 50 invoked commands after the cursor, in order. Retained 7 days. IDs are strings: keep full bigint precision. Advance the cursor after processing; use stable message nonces to avoid duplicates after retries.",
        "security": [
          {
            "botToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Event"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "403": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "429": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{1,18}$",
              "default": "0"
            }
          }
        ]
      }
    },
    "/messages": {
      "post": {
        "operationId": "sendMessage",
        "description": "Send text only in an installed channel. At most 30 messages per minute per bot; channel slowmode applies. No @everyone/@here. Retry the exact same content/channel/nonce to get the same message. Removing installation or banning the owner blocks access.",
        "security": [
          {
            "botToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "channel_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "nonce": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "content": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000
                  }
                },
                "required": [
                  "channel_id",
                  "nonce",
                  "content"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "replayed": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "403": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "429": {
            "description": "Error. 429 includes Retry-After: 60. Retry polling at least 3 seconds apart.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ],
                  "additionalProperties": false
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "botToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "onyx_bot_<64 lowercase hex>",
        "description": "Delivered to the bot process after owner approval. Never place a token in a website, frontend build, logs or repository."
      }
    },
    "schemas": {
      "Pairing": {
        "type": "object",
        "properties": {
          "user_code": {
            "type": "string"
          },
          "verification_uri": {
            "type": "string",
            "format": "uri"
          },
          "expires_in": {
            "const": 300
          },
          "interval": {
            "const": 3
          }
        },
        "required": [
          "user_code",
          "verification_uri",
          "expires_in",
          "interval"
        ],
        "additionalProperties": false
      },
      "Approved": {
        "type": "object",
        "properties": {
          "status": {
            "const": "approved"
          },
          "bot_id": {
            "type": "string",
            "format": "uuid"
          },
          "token": {
            "type": "string"
          },
          "expires_in": {
            "const": 2592000
          }
        },
        "required": [
          "status",
          "bot_id",
          "token",
          "expires_in"
        ],
        "additionalProperties": false
      },
      "Event": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-9]+$"
          },
          "command": {
            "type": "string"
          },
          "args": {
            "type": "string"
          },
          "channel_id": {
            "type": "string",
            "format": "uuid"
          },
          "user_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "command",
          "args",
          "channel_id",
          "user_id",
          "created_at"
        ],
        "additionalProperties": false
      }
    }
  }
}
