{
  "openapi": "3.0.3",
  "info": {
    "title": "HOPX Public API",
    "description": "Lifecycle management API for HOPX sandboxes (VMs)",
    "version": "2025-10-21",
    "contact": {
      "name": "HOPX Support",
      "email": "support@hopx.dev",
      "url": "https://hopx.dev"
    }
  },
  "servers": [
    {
      "url": "https://api.hopx.dev",
      "description": "Production"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "getHealth",
        "tags": [
          "System"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "API is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "healthy"
                    },
                    "service": {
                      "type": "string",
                      "example": "HOPX Public API"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/sandboxes": {
      "get": {
        "summary": "List sandboxes",
        "operationId": "listSandboxes",
        "tags": [
          "Sandboxes"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Number of results to return (max 100)",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by status",
            "schema": {
              "type": "string",
              "enum": [
                "running",
                "stopped",
                "paused",
                "creating"
              ]
            }
          },
          {
            "name": "region",
            "in": "query",
            "description": "Filter by region",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of sandboxes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "post": {
        "summary": "Create sandbox",
        "operationId": "createSandbox",
        "tags": [
          "Sandboxes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSandboxRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sandbox created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Sandbox"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/v1/sandboxes/{id}": {
      "get": {
        "summary": "Get sandbox",
        "operationId": "getSandbox",
        "tags": [
          "Sandboxes"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SandboxId"
          }
        ],
        "responses": {
          "200": {
            "description": "Sandbox details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Sandbox"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "delete": {
        "summary": "Delete sandbox",
        "operationId": "deleteSandbox",
        "tags": [
          "Sandboxes"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SandboxId"
          }
        ],
        "responses": {
          "200": {
            "description": "Sandbox deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "deleted"
                    },
                    "id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/sandboxes/{id}/start": {
      "post": {
        "summary": "Start sandbox",
        "operationId": "startSandbox",
        "tags": [
          "Sandboxes"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SandboxId"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/ActionSuccess"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/sandboxes/{id}/stop": {
      "post": {
        "summary": "Stop sandbox",
        "operationId": "stopSandbox",
        "tags": [
          "Sandboxes"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SandboxId"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/ActionSuccess"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/sandboxes/{id}/pause": {
      "post": {
        "summary": "Pause sandbox",
        "operationId": "pauseSandbox",
        "tags": [
          "Sandboxes"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SandboxId"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/ActionSuccess"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/sandboxes/{id}/resume": {
      "post": {
        "summary": "Resume sandbox",
        "operationId": "resumeSandbox",
        "tags": [
          "Sandboxes"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SandboxId"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/ActionSuccess"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/templates": {
      "get": {
        "summary": "List templates",
        "operationId": "listTemplates",
        "tags": [
          "Templates"
        ],
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "development",
                "infrastructure",
                "operating-system"
              ]
            }
          },
          {
            "name": "language",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of templates",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateList"
                }
              }
            }
          }
        }
      }
    },
    "/v1/templates/{name}": {
      "get": {
        "summary": "Get template",
        "operationId": "getTemplate",
        "tags": [
          "Templates"
        ],
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Template details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Template"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "SandboxId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Sandbox ID",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "Sandbox": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "1761048129dsaqav4n"
          },
          "object": {
            "type": "string",
            "example": "sandbox"
          },
          "live_mode": {
            "type": "boolean",
            "example": true
          },
          "organization_id": {
            "type": "string"
          },
          "node_id": {
            "type": "string"
          },
          "region": {
            "type": "string",
            "example": "eu-west"
          },
          "template_name": {
            "type": "string",
            "example": "code-interpreter"
          },
          "template_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "creating",
              "running",
              "stopped",
              "paused"
            ],
            "example": "running"
          },
          "direct_url": {
            "type": "string",
            "format": "uri"
          },
          "public_host": {
            "type": "string",
            "format": "uri"
          },
          "resources": {
            "$ref": "#/components/schemas/Resources"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "request_id": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "status",
          "direct_url"
        ]
      },
      "SandboxList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "example": "list"
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Sandbox"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "url": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "CreateSandboxRequest": {
        "type": "object",
        "required": [
          "template_name",
          "vcpu",
          "memory_mb"
        ],
        "properties": {
          "template_name": {
            "type": "string",
            "description": "Human-readable template name",
            "example": "code-interpreter"
          },
          "template_id": {
            "type": "string"
          },
          "region": {
            "type": "string"
          },
          "vcpu": {
            "type": "integer",
            "minimum": 1,
            "maximum": 64,
            "example": 2
          },
          "memory_mb": {
            "type": "integer",
            "minimum": 128,
            "example": 2048
          },
          "disk_gb": {
            "type": "integer",
            "minimum": 5,
            "maximum": 500
          }
        }
      },
      "Resources": {
        "type": "object",
        "properties": {
          "vcpu": {
            "type": "integer"
          },
          "memory_mb": {
            "type": "integer"
          },
          "disk_mb": {
            "type": "integer"
          }
        }
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "example": "template"
          },
          "name": {
            "type": "string",
            "example": "code-interpreter"
          },
          "display_name": {
            "type": "string",
            "example": "Code Interpreter"
          },
          "description": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "language": {
            "type": "string"
          },
          "icon": {
            "type": "string"
          },
          "default_resources": {
            "$ref": "#/components/schemas/TemplateResources"
          },
          "min_resources": {
            "$ref": "#/components/schemas/TemplateResources"
          },
          "max_resources": {
            "$ref": "#/components/schemas/TemplateResources"
          },
          "features": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "popularity_score": {
            "type": "integer"
          },
          "docs_url": {
            "type": "string",
            "format": "uri"
          },
          "is_active": {
            "type": "boolean"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "TemplateList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "example": "list"
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Template"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "url": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "TemplateResources": {
        "type": "object",
        "properties": {
          "vcpu": {
            "type": "integer"
          },
          "memory_mb": {
            "type": "integer"
          },
          "disk_gb": {
            "type": "integer"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "example": "rate_limit_error"
              },
              "code": {
                "type": "string",
                "example": "rate_limit_exceeded"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object"
              },
              "docs_url": {
                "type": "string",
                "format": "uri"
              },
              "request_id": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Unauthorized",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "BadRequest": {
        "description": "Bad request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimitExceeded": {
        "description": "Rate limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ServerError": {
        "description": "Server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ActionSuccess": {
        "description": "Action completed successfully",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string"
                },
                "id": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
