{
  "openapi": "3.1.0",
  "info": {
    "title": "AI GIF Generator API",
    "version": "2.0.0",
    "description": "Text and optional still-image references produce native GIF downloads. One fixed server profile: 9 frames, 200 ms each. API generation costs one credit (20 accounting units) on success. No daily free API use. API keys must stay in trusted local or server code."
  },
  "servers": [
    {
      "url": "https://ai-gif-generator.com"
    }
  ],
  "paths": {
    "/api/v1/edits/quote": {
      "post": {
        "summary": "Quote a text or reference GIF generation",
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 4000
                  },
                  "reference": {
                    "$ref": "#/components/schemas/Reference"
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "prompt"
                    ],
                    "properties": {
                      "prompt": {
                        "type": "string",
                        "pattern": "\\S"
                      }
                    }
                  },
                  {
                    "required": [
                      "reference"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "inputKind": {
                      "enum": [
                        "text",
                        "image"
                      ]
                    },
                    "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"
          },
          "502": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/edits": {
      "post": {
        "summary": "Create a GIF generation; text queues immediately, references require upload and submit",
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 4000
                  },
                  "reference": {
                    "$ref": "#/components/schemas/Reference"
                  },
                  "expectedChargeUnits": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "idempotencyKey": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9_-]{16,80}$"
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "prompt"
                    ],
                    "properties": {
                      "prompt": {
                        "type": "string",
                        "pattern": "\\S"
                      }
                    }
                  },
                  {
                    "required": [
                      "reference"
                    ]
                  }
                ],
                "required": [
                  "expectedChargeUnits",
                  "idempotencyKey"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "inputKind": {
                      "enum": [
                        "text",
                        "image"
                      ]
                    },
                    "state": {
                      "enum": [
                        "awaiting_upload",
                        "queued",
                        "processing",
                        "ready",
                        "failed",
                        "canceled",
                        "expired"
                      ]
                    },
                    "uploaded": {
                      "type": "boolean"
                    },
                    "hasThumbnail": {
                      "type": "boolean"
                    },
                    "gif": {
                      "$ref": "#/components/schemas/GifMetadata"
                    },
                    "chargeCredits": {
                      "type": "number"
                    },
                    "expiresAt": {
                      "type": "integer",
                      "description": "Unix milliseconds; availability ends one hour after completion."
                    },
                    "createdAt": {
                      "type": "integer"
                    },
                    "pollAfterMs": {
                      "type": "integer",
                      "minimum": 3000,
                      "maximum": 10000
                    },
                    "resultUrl": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "failureReason": {
                      "enum": [
                        "moderation",
                        "invalid_image",
                        "provider_error",
                        "unknown"
                      ]
                    },
                    "uploadUrl": {
                      "type": "string",
                      "description": "Present only for reference jobs."
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "inputKind": {
                      "enum": [
                        "text",
                        "image"
                      ]
                    },
                    "state": {
                      "enum": [
                        "awaiting_upload",
                        "queued",
                        "processing",
                        "ready",
                        "failed",
                        "canceled",
                        "expired"
                      ]
                    },
                    "uploaded": {
                      "type": "boolean"
                    },
                    "hasThumbnail": {
                      "type": "boolean"
                    },
                    "gif": {
                      "$ref": "#/components/schemas/GifMetadata"
                    },
                    "chargeCredits": {
                      "type": "number"
                    },
                    "expiresAt": {
                      "type": "integer",
                      "description": "Unix milliseconds; availability ends one hour after completion."
                    },
                    "createdAt": {
                      "type": "integer"
                    },
                    "pollAfterMs": {
                      "type": "integer",
                      "minimum": 3000,
                      "maximum": 10000
                    },
                    "resultUrl": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "failureReason": {
                      "enum": [
                        "moderation",
                        "invalid_image",
                        "provider_error",
                        "unknown"
                      ]
                    },
                    "uploadUrl": {
                      "type": "string",
                      "description": "Present only for reference jobs."
                    }
                  }
                }
              }
            }
          },
          "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"
          },
          "502": {
            "$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 the original job",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "inputKind": {
                      "enum": [
                        "text",
                        "image"
                      ]
                    },
                    "state": {
                      "enum": [
                        "awaiting_upload",
                        "queued",
                        "processing",
                        "ready",
                        "failed",
                        "canceled",
                        "expired"
                      ]
                    },
                    "uploaded": {
                      "type": "boolean"
                    },
                    "hasThumbnail": {
                      "type": "boolean"
                    },
                    "gif": {
                      "$ref": "#/components/schemas/GifMetadata"
                    },
                    "chargeCredits": {
                      "type": "number"
                    },
                    "expiresAt": {
                      "type": "integer",
                      "description": "Unix milliseconds; availability ends one hour after completion."
                    },
                    "createdAt": {
                      "type": "integer"
                    },
                    "pollAfterMs": {
                      "type": "integer",
                      "minimum": 3000,
                      "maximum": 10000
                    },
                    "resultUrl": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "failureReason": {
                      "enum": [
                        "moderation",
                        "invalid_image",
                        "provider_error",
                        "unknown"
                      ]
                    }
                  }
                }
              }
            }
          },
          "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"
          },
          "502": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "summary": "Cancel before processing or delete private 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"
          },
          "502": {
            "$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 declared prepared PNG; rejected for text jobs",
        "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"
          },
          "502": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 33554432
              }
            }
          }
        }
      }
    },
    "/api/v1/edits/{id}/submit": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "summary": "Idempotently enqueue a prepared reference job or recover a queued job",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "202": {
            "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"
          },
          "502": {
            "$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 original validated GIF bytes",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Private/no-store GIF. Save bytes directly; no final export step.",
            "content": {
              "image/gif": {
                "schema": {
                  "type": "string",
                  "format": "binary",
                  "maxLength": 33554432
                }
              }
            }
          },
          "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",
                      "decoder_load",
                      "decode_failed",
                      "browser_limit",
                      "encode_failed",
                      "network_error",
                      "storage_unavailable",
                      "timeout",
                      "unexpected"
                    ]
                  },
                  "format": {
                    "enum": [
                      "jpeg",
                      "png",
                      "webp",
                      "gif",
                      "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"
                    ]
                  }
                }
              }
            }
          }
        },
        "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"
                    },
                    "generationChargeUnits": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "minimum": 0,
                      "description": "Display-only paid-generation tariff hint; 0 in local mock mode, null when disabled. Creation revalidates expectedChargeUnits before admission."
                    },
                    "paymentsEnabled": {
                      "type": "boolean"
                    },
                    "emailEnabled": {
                      "type": "boolean"
                    },
                    "mode": {
                      "enum": [
                        "disabled",
                        "mock",
                        "live"
                      ]
                    },
                    "oauthProviders": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/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"
                        },
                        "generationChargeUnits": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "minimum": 0,
                          "description": "Display-only paid-generation tariff hint; 0 in local mock mode, null when disabled. Creation revalidates expectedChargeUnits before admission."
                        },
                        "paymentsEnabled": {
                          "type": "boolean"
                        },
                        "emailEnabled": {
                          "type": "boolean"
                        },
                        "mode": {
                          "enum": [
                            "disabled",
                            "mock",
                            "live"
                          ]
                        },
                        "oauthProviders": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "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; not a remaining-time estimate."
                    },
                    "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"
          },
          "502": {
            "$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}$"
            }
          }
        ],
        "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"
          },
          "502": {
            "$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"
          },
          "502": {
            "$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"
          },
          "502": {
            "$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"
          },
          "502": {
            "$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"
                    ],
                    "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"
          },
          "502": {
            "$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 version-2 generation plan; no local export needed"
                          },
                          "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"
          },
          "502": {
            "$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 version-2 generation plan; no local export needed"
                          },
                          "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"
          },
          "502": {
            "$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 preview, private/no-store, same expiry as the result",
            "content": {
              "image/webp": {
                "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"
          },
          "502": {
            "$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. 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
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "Rejected request. Error codes are safe fixed strings; prompts, private URLs and provider errors are never returned.",
        "headers": {
          "Retry-After": {
            "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-aigifgenerator_session"
      }
    },
    "schemas": {
      "Geometry": {
        "type": "object",
        "required": [
          "width",
          "height"
        ],
        "properties": {
          "width": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3840
          },
          "height": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3840
          }
        }
      },
      "Reference": {
        "type": "object",
        "required": [
          "width",
          "height",
          "uploadSha256",
          "uploadBytes"
        ],
        "properties": {
          "width": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3840
          },
          "height": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3840
          },
          "uploadSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "uploadBytes": {
            "type": "integer",
            "minimum": 45,
            "maximum": 33554432
          }
        },
        "additionalProperties": false,
        "description": "Prepared still PNG, at most 7,000,000 pixels; no upscaling, cropping or padding. For a GIF source, clients prepare only the first frame on its full logical canvas. Raw GIF uploads are not accepted."
      },
      "GifMetadata": {
        "type": "object",
        "description": "Native GIF metadata. New text-only jobs use 896x896. Reference jobs select the closest supported proportions within 1:3 to 3:1, up to 1280 pixels per edge and 830208 pixels per frame. Service-controlled high quality and dimensions cannot be overridden. Historical jobs retain their saved settings. Browser-resized copies do not alter this metadata.",
        "required": [
          "width",
          "height",
          "frameCount",
          "frameDurationMs",
          "durationMs",
          "loopCount"
        ],
        "properties": {
          "width": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
          },
          "height": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
          },
          "frameCount": {
            "const": 9
          },
          "frameDurationMs": {
            "const": 200
          },
          "durationMs": {
            "const": 1800
          },
          "loopCount": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "description": "0 means infinite, a positive number is finite, null means unspecified."
          }
        }
      },
      "Edit": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "inputKind": {
            "enum": [
              "text",
              "image"
            ]
          },
          "state": {
            "enum": [
              "awaiting_upload",
              "queued",
              "processing",
              "ready",
              "failed",
              "canceled",
              "expired"
            ]
          },
          "uploaded": {
            "type": "boolean"
          },
          "hasThumbnail": {
            "type": "boolean"
          },
          "gif": {
            "$ref": "#/components/schemas/GifMetadata"
          },
          "chargeCredits": {
            "type": "number"
          },
          "expiresAt": {
            "type": "integer",
            "description": "Unix milliseconds; availability ends one hour after completion."
          },
          "createdAt": {
            "type": "integer"
          },
          "pollAfterMs": {
            "type": "integer",
            "minimum": 3000,
            "maximum": 10000
          },
          "resultUrl": {
            "type": "string"
          },
          "error": {
            "type": "string"
          },
          "failureReason": {
            "enum": [
              "moderation",
              "invalid_image",
              "provider_error",
              "unknown"
            ]
          }
        }
      }
    }
  }
}
