{
  "openapi": "3.0.3",
  "info": {
    "title": "StartOCR API",
    "version": "1.1.0",
    "description": "Submit OCR jobs, poll task status, export results, and receive webhooks. Authenticate with `Authorization: Bearer <api_key>`."
  },
  "servers": [
    {
      "url": "https://startocr.com"
    }
  ],
  "paths": {
    "/api/ocr": {
      "post": {
        "operationId": "submitOcr",
        "summary": "Submit an OCR job",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "imageBase64"
                ],
                "properties": {
                  "imageBase64": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "provider": {
                    "type": "string",
                    "enum": [
                      "paddle-ai-studio",
                      "baidu"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task accepted"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Insufficient page balance"
          }
        }
      }
    },
    "/api/tasks": {
      "get": {
        "operationId": "listTasks",
        "summary": "List OCR tasks",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task list"
          }
        }
      }
    },
    "/api/tasks/{taskId}": {
      "get": {
        "operationId": "getTask",
        "summary": "Get a task (includes resultText when done)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "taskId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task detail"
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "delete": {
        "operationId": "deleteTask",
        "summary": "Delete a task and associated files",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "taskId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/api/export/{taskId}/{format}": {
      "get": {
        "operationId": "exportTask",
        "summary": "Export a completed task (requires ocr:read scope)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "taskId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "docx",
                "xlsx",
                "pdf"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Binary export"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key"
      }
    }
  }
}