{
  "openapi": "3.1.0",
  "info": {
    "title": "GhostLink Zero-Knowledge Ephemeral Meeting & Room API",
    "description": "Production REST API and Model Context Protocol (MCP) backend for GhostLink. Enables AI agents, healthcare applications, and legal platforms to programmatically provision disposable, zero-telemetry, peer-to-peer encrypted video rooms and customizable iframe embeds.",
    "version": "1.0.0",
    "contact": {
      "name": "GhostLink Engineering",
      "url": "https://ghostlink.chat/developers",
      "email": "security@ghostlink.chat"
    },
    "license": {
      "name": "Commercial License",
      "url": "https://ghostlink.chat/terms"
    }
  },
  "servers": [
    {
      "url": "https://ghostlink.chat/api/v1",
      "description": "Production Edge Mesh"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/rooms": {
      "post": {
        "summary": "Create an ephemeral secure room",
        "description": "Provisions a cryptographically isolated WebRTC room backed by Cloudflare Durable Objects. Returns guest URLs, host tokens, embed codes, and enforces strict duration and occupant boundaries.",
        "operationId": "createRoom",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateRoomRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Room successfully created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateRoomResponse"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "429": {
            "description": "Rate limit exceeded (e.g. sandbox IP limit or monthly quota exhausted)"
          }
        }
      }
    },
    "/rooms/{roomId}": {
      "get": {
        "summary": "Get room status & occupant metrics",
        "description": "Queries the active Durable Object to check whether the room is alive, current occupant count, and remaining lifespan.",
        "operationId": "getRoomStatus",
        "parameters": [
          {
            "name": "roomId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique cryptographically random room identifier"
          }
        ],
        "responses": {
          "200": {
            "description": "Current room status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RoomStatusResponse"
                }
              }
            }
          },
          "404": {
            "description": "Room not found or already destroyed"
          }
        }
      },
      "delete": {
        "summary": "Terminate room immediately",
        "description": "Instantly closes the room, severs all active WebRTC peer connections, triggers room.ended webhook, and wipes all in-memory signaling state.",
        "operationId": "terminateRoom",
        "parameters": [
          {
            "name": "roomId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Room successfully terminated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "Room terminated" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/usage": {
      "get": {
        "summary": "Get API key usage and monthly quotas",
        "description": "Returns current billing cycle room hours consumed, allowed monthly quota, plan tier, and subscription status.",
        "operationId": "getUsage",
        "responses": {
          "200": {
            "description": "Usage metrics",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageResponse"
                }
              }
            }
          }
        }
      }
    },
    "/keys/domains": {
      "get": {
        "summary": "List whitelisted embed domains",
        "operationId": "listAllowedDomains",
        "responses": {
          "200": {
            "description": "List of authorized domains allowed to frame /embed/*",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "allowed_domains": {
                      "type": "array",
                      "items": { "type": "string" },
                      "example": ["app.healthcare-portal.com", "telehealth.org"]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Whitelist a new embed domain",
        "operationId": "addAllowedDomain",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["domain"],
                "properties": {
                  "domain": {
                    "type": "string",
                    "example": "app.healthcare-portal.com"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Domain successfully added"
          }
        }
      },
      "delete": {
        "summary": "Remove a whitelisted domain",
        "operationId": "removeAllowedDomain",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["domain"],
                "properties": {
                  "domain": {
                    "type": "string",
                    "example": "app.healthcare-portal.com"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Domain removed"
          }
        }
      }
    },
    "/webhooks/test": {
      "post": {
        "summary": "Dispatch simulated webhook with HMAC-SHA256 signature",
        "operationId": "testWebhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": { "type": "string", "format": "uri", "example": "https://api.mycompany.com/webhooks/ghostlink" },
                  "secret": { "type": "string", "example": "whsec_test_secret_123" },
                  "event": { "type": "string", "enum": ["room.started", "room.ended"], "default": "room.started" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook simulation response with round-trip latency and target status code"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Supply your GhostLink B2B API Key (e.g. gl_live_... or gl_test_sandbox) in the Authorization header: `Bearer <YOUR_KEY>`"
      }
    },
    "schemas": {
      "CreateRoomRequest": {
        "type": "object",
        "properties": {
          "duration_minutes": {
            "type": "integer",
            "minimum": 5,
            "maximum": 240,
            "default": 60,
            "description": "Room lifespan in minutes (max 15 for sandbox; up to 240 for live plans)"
          },
          "max_participants": {
            "type": "integer",
            "minimum": 2,
            "maximum": 5,
            "default": 5,
            "description": "Max simultaneous peer connections (max 2 for sandbox)"
          },
          "webhook_url": {
            "type": "string",
            "format": "uri",
            "description": "Destination endpoint for signed room lifecycle webhooks"
          },
          "default_video": {
            "type": "string",
            "enum": ["on", "off"],
            "default": "on"
          },
          "default_audio": {
            "type": "string",
            "enum": ["on", "off"],
            "default": "on"
          },
          "hide_chat": {
            "type": "boolean",
            "default": false
          },
          "hide_notepad": {
            "type": "boolean",
            "default": false
          },
          "lobby_msg": {
            "type": "string",
            "maxLength": 160,
            "example": "Your session will begin shortly. Please wait for the host."
          },
          "redirect_on_leave": {
            "type": "string",
            "format": "uri",
            "example": "https://app.client.com/feedback"
          }
        }
      },
      "CreateRoomResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "room_id": { "type": "string", "example": "a4f89b1c-92de-4e78-953b-e0182613d5b0" },
          "room_url": { "type": "string", "example": "https://ghostlink.chat/room/a4f89b1c-92de-4e78-953b-e0182613d5b0" },
          "embed_url": { "type": "string", "example": "https://ghostlink.chat/embed/a4f89b1c-92de-4e78-953b-e0182613d5b0?token=..." },
          "iframe_code": { "type": "string" },
          "duration_minutes": { "type": "integer", "example": 60 },
          "max_participants": { "type": "integer", "example": 5 },
          "expires_at": { "type": "string", "format": "date-time" },
          "is_sandbox": { "type": "boolean", "example": false }
        }
      },
      "RoomStatusResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "room_id": { "type": "string" },
          "active": { "type": "boolean", "example": true },
          "occupants": { "type": "integer", "example": 2 },
          "max_occupants": { "type": "integer", "example": 5 },
          "locked": { "type": "boolean", "example": false },
          "remaining_minutes": { "type": "integer", "example": 45 },
          "expires_at": { "type": "string", "format": "date-time" }
        }
      },
      "UsageResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "plan": { "type": "string", "example": "scale" },
          "monthly_hours_used": { "type": "number", "example": 42.5 },
          "monthly_hours_limit": { "type": "number", "example": 500 },
          "usage_percent": { "type": "number", "example": 8.5 },
          "reset_date": { "type": "string", "format": "date-time" }
        }
      }
    }
  }
}
