{
  "openapi": "3.1.0",
  "info": {
    "title": "AIImageEdits API",
    "version": "1.0.0",
    "description": "Native auto-quality edits with local original-size export. API keys: 6 creations/minute and 120 control requests/minute. Prepared PNG ≤32 MiB, decoded generated PNG ≤32 MiB, source ≤50 MP and 16384 pixels/edge. Native generation is capped at 7,000,000 pixels; source files accepted by the website remain ≤25 MiB. Unqualified native tiers fail closed."
  },
  "servers": [
    {
      "url": "https://aiimageedits.com"
    }
  ],
  "paths": {
    "/api/v1/edits/quote": {
      "post": {
        "summary": "Quote an edit",
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "width",
                  "height",
                  "format"
                ],
                "properties": {
                  "width": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 16384
                  },
                  "height": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 16384
                  },
                  "format": {
                    "enum": [
                      "image/png",
                      "image/jpeg",
                      "image/webp"
                    ]
                  },
                  "background": {
                    "const": "transparent",
                    "description": "Optional instruction to preserve transparent output. The website sets this when the original has transparent pixels."
                  },
                  "nativeTier": {
                    "type": "integer",
                    "enum": [
                      1,
                      2,
                      4,
                      7
                    ],
                    "description": "Optional processing tier, independent of original download dimensions. Select from /api/config nativeTiers and send the same value for quote and creation. Without it, native resolution follows the source size; an unavailable tier returns 503."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "exportPlan": {
                      "$ref": "#/components/schemas/ExportPlan"
                    },
                    "chargeUnits": {
                      "type": "integer"
                    },
                    "chargeCredits": {
                      "type": "number"
                    },
                    "free": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/edits": {
      "post": {
        "summary": "Reserve credits and create an edit",
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "type": "object",
                    "required": [
                      "width",
                      "height",
                      "format"
                    ],
                    "properties": {
                      "width": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 16384
                      },
                      "height": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 16384
                      },
                      "format": {
                        "enum": [
                          "image/png",
                          "image/jpeg",
                          "image/webp"
                        ]
                      },
                      "background": {
                        "const": "transparent",
                        "description": "Optional instruction to preserve transparent output. The website sets this when the original has transparent pixels."
                      },
                      "nativeTier": {
                        "type": "integer",
                        "enum": [
                          1,
                          2,
                          4,
                          7
                        ],
                        "description": "Optional processing tier, independent of original download dimensions. Select from /api/config nativeTiers and send the same value for quote and creation. Without it, native resolution follows the source size; an unavailable tier returns 503."
                      }
                    }
                  },
                  {
                    "type": "object",
                    "required": [
                      "prompt",
                      "uploadSha256",
                      "uploadBytes",
                      "expectedChargeUnits",
                      "idempotencyKey"
                    ],
                    "properties": {
                      "prompt": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 4000
                      },
                      "uploadSha256": {
                        "type": "string",
                        "pattern": "^[a-f0-9]{64}$"
                      },
                      "uploadBytes": {
                        "type": "integer",
                        "minimum": 45,
                        "maximum": 33554432
                      },
                      "expectedChargeUnits": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "idempotencyKey": {
                        "type": "string",
                        "minLength": 16,
                        "maxLength": 80
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "hasThumbnail": {
                      "type": "boolean"
                    },
                    "uploaded": {
                      "type": "boolean",
                      "description": "Input upload was accepted; a resumed awaiting_upload job can be submitted without uploading again."
                    },
                    "state": {
                      "enum": [
                        "awaiting_upload",
                        "queued",
                        "processing",
                        "ready",
                        "failed",
                        "canceled",
                        "expired"
                      ]
                    },
                    "exportPlan": {
                      "$ref": "#/components/schemas/ExportPlan"
                    },
                    "chargeCredits": {
                      "type": "number"
                    },
                    "expiresAt": {
                      "type": "integer",
                      "description": "Unix milliseconds. Pending job deadline; reset to one hour after successful completion."
                    },
                    "createdAt": {
                      "type": "integer"
                    },
                    "pollAfterMs": {
                      "type": "integer",
                      "minimum": 3000,
                      "maximum": 10000,
                      "description": "Suggested delay before the next status request."
                    },
                    "resultUrl": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "failureReason": {
                      "enum": [
                        "moderation",
                        "invalid_image",
                        "provider_error",
                        "unknown"
                      ],
                      "description": "Optional safe category for a failed edit. The existing error code remains authoritative; private provider diagnostics and request IDs are never returned. A new attempt requires an explicit new request after confirmed failure."
                    },
                    "uploadUrl": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "hasThumbnail": {
                      "type": "boolean"
                    },
                    "uploaded": {
                      "type": "boolean",
                      "description": "Input upload was accepted; a resumed awaiting_upload job can be submitted without uploading again."
                    },
                    "state": {
                      "enum": [
                        "awaiting_upload",
                        "queued",
                        "processing",
                        "ready",
                        "failed",
                        "canceled",
                        "expired"
                      ]
                    },
                    "exportPlan": {
                      "$ref": "#/components/schemas/ExportPlan"
                    },
                    "chargeCredits": {
                      "type": "number"
                    },
                    "expiresAt": {
                      "type": "integer",
                      "description": "Unix milliseconds. Pending job deadline; reset to one hour after successful completion."
                    },
                    "createdAt": {
                      "type": "integer"
                    },
                    "pollAfterMs": {
                      "type": "integer",
                      "minimum": 3000,
                      "maximum": 10000,
                      "description": "Suggested delay before the next status request."
                    },
                    "resultUrl": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "failureReason": {
                      "enum": [
                        "moderation",
                        "invalid_image",
                        "provider_error",
                        "unknown"
                      ],
                      "description": "Optional safe category for a failed edit. The existing error code remains authoritative; private provider diagnostics and request IDs are never returned. A new attempt requires an explicit new request after confirmed failure."
                    },
                    "uploadUrl": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "201 on creation, 200 on an identical idempotent retry. Keys are account-scoped and retained for seven days after artifact purge. Do not reuse after retention. Upload within ten minutes; pending deadline one hour. No automatic provider retry."
      }
    },
    "/api/v1/edits/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read an edit",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "hasThumbnail": {
                      "type": "boolean"
                    },
                    "uploaded": {
                      "type": "boolean",
                      "description": "Input upload was accepted; a resumed awaiting_upload job can be submitted without uploading again."
                    },
                    "state": {
                      "enum": [
                        "awaiting_upload",
                        "queued",
                        "processing",
                        "ready",
                        "failed",
                        "canceled",
                        "expired"
                      ]
                    },
                    "exportPlan": {
                      "$ref": "#/components/schemas/ExportPlan"
                    },
                    "chargeCredits": {
                      "type": "number"
                    },
                    "expiresAt": {
                      "type": "integer",
                      "description": "Unix milliseconds. Pending job deadline; reset to one hour after successful completion."
                    },
                    "createdAt": {
                      "type": "integer"
                    },
                    "pollAfterMs": {
                      "type": "integer",
                      "minimum": 3000,
                      "maximum": 10000,
                      "description": "Suggested delay before the next status request."
                    },
                    "resultUrl": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "failureReason": {
                      "enum": [
                        "moderation",
                        "invalid_image",
                        "provider_error",
                        "unknown"
                      ],
                      "description": "Optional safe category for a failed edit. The existing error code remains authoritative; private provider diagnostics and request IDs are never returned. A new attempt requires an explicit new request after confirmed failure."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "summary": "Cancel a queued edit or delete its files",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Processing edits return 409. Repeated deletion preserves failed/canceled states, consumed free allowances, and credit settlement. Successful results become expired."
      }
    },
    "/api/v1/edits/{id}/upload": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "summary": "Upload the prepared PNG",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        }
      }
    },
    "/api/v1/edits/{id}/submit": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "summary": "Queue a prepared edit",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "202": {
            "description": "Accepted. Poll until the edit reaches a terminal state.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "id",
                    "state"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "state": {
                      "enum": [
                        "queued",
                        "processing",
                        "ready"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/edits/{id}/result": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Download the generated PNG",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Generated PNG named image.png with embedded Content Credentials and descriptive metadata removed. Apply exportPlan locally.",
            "content": {
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/client-errors": {
      "post": {
        "summary": "Report an anonymous browser image failure",
        "security": [],
        "description": "Website diagnostic endpoint, not an authenticated editing API. Exact same-origin JSON is required even with Authorization. Maximum body 512 bytes; enum fields only. At most 10 accepted reports/network/hour and 1000 globally per rolling 24 hours. The browser deduplicates failures, sends at most five per page, and never retries. No session is created. Daily counts are eligible for cleanup after 90 days. Reports are untrusted and incomplete, not a measured failure rate.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "v",
                  "stage",
                  "code",
                  "format",
                  "pixels",
                  "browser",
                  "locale"
                ],
                "properties": {
                  "v": {
                    "const": 1
                  },
                  "stage": {
                    "enum": [
                      "prepare",
                      "upload",
                      "download",
                      "export",
                      "storage"
                    ]
                  },
                  "code": {
                    "enum": [
                      "file_too_large",
                      "pixel_limit",
                      "unsupported_format",
                      "unsupported_heif",
                      "hdr_profile",
                      "icc_profile",
                      "codec_unsupported",
                      "invalid_image",
                      "invalid_header",
                      "invalid_structure",
                      "truncated_image",
                      "animated_image",
                      "file_unreadable",
                      "decoder_load",
                      "decode_failed",
                      "browser_limit",
                      "encode_failed",
                      "network_error",
                      "storage_unavailable",
                      "timeout",
                      "unexpected"
                    ]
                  },
                  "format": {
                    "enum": [
                      "jpeg",
                      "png",
                      "webp",
                      "heic",
                      "other"
                    ]
                  },
                  "pixels": {
                    "enum": [
                      "unknown",
                      "small",
                      "large",
                      "over"
                    ],
                    "description": "unknown, up to 16 MP, up to 50 MP, or over 50 MP."
                  },
                  "browser": {
                    "enum": [
                      "chromium",
                      "firefox",
                      "webkit",
                      "other"
                    ]
                  },
                  "locale": {
                    "enum": [
                      "en",
                      "es",
                      "pt",
                      "fr",
                      "de",
                      "zh",
                      "ja",
                      "ko",
                      "hi",
                      "ar",
                      "it",
                      "id",
                      "tr",
                      "ru",
                      "vi",
                      "th",
                      "nl",
                      "pl",
                      "uk",
                      "sv"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Recorded; no content or cookie; Cache-Control: no-store"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/config": {
      "get": {
        "summary": "Stateless public service configuration",
        "security": [],
        "responses": {
          "200": {
            "description": "No session, database, or Durable Object writes. Public production cache: 60 seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "editingEnabled": {
                      "type": "boolean"
                    },
                    "paymentsEnabled": {
                      "type": "boolean"
                    },
                    "emailEnabled": {
                      "type": "boolean"
                    },
                    "mode": {
                      "enum": [
                        "disabled",
                        "mock",
                        "live"
                      ]
                    },
                    "oauthProviders": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "nativeTiers": {
                      "type": "array",
                      "items": {
                        "type": "integer",
                        "enum": [
                          1,
                          2,
                          4,
                          7
                        ]
                      },
                      "description": "Enabled processing tiers in ascending order. Empty when editing is disabled."
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/editor/state": {
      "get": {
        "summary": "Read browser editor configuration, personal allowance, and account balance",
        "security": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "config": {
                      "type": "object",
                      "properties": {
                        "editingEnabled": {
                          "type": "boolean"
                        },
                        "paymentsEnabled": {
                          "type": "boolean"
                        },
                        "emailEnabled": {
                          "type": "boolean"
                        },
                        "mode": {
                          "enum": [
                            "disabled",
                            "mock",
                            "live"
                          ]
                        },
                        "oauthProviders": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "nativeTiers": {
                          "type": "array",
                          "items": {
                            "type": "integer",
                            "enum": [
                              1,
                              2,
                              4,
                              7
                            ]
                          },
                          "description": "Enabled processing tiers in ascending order. Empty when editing is disabled."
                        }
                      }
                    },
                    "allowance": {
                      "type": "object",
                      "required": [
                        "limit",
                        "remaining",
                        "resetsAt",
                        "available",
                        "reason",
                        "capacity"
                      ],
                      "properties": {
                        "limit": {
                          "const": 1
                        },
                        "remaining": {
                          "enum": [
                            0,
                            1,
                            null
                          ],
                          "description": "Personal daily allowance; null means unknown, never assumed zero."
                        },
                        "resetsAt": {
                          "type": "integer",
                          "description": "Next UTC midnight, Unix milliseconds."
                        },
                        "available": {
                          "type": "boolean",
                          "description": "Includes shared capacity and service availability."
                        },
                        "reason": {
                          "enum": [
                            "used",
                            "capacity",
                            "disabled",
                            "unknown",
                            null
                          ]
                        },
                        "capacity": {
                          "enum": [
                            "available",
                            "global_limit",
                            "network_limit",
                            "unknown"
                          ],
                          "description": "Shared availability, independent of whether this visitor has used their daily edit."
                        }
                      }
                    },
                    "averageProcessingSeconds24h": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "Successful upload-to-completion average over the last 24 hours, cached for five minutes. Null when unavailable or explicitly omitted. This is the historical average, in seconds."
                    },
                    "balance": {
                      "type": "object",
                      "properties": {
                        "signedIn": {
                          "type": "boolean"
                        },
                        "balance": {
                          "type": "number"
                        },
                        "available": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "X-Visitor-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{32}$"
            }
          },
          {
            "name": "X-Processing-Average",
            "in": "header",
            "schema": {
              "const": "omit"
            },
            "description": "Skip the timing lookup and return null for the processing average."
          }
        ],
        "description": "Browser endpoint, private/no-store. Makes no session, database or Durable Object writes. A random visitor identifier supports allowance continuity; it never authorizes image or account access. API keys are rejected."
      }
    },
    "/api/account/security": {
      "post": {
        "summary": "Change a username password or replace a recovery code",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "action",
                  "currentPassword"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "password",
                      "recovery-code"
                    ]
                  },
                  "currentPassword": {
                    "type": "string",
                    "minLength": 6,
                    "maxLength": 128,
                    "description": "Current secret. Existing passwords accepted under the previous 12–128 UTF-16-unit rule remain valid."
                  },
                  "newPassword": {
                    "type": "string",
                    "minLength": 7,
                    "maxLength": 128,
                    "description": "Required for action=password."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "recoveryCode": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Browser session only. Requires the current password, rotates the recovery code, atomically revokes sessions and API keys, and expires the current cookie. Save the replacement code immediately. Five attempts/account/15 minutes."
      }
    },
    "/api/account/payments": {
      "get": {
        "summary": "Read older account payments",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payments": {
                      "type": "array",
                      "maxItems": 20,
                      "items": {
                        "type": "object"
                      }
                    },
                    "paymentsCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 256
            }
          }
        ],
        "description": "Use paymentsCursor from /api/account/history or this endpoint. Account-scoped keyset pagination; no Stripe request. API keys are rejected."
      }
    },
    "/api/contact": {
      "post": {
        "summary": "Send private feedback",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 4000
                  },
                  "email": {
                    "type": "string",
                    "maxLength": 254,
                    "description": "Optional reply email."
                  },
                  "purpose": {
                    "enum": [
                      "personal",
                      "social",
                      "business",
                      "client",
                      "research",
                      "other"
                    ]
                  },
                  "satisfaction": {
                    "enum": [
                      "very_satisfied",
                      "satisfied",
                      "neutral",
                      "dissatisfied",
                      "very_dissatisfied",
                      "incomplete",
                      "not_used"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "The website requires purpose and satisfaction; older request bodies may omit them. Three requests/network/hour, 50/site/day. Stored privately for up to 90 days; no automatic external email."
      }
    },
    "/api/billing/status": {
      "get": {
        "summary": "Read account-scoped checkout status",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "enum": [
                        "pending",
                        "paid",
                        "failed",
                        "expired"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "description": "Browser session only; API keys cannot access billing. Does not fetch payment history or contact Stripe."
      }
    },
    "/api/billing/checkout": {
      "post": {
        "summary": "Create or resume a hosted credit checkout",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount",
                  "idempotencyKey"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "minimum": 300,
                    "maximum": 100000,
                    "description": "USD cents. Fixed packs 300/1000/2500 or a custom amount."
                  },
                  "locale": {
                    "enum": [
                      "en",
                      "es",
                      "pt",
                      "fr",
                      "de",
                      "zh",
                      "ja",
                      "ko",
                      "hi",
                      "ar",
                      "it",
                      "id",
                      "tr",
                      "ru",
                      "vi",
                      "th",
                      "nl",
                      "pl",
                      "uk",
                      "sv"
                    ],
                    "default": "en"
                  },
                  "idempotencyKey": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9_-]{16,80}$"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Browser session only. Five requests/account/hour, 20/network/hour. Reuse the key for retries; changing amount or locale conflicts. New unlinked checkouts are retryable for 30 minutes. Catalog, terms and locale are snapshotted; checkout expires after 31 minutes. Fulfillment requires a signed webhook and canonical Stripe state, never the return page. Unpaid terminal idempotency records last 30 days; paid financial records are retained."
      }
    },
    "/api/auth/password": {
      "post": {
        "summary": "Sign in or create a username account",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "username",
                  "password"
                ],
                "properties": {
                  "username": {
                    "type": "string",
                    "description": "Trim outer whitespace, lowercase, then require 3–32 ASCII letters, digits, underscore or hyphen."
                  },
                  "password": {
                    "type": "string",
                    "minLength": 6,
                    "maxLength": 128,
                    "description": "New passwords require 7–128 Unicode code points. No trimming or normalization. Existing legacy passwords remain valid for sign-in."
                  },
                  "createIfMissing": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in; HttpOnly session cookie."
          },
          "201": {
            "description": "Account created; recoveryCode must be saved before signing in."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "createIfMissing returns 201 and a recovery code for a new account without signing in. Save the code, then repeat to sign in. Existing usernames always require the correct password. Username accounts do not receive signup credits. Creating accounts is limited to 5/network/hour and 10/network/day."
      }
    },
    "/api/account/history": {
      "get": {
        "summary": "Read account downloads, keys, and payments",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "edits": {
                      "type": "array",
                      "maxItems": 10,
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "state": {
                            "enum": [
                              "awaiting_upload",
                              "queued",
                              "processing",
                              "ready",
                              "failed",
                              "canceled",
                              "expired"
                            ]
                          },
                          "plan": {
                            "type": "string",
                            "description": "JSON-encoded ExportPlan"
                          },
                          "created_at": {
                            "type": "integer"
                          },
                          "expires_at": {
                            "type": "integer"
                          },
                          "has_thumbnail": {
                            "type": "integer",
                            "enum": [
                              0,
                              1
                            ]
                          }
                        }
                      }
                    },
                    "editsCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "keys": {
                      "type": "array",
                      "maxItems": 5,
                      "items": {
                        "type": "object"
                      }
                    },
                    "payments": {
                      "type": "array",
                      "maxItems": 20,
                      "items": {
                        "type": "object"
                      }
                    },
                    "paymentsCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "ledger": {
                      "type": "array",
                      "maxItems": 0,
                      "description": "Deprecated compatibility field, always empty. Financial records remain stored immutably."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Bounded indexed reads scoped to the signed-in account and its claimed guest edits. Does not contact Stripe. API keys cannot access this endpoint."
      }
    },
    "/api/account/downloads": {
      "get": {
        "summary": "Read older account downloads",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "edits": {
                      "type": "array",
                      "maxItems": 10,
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "state": {
                            "enum": [
                              "awaiting_upload",
                              "queued",
                              "processing",
                              "ready",
                              "failed",
                              "canceled",
                              "expired"
                            ]
                          },
                          "plan": {
                            "type": "string",
                            "description": "JSON-encoded ExportPlan"
                          },
                          "created_at": {
                            "type": "integer"
                          },
                          "expires_at": {
                            "type": "integer"
                          },
                          "has_thumbnail": {
                            "type": "integer",
                            "enum": [
                              0,
                              1
                            ]
                          }
                        }
                      }
                    },
                    "editsCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 256
            }
          }
        ],
        "description": "Use editsCursor from account history or this endpoint. Stable keyset pagination includes claimed guest edits. API keys are rejected; no image bytes are loaded by this query."
      }
    },
    "/api/v1/edits/{id}/thumbnail": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read an optional private preview",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "WebP or JPEG preview, private/no-store, same expiry as the result",
            "content": {
              "image/webp": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "put": {
        "summary": "Store an optional locally generated preview",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Ready edits only. At most 192 pixels per edge and 24 KiB, single-frame WebP or JPEG. Repeated upload preserves the first preview. Does not generate an image or change credits. Twenty attempts/owner/minute.",
        "requestBody": {
          "required": true,
          "content": {
            "image/webp": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 24576
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 24576
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "Request rejected. 400/413/415: invalid or oversized input; 401/403: authentication/origin; 404: missing or not owned; 402: insufficient credits; 409: state/price/idempotency conflict; 410: expired; 429: rate/capacity; 503: disabled service, unqualified tier, or temporary failure.",
        "headers": {
          "Retry-After": {
            "description": "Seconds until a rate limit or admission-capacity rejection may be retried; present on 429 responses.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "error"
              ],
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer"
      },
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-aie_session"
      }
    },
    "schemas": {
      "Geometry": {
        "type": "object",
        "required": [
          "width",
          "height"
        ],
        "properties": {
          "width": {
            "type": "integer",
            "minimum": 1,
            "maximum": 16384
          },
          "height": {
            "type": "integer",
            "minimum": 1,
            "maximum": 16384
          }
        }
      },
      "ExportPlan": {
        "type": "object",
        "required": [
          "version",
          "target",
          "canvas",
          "crop",
          "format"
        ],
        "properties": {
          "version": {
            "const": 1
          },
          "target": {
            "$ref": "#/components/schemas/Geometry"
          },
          "canvas": {
            "$ref": "#/components/schemas/Geometry"
          },
          "crop": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Geometry"
              },
              {
                "type": "object",
                "required": [
                  "x",
                  "y"
                ],
                "properties": {
                  "x": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "y": {
                    "type": "integer",
                    "minimum": 0
                  }
                }
              }
            ]
          },
          "format": {
            "enum": [
              "image/png",
              "image/jpeg",
              "image/webp"
            ]
          },
          "background": {
            "const": "transparent",
            "description": "Optional instruction to preserve transparent output. The website sets this when the original has transparent pixels."
          }
        }
      },
      "Edit": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "hasThumbnail": {
            "type": "boolean"
          },
          "uploaded": {
            "type": "boolean",
            "description": "Input upload was accepted; a resumed awaiting_upload job can be submitted without uploading again."
          },
          "state": {
            "enum": [
              "awaiting_upload",
              "queued",
              "processing",
              "ready",
              "failed",
              "canceled",
              "expired"
            ]
          },
          "exportPlan": {
            "$ref": "#/components/schemas/ExportPlan"
          },
          "chargeCredits": {
            "type": "number"
          },
          "expiresAt": {
            "type": "integer",
            "description": "Unix milliseconds. Pending job deadline; reset to one hour after successful completion."
          },
          "createdAt": {
            "type": "integer"
          },
          "pollAfterMs": {
            "type": "integer",
            "minimum": 3000,
            "maximum": 10000,
            "description": "Suggested delay before the next status request."
          },
          "resultUrl": {
            "type": "string"
          },
          "error": {
            "type": "string"
          },
          "failureReason": {
            "enum": [
              "moderation",
              "invalid_image",
              "provider_error",
              "unknown"
            ],
            "description": "Optional safe category for a failed edit. The existing error code remains authoritative; private provider diagnostics and request IDs are never returned. A new attempt requires an explicit new request after confirmed failure."
          }
        }
      }
    }
  }
}
