{
  "openapi": "3.1.0",
  "info": {
    "title": "RestorePhotosApp API",
    "version": "1.0.0",
    "summary": "AI photo restoration, colorization, enhancement and animation.",
    "description": "HTTP API behind RestorePhotosApp. Most endpoints require an authenticated NextAuth session cookie. Errors are returned as structured JSON using the `Error` schema. This document is served at /openapi.json.",
    "contact": {
      "name": "RestorePhotosApp",
      "url": "https://restorephotosapp.com/contact"
    },
    "license": {
      "name": "MIT",
      "identifier": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://restorephotosapp.com",
      "description": "Production"
    }
  ],
  "externalDocs": {
    "description": "LLM-friendly product overview",
    "url": "https://restorephotosapp.com/llms.txt"
  },
  "tags": [
    {
      "name": "Service",
      "description": "Service discovery and status."
    },
    {
      "name": "Credits",
      "description": "Credit balance."
    },
    {
      "name": "Restoration",
      "description": "Upload, restore and animate photos."
    },
    {
      "name": "History",
      "description": "Past restorations."
    },
    {
      "name": "Billing",
      "description": "Checkout and purchases."
    }
  ],
  "paths": {
    "/api/status": {
      "get": {
        "tags": [
          "Service"
        ],
        "summary": "Service status",
        "description": "Public, unauthenticated health check. Returns links to the OpenAPI spec, llms.txt and sitemap.",
        "operationId": "getStatus",
        "security": [],
        "responses": {
          "200": {
            "description": "Service is reachable.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "service"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "service": {
                      "type": "string",
                      "example": "RestorePhotosApp"
                    },
                    "docs": {
                      "type": "string",
                      "format": "uri"
                    },
                    "llms": {
                      "type": "string",
                      "format": "uri"
                    },
                    "sitemap": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/remaining": {
      "get": {
        "tags": [
          "Credits"
        ],
        "summary": "Remaining credits",
        "description": "Returns the number of restoration credits for the signed-in user.",
        "operationId": "getRemaining",
        "responses": {
          "200": {
            "description": "Current credit balance.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "remainingGenerations"
                  ],
                  "properties": {
                    "remainingGenerations": {
                      "type": "integer",
                      "minimum": 0,
                      "example": 8
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/upload": {
      "post": {
        "tags": [
          "Restoration"
        ],
        "summary": "Upload a photo",
        "description": "Uploads raw image bytes (JPEG, PNG or WebP, max 10 MB) and returns a URL you can pass to /api/generate. Send the file as the raw request body with the matching Content-Type — not multipart/form-data.",
        "operationId": "uploadImage",
        "requestBody": {
          "required": true,
          "content": {
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/webp": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Upload succeeded.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "url"
                  ],
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/generate": {
      "post": {
        "tags": [
          "Restoration"
        ],
        "summary": "Restore a photo",
        "description": "Runs AI restoration on a previously uploaded image and returns the restored image URL. Consumes one credit. Note: for backwards compatibility this endpoint returns the restored URL as a bare JSON string on success and a bare JSON string message on error (it does not use the shared Error schema).",
        "operationId": "generateRestoration",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "imageUrl"
                ],
                "properties": {
                  "imageUrl": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL returned by /api/upload."
                  },
                  "style": {
                    "type": "string",
                    "description": "Restoration style.",
                    "enum": [
                      "restore",
                      "colorize",
                      "enhance",
                      "cleanup",
                      "sharpen",
                      "deblur",
                      "denoise"
                    ],
                    "default": "restore"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Restored image URL (bare JSON string).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input (bare JSON string message).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited or out of credits (bare JSON string message).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "description": "Restoration failed (bare JSON string message).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/api/animate": {
      "post": {
        "tags": [
          "Restoration"
        ],
        "summary": "Animate a photo",
        "description": "Starts an animation job for an image URL. Consumes credits.",
        "operationId": "animatePhoto",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "imageUrl"
                ],
                "properties": {
                  "imageUrl": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Animation job started.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Restoration"
        ],
        "summary": "Poll an animation job",
        "description": "Returns the status (and video URL when complete) for an animation job.",
        "operationId": "getAnimation",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Animation job id returned by POST /api/animate."
          }
        ],
        "responses": {
          "200": {
            "description": "Animation status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "completed"
                    },
                    "videoUrl": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/history": {
      "get": {
        "tags": [
          "History"
        ],
        "summary": "List restorations",
        "description": "Returns the signed-in user’s past restorations.",
        "operationId": "listHistory",
        "responses": {
          "200": {
            "description": "Restoration history.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/HistoryItem"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/history/{id}": {
      "delete": {
        "tags": [
          "History"
        ],
        "summary": "Delete a restoration",
        "operationId": "deleteHistoryItem",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/checkout": {
      "get": {
        "tags": [
          "Billing"
        ],
        "summary": "Start a checkout",
        "description": "Creates a Polar checkout for the given product and redirects (303) to the hosted checkout page. Redirects to /signin when not authenticated.",
        "operationId": "startCheckout",
        "parameters": [
          {
            "name": "productId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "303": {
            "description": "Redirect to the hosted checkout or /signin."
          },
          "400": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Structured error. `error.code` is a stable machine-readable identifier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "next-auth.session-token",
        "description": "NextAuth session cookie obtained by signing in at /signin. Over HTTPS the cookie is named __Secure-next-auth.session-token."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "status",
              "docs"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Stable machine-readable error identifier.",
                "example": "unauthorized"
              },
              "message": {
                "type": "string",
                "description": "Human-readable explanation."
              },
              "status": {
                "type": "integer",
                "description": "HTTP status code.",
                "example": 401
              },
              "hint": {
                "type": "string",
                "description": "Optional resolution suggestion."
              },
              "docs": {
                "type": "string",
                "format": "uri",
                "description": "Link to this spec."
              }
            }
          }
        }
      },
      "HistoryItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "originalUrl": {
            "type": "string",
            "format": "uri"
          },
          "restoredUrl": {
            "type": "string",
            "format": "uri"
          },
          "style": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "security": [
    {
      "sessionCookie": []
    }
  ]
}