{
  "openapi": "3.1.0",
  "info": {
    "title": "EraseText API",
    "version": "1.0.0",
    "summary": "Erase lettering from images over HTTP.",
    "description": "Same specialised text-erase path as All text and Select in the EraseText editor. Authenticate with an API key (`X-Api-Key: et_…`). One successful `POST /erase` spends 1 credit; failures and `GET /account` are free. First key grants a one-time 50 API-credit trial. Do not send `size` or `engine` — both are retired and return 400.\n\nMCP: `https://api.erasetext.com/mcp` uses the same key and billing. Docs: https://erasetext.com/docs/api/",
    "contact": {
      "name": "Morling, LLC",
      "email": "support@erasetext.com",
      "url": "https://erasetext.com/about/#contact"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://erasetext.com/legal/terms/"
    }
  },
  "servers": [
    {
      "url": "https://api.erasetext.com/v1",
      "description": "Public gateway"
    }
  ],
  "security": [{ "apiKey": [] }],
  "tags": [
    { "name": "erase", "description": "Text removal" },
    { "name": "account", "description": "Balances and usage" }
  ],
  "paths": {
    "/erase": {
      "post": {
        "tags": ["erase"],
        "operationId": "eraseText",
        "summary": "Erase text from an image",
        "description": "Synchronous. Returns image bytes by default (WebP). Send `response=json` for base64. Omit the mask to detect and erase all text. White pixels (channel >127) in a mask mark what to erase. Charged 1 credit only after a successful plate. Times out at 90s with 504 and no charge.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": { "$ref": "#/components/schemas/EraseMultipart" }
            },
            "application/json": {
              "schema": { "$ref": "#/components/schemas/EraseJson" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Erased image",
            "headers": {
              "X-Credits-Charged": {
                "schema": { "type": "integer", "example": 1 }
              },
              "X-Credits-Remaining": {
                "schema": { "type": "integer" }
              },
              "X-RateLimit-Limit": { "schema": { "type": "integer" } },
              "X-RateLimit-Remaining": { "schema": { "type": "integer" } },
              "X-RateLimit-Reset": {
                "description": "Unix seconds",
                "schema": { "type": "integer" }
              },
              "X-Ocr-Boxes": {
                "description": "JSON quads when return_boxes=1 and no mask",
                "schema": { "type": "string" }
              }
            },
            "content": {
              "image/webp": { "schema": { "type": "string", "format": "binary" } },
              "image/png": { "schema": { "type": "string", "format": "binary" } },
              "image/jpeg": { "schema": { "type": "string", "format": "binary" } },
              "application/json": {
                "schema": { "$ref": "#/components/schemas/EraseJsonResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "402": { "$ref": "#/components/responses/PaymentRequired" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "502": { "$ref": "#/components/responses/Error" },
          "504": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/account": {
      "get": {
        "tags": ["account"],
        "operationId": "getAccount",
        "summary": "Balances and this month's usage",
        "description": "Never spends a credit. Safe to poll before a batch.",
        "responses": {
          "200": {
            "description": "Account snapshot",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Account" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "Key from Account → Developer. Prefix `et_`."
      }
    },
    "schemas": {
      "EraseMultipart": {
        "type": "object",
        "properties": {
          "image_file": { "type": "string", "format": "binary" },
          "image_url": { "type": "string", "format": "uri" },
          "mask_file": { "type": "string", "format": "binary" },
          "mask_url": { "type": "string", "format": "uri" },
          "format": {
            "type": "string",
            "enum": ["webp", "png", "jpg", "jpeg"],
            "default": "webp"
          },
          "resolution": {
            "type": "integer",
            "minimum": 256,
            "maximum": 1024,
            "default": 512,
            "description": "Short-edge target for the model"
          },
          "paste_back": { "type": "string", "default": "true" },
          "return_boxes": {
            "type": "string",
            "description": "1/true when no mask — OCR quads in X-Ocr-Boxes"
          },
          "response": {
            "type": "string",
            "enum": ["json"],
            "description": "Return JSON with base64 instead of raw bytes"
          }
        }
      },
      "EraseJson": {
        "type": "object",
        "properties": {
          "image_url": { "type": "string", "format": "uri" },
          "image_file_b64": { "type": "string", "description": "Raw or data-URL base64" },
          "mask_url": { "type": "string", "format": "uri" },
          "mask_file_b64": { "type": "string" },
          "format": {
            "type": "string",
            "enum": ["webp", "png", "jpg", "jpeg"],
            "default": "webp"
          },
          "resolution": {
            "type": "integer",
            "minimum": 256,
            "maximum": 1024,
            "default": 512
          },
          "paste_back": { "type": "boolean", "default": true },
          "return_boxes": { "type": "boolean" },
          "response": { "type": "string", "enum": ["json"] }
        }
      },
      "EraseJsonResponse": {
        "type": "object",
        "required": [
          "image_base64",
          "content_type",
          "credits_charged",
          "credits_remaining"
        ],
        "properties": {
          "image_base64": { "type": "string" },
          "content_type": { "type": "string", "example": "image/webp" },
          "credits_charged": { "type": "integer", "example": 1 },
          "credits_remaining": { "type": "integer" },
          "ocr_boxes": { "type": ["array", "null"], "items": {} }
        }
      },
      "Account": {
        "type": "object",
        "properties": {
          "credits": {
            "type": "object",
            "properties": {
              "total": { "type": "integer" },
              "api": { "type": "integer" },
              "web": { "type": "integer" }
            }
          },
          "plan": { "type": "string" },
          "api": {
            "type": "object",
            "properties": {
              "credit_cost_per_call": { "type": "integer", "example": 1 },
              "month": { "type": "string" },
              "calls": { "type": "integer" },
              "credits_spent": { "type": "integer" }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["error", "code"],
        "properties": {
          "error": { "type": "string" },
          "code": {
            "type": "string",
            "enum": [
              "bad_request",
              "invalid_api_key",
              "insufficient_credits",
              "not_found",
              "method_not_allowed",
              "rate_limit",
              "busy",
              "internal",
              "erase_failed",
              "misconfigured",
              "timeout"
            ]
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "JSON `{ error, code }`",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" }
          }
        }
      },
      "PaymentRequired": {
        "description": "Not enough credits",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                { "$ref": "#/components/schemas/Error" },
                {
                  "type": "object",
                  "properties": {
                    "required": { "type": "integer" },
                    "balance": { "type": "integer" }
                  }
                }
              ]
            }
          }
        }
      },
      "RateLimited": {
        "description": "Per-key RPM or backend busy",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                { "$ref": "#/components/schemas/Error" },
                {
                  "type": "object",
                  "properties": {
                    "retryAfter": { "type": "integer" }
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}
