{
  "openapi": "3.1.0",
  "info": {
    "title": "PixelVault API",
    "version": "1.0.0",
    "description": "Agent-first image hosting API. Upload images via API, get instant CDN URLs. Free tier: 200 MB storage, 500 uploads/month, 1 GB bandwidth/month.",
    "contact": { "email": "support@pixelvault.dev" }
  },
  "servers": [
    { "url": "https://api.pixelvault.dev", "description": "Production" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key with prefix pv_live_ or pv_test_. Example: Bearer pv_live_xxxxxxxx"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" }
            },
            "required": ["code", "message"]
          }
        }
      },
      "Image": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "img_a1b2c3d4e5f6" },
          "url": { "type": "string", "format": "uri", "example": "https://img.pixelvault.dev/proj_xyz789/a1b2c3d4e5f6.jpg" },
          "mime_type": { "type": "string", "example": "image/jpeg" },
          "size": { "type": "integer", "example": 245782 },
          "width": { "type": ["integer", "null"] },
          "height": { "type": ["integer", "null"] },
          "filename": { "type": "string", "example": "photo.jpg" },
          "folder": { "type": ["string", "null"] },
          "created_at": { "type": "string", "format": "date-time" }
        }
      }
    }
  },
  "paths": {
    "/v1/auth/register": {
      "post": {
        "operationId": "register_account",
        "tags": ["Authentication"],
        "summary": "Create account and get API key",
        "description": "Creates an account with a default project and returns a live API key instantly. No browser or signup form needed.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": { "type": "string", "format": "email", "example": "dev@example.com" },
                  "password": { "type": "string", "minLength": 8, "example": "your-secure-password" }
                },
                "required": ["email", "password"]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Account created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "account_id": { "type": "string", "example": "acct_abc123" },
                        "email": { "type": "string", "example": "dev@example.com" },
                        "plan": { "type": "string", "example": "free" },
                        "default_project": {
                          "type": "object",
                          "properties": {
                            "id": { "type": "string", "example": "proj_xyz789" },
                            "name": { "type": "string", "example": "Default" },
                            "api_keys": {
                              "type": "object",
                              "properties": {
                                "live": { "type": "string", "example": "pv_live_xxxxxxxxxxxxxxxx" }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "description": "Validation error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "409": { "description": "Email already registered", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/v1/images": {
      "post": {
        "operationId": "upload_image",
        "tags": ["Images"],
        "summary": "Upload an image",
        "description": "Upload an image file and receive a public CDN URL. Supports JPEG, PNG, GIF, WebP, AVIF, and SVG.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": { "type": "string", "format": "binary", "description": "Image file to upload" },
                  "folder": { "type": "string", "description": "Optional folder name" }
                },
                "required": ["file"]
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Image uploaded", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Image" } } } } } },
          "400": { "description": "Missing or invalid file", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "description": "Invalid or missing API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Upload or storage limit reached", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "get": {
        "operationId": "list_images",
        "tags": ["Images"],
        "summary": "List images",
        "description": "Get a paginated list of images in the project.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "page", "in": "query", "schema": { "type": "integer", "minimum": 1, "default": 1 } },
          { "name": "per_page", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 } }
        ],
        "responses": {
          "200": {
            "description": "List of images",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/Image" } },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "total": { "type": "integer" },
                        "page": { "type": "integer" },
                        "per_page": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "description": "Invalid or missing API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/v1/images/{id}": {
      "get": {
        "operationId": "get_image",
        "tags": ["Images"],
        "summary": "Get image details",
        "description": "Retrieve metadata and CDN URL for a specific image.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "example": "img_a1b2c3d4e5f6" } }
        ],
        "responses": {
          "200": { "description": "Image details", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Image" } } } } } },
          "401": { "description": "Invalid or missing API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "Image not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "delete": {
        "operationId": "delete_image",
        "tags": ["Images"],
        "summary": "Delete image",
        "description": "Permanently delete an image from storage and CDN.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "example": "img_a1b2c3d4e5f6" } }
        ],
        "responses": {
          "200": { "description": "Image deleted", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean", "example": true } } } } } },
          "401": { "description": "Invalid or missing API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "Image not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "health_check",
        "tags": ["Health"],
        "summary": "Health check",
        "description": "Returns service health status.",
        "responses": {
          "200": { "description": "Service is healthy", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string", "example": "ok" } } } } } }
        }
      }
    }
  }
}
