{
  "openapi": "3.1.0",
  "info": {
    "title": "PloyHQ API",
    "version": "0.1.0",
    "description": "App hosting for AI agents. Prepaid credit, billed per second. Every error has error.code, error.message and error.fix."
  },
  "servers": [
    {
      "url": "https://api.ployhq.dev"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "fix": {
                "type": "string"
              }
            }
          }
        }
      },
      "App": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "provisioning",
              "running",
              "stopped",
              "failed",
              "deleted"
            ]
          },
          "url": {
            "type": "string"
          },
          "plan": {
            "type": "string"
          },
          "tier": {
            "type": "string"
          },
          "cpu": {
            "type": "string"
          },
          "avx2": {
            "type": "boolean"
          },
          "ram_mb": {
            "type": "integer"
          },
          "vcpu_shared": {
            "type": "integer"
          },
          "usd_per_hour": {
            "type": "number"
          },
          "source": {
            "type": "object"
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "NewApp": {
        "type": "object",
        "required": [
          "name",
          "source"
        ],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{1,30}[a-z0-9]$"
          },
          "plan": {
            "type": "string",
            "enum": [
              "nano",
              "small",
              "medium",
              "large",
              "xl"
            ],
            "default": "small"
          },
          "tier": {
            "type": "string",
            "enum": [
              "standard",
              "classic"
            ],
            "default": "standard",
            "description": "standard = Xeon E5 v4 with AVX2. classic = Xeon E5 v2, cheaper, no AVX2."
          },
          "source": {
            "type": "object",
            "properties": {
              "git": {
                "type": "string"
              },
              "image": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/v1/plans": {
      "get": {
        "summary": "List plans and prices",
        "security": [],
        "responses": {
          "200": {
            "description": "Plan catalog"
          }
        }
      }
    },
    "/v1/accounts": {
      "post": {
        "summary": "Create an account and API key",
        "security": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "account_id and api_key (shown once)"
          },
          "429": {
            "description": "Too many signups",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/account": {
      "get": {
        "summary": "Balance, spend per hour, runway, and new-account limits",
        "responses": {
          "200": {
            "description": "Account"
          }
        }
      }
    },
    "/v1/credits": {
      "post": {
        "summary": "Add prepaid credit (returns a checkout link)",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount_usd"
                ],
                "properties": {
                  "amount_usd": {
                    "type": "number",
                    "minimum": 20
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout link or credited balance"
          }
        }
      }
    },
    "/v1/apps": {
      "get": {
        "summary": "List apps",
        "responses": {
          "200": {
            "description": "Apps"
          }
        }
      },
      "post": {
        "summary": "Deploy an app",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewApp"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/App"
                }
              }
            }
          },
          "402": {
            "description": "Not enough credit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Name in use",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "New-account limit (error.code new_account_limit); error.fix says when it lifts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "Bad request, including name_not_allowed for brand or login words",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/apps/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "summary": "Get one app",
        "responses": {
          "200": {
            "description": "App",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/App"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete an app and stop billing",
        "responses": {
          "200": {
            "description": "Deleted"
          }
        }
      }
    },
    "/v1/apps/{id}/logs": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "summary": "Recent log lines",
        "responses": {
          "200": {
            "description": "Log lines"
          }
        }
      }
    }
  }
}
