{
  "openapi": "3.1.0",
  "info": {
    "title": "Nyxory Agent API",
    "version": "0.1.0",
    "description": "Create-is-deploy API for agents. Anon key is minted on unauthenticated create."
  },
  "servers": [
    {
      "url": "https://api.nyxory.live"
    }
  ],
  "paths": {
    "/v1/apps": {
      "post": {
        "summary": "Create and deploy app from VCS",
        "description": "Unauthenticated calls mint an anon_key in the response. Bearer pro_key calls create directly on Pro.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "vcs_url"
                ],
                "properties": {
                  "vcs_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "ref": {
                    "type": "string",
                    "default": "main"
                  },
                  "env": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Create successful",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppCreateResponse"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/v1/apps/{id}": {
      "get": {
        "summary": "Get app state",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current app state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppStatusResponse"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      },
      "delete": {
        "summary": "Delete app",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Delete response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deleted": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "deleted"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/v1/apps/{id}/redeploy": {
      "post": {
        "summary": "Redeploy app from VCS",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ref": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Redeploy accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deployment_id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "deployment_id",
                    "status"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/v1/apps/{id}/claim": {
      "post": {
        "summary": "Claim anon app to Pro account",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pro_key": {
                    "type": "string"
                  },
                  "tier": {
                    "type": "string",
                    "enum": [
                      "pro"
                    ]
                  },
                  "budget": {
                    "type": "object",
                    "properties": {
                      "currency": {
                        "type": "string",
                        "example": "USD"
                      },
                      "monthly": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Claim successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "app_id": {
                      "type": "string"
                    },
                    "tier": {
                      "type": "string"
                    },
                    "claimed": {
                      "type": "boolean"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  },
                  "required": [
                    "app_id",
                    "tier",
                    "claimed",
                    "url"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "AppCreateResponse": {
        "type": "object",
        "properties": {
          "app_id": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "anon_key": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "app_id",
          "url",
          "status"
        ]
      },
      "AppStatusResponse": {
        "type": "object",
        "properties": {
          "app_id": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "status": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "tier": {
            "type": "string"
          }
        },
        "required": [
          "app_id",
          "url",
          "status"
        ]
      },
      "ErrorEnvelope": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              }
            },
            "required": [
              "code",
              "message",
              "retryable"
            ]
          }
        },
        "required": [
          "error"
        ]
      }
    },
    "responses": {
      "ErrorResponse": {
        "description": "Error response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      }
    }
  }
}