{
  "openapi": "3.1.0",
  "info": {
    "title": "AIIPWorld API",
    "version": "1.0.0",
    "summary": "Render HTML or URLs to PDF, PNG or JPEG, and process images, with one asynchronous job API.",
    "description": "The AIIPWorld API runs jobs on isolated, resource-limited worker containers. Every job is asynchronous: submit it (202 with a `job_id`), poll `GET /v1/jobs/{id}` until `status` is `succeeded`, `failed` or `timeout`, then fetch the file from `download_url`, a signed link that works for 10 minutes by default (no API key needed on that link; request the job again for a fresh one).\n\nCredits: one pool covers the API and the web tools. Credits are reserved at submit and settled when the job ends; credits for failed and timed-out jobs are returned. The free plan includes 100 credits a month. Credit costs are provisional until launch.\n\nRate limits per minute, per key: Free 30, Starter 60, Pro 180, Business 600. Results are deleted at `expires_at`: 1 day on Free, 7 days on Starter and Pro, 30 days on Business.\n\nNot available yet: webhooks, templates (`template_id`) and WebP render output.",
    "contact": {
      "name": "AIIPWorld",
      "email": "contact@aiipworld.com",
      "url": "https://aiipworld.com/docs/"
    },
    "termsOfService": "https://aiipworld.com/terms/"
  },
  "externalDocs": {
    "description": "API documentation",
    "url": "https://aiipworld.com/docs/"
  },
  "servers": [
    {
      "url": "https://api.aiipworld.com",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Render",
      "description": "HTML or URL to PDF, PNG, JPEG or rendered HTML (headless Chromium)."
    },
    {
      "name": "Images",
      "description": "Upload an image and trace, convert, resize or compress it."
    },
    {
      "name": "Jobs",
      "description": "Poll job status and get download links."
    },
    {
      "name": "Usage",
      "description": "Credit balance and recent debits."
    },
    {
      "name": "Files",
      "description": "Upload files and run PDF, e-book, Office and image-combine jobs on them."
    },
    {
      "name": "Health",
      "description": "Gateway health."
    }
  ],
  "security": [
    {
      "bearerAuth": []
    },
    {
      "apiKeyHeader": []
    }
  ],
  "paths": {
    "/v1/render": {
      "post": {
        "operationId": "createRenderJob",
        "tags": [
          "Render"
        ],
        "summary": "Render HTML or a URL to PDF, PNG, JPEG or HTML",
        "description": "Send exactly one of `html` or `url`. `output` is `pdf` (default), `png`, `jpeg` or `html`. `output=html` needs `url`: the result is the page's HTML after its JavaScript has run, as a text file. `options` is passed to the rendering engine; unknown option names are rejected when the job runs (the job fails with `invalid_input`).\n\nCredits: a simple render costs 1 credit. PDFs beyond 10 pages cost 1 more credit per further 10 pages (or part of); a full-page screenshot (`options.full_page`) costs 2 credits up to 5,000 px of output height, plus 1 per further 5,000 px (or part of), 5 at most (the job is reserved at 2 and settled on the real image height; output px = CSS px x `device_scale_factor`); a result over 5 MB costs 1 more credit per further 5 MB. Requests to private network addresses are blocked.\n\nRequest body is limited to 256 KB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RenderRequest"
              },
              "examples": {
                "htmlToPdf": {
                  "summary": "HTML to PDF",
                  "value": {
                    "html": "<h1>Hello</h1><p>Rendered by headless Chromium.</p>",
                    "output": "pdf",
                    "options": {
                      "format": "A4",
                      "print_background": true
                    }
                  }
                },
                "urlToPng": {
                  "summary": "Screenshot of a public page",
                  "value": {
                    "url": "https://aiipworld.com",
                    "output": "png",
                    "options": {
                      "viewport": {
                        "width": 1280,
                        "height": 800
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted and queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobAccepted"
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters. `error` is one of `invalid_source`, `invalid_output`, `invalid_options`, `invalid_data`, `data_requires_template`, `invalid_timeout_sec` or `invalid_params`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_source",
                  "message": "provide exactly one of template_id, html, url"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientCredits"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "501": {
            "description": "Reserved feature: `template_id` (`templates_not_implemented`) or `output=webp` (`output_not_supported`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "output_not_supported",
                  "message": "webp output is not supported by the engine yet; use pdf, png or jpeg"
                }
              }
            }
          }
        }
      }
    },
    "/v1/image-jobs": {
      "post": {
        "operationId": "createImageJob",
        "tags": [
          "Images"
        ],
        "summary": "Trace, convert, resize or compress an image",
        "description": "Send the image itself as the request body (not JSON) and set `Content-Type` to `image/png`, `image/jpeg`, `image/webp`, `image/avif`, `image/gif`, `image/bmp` or `image/tiff`. The file is identified by its content, not by its name or header. AVIF is read as input only; the API never writes AVIF. Maximum 10 MB and 16 MP (4096 x 4096). SVG, PDF, HEIC, BigTIFF and camera RAW files are rejected with `400 unsupported_image`; a larger file gets `413 file_too_large`. Settings go in the query string; each may appear once.\n\n`op=image_to_svg` (default) traces to SVG vector paths: 5 credits, plus 1 per 5 MB of SVG after the first 5 MB. `op=image_convert` converts the format to png, jpeg, webp, gif or ico (requires `format`). `op=image_resize` makes the picture smaller in pixels (exactly one of `scale`, `max_side`, or `width` and/or `height`). `op=image_compress` makes the file smaller at the same pixel size (`quality` or `target_kb`, not both). Convert, resize and compress each cost 1 credit, plus 1 per 5 MB of result after the first 5 MB; animations add 1 credit per started 10 megapixels of decoded frames beyond the first 10 (up to 300 frames and 64 MP). The uploaded file is deleted when the job ends.\n\nJobs can fail with `invalid_input`, `output_limit` (result over 20 MB), `memory_limit` or `timeout`; credits are returned.",
        "parameters": [
          {
            "name": "op",
            "in": "query",
            "required": false,
            "description": "Operation. The settings of each op are the other query parameters (the docs list them for each op, including image_to_text, image_invert, image_edit, gif_edit and image_remove_bg); a name that does not belong to the op is rejected. HEIC input is accepted by image_convert only; a PDF is accepted by image_to_text only.",
            "schema": {
              "type": "string",
              "enum": [
                "image_to_svg",
                "image_convert",
                "image_resize",
                "image_compress",
                "gif_edit",
                "image_to_text",
                "image_invert",
                "image_edit",
                "image_remove_bg"
              ],
              "default": "image_to_svg"
            }
          },
          {
            "name": "timeout_sec",
            "in": "query",
            "required": false,
            "description": "Hard time limit for the job. Send 60 for animations.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 60,
              "default": 30
            }
          },
          {
            "name": "colormode",
            "in": "query",
            "required": false,
            "description": "image_to_svg: full colour, or one black layer for line art, signatures and scans.",
            "schema": {
              "type": "string",
              "enum": [
                "color",
                "binary"
              ],
              "default": "color"
            }
          },
          {
            "name": "hierarchical",
            "in": "query",
            "required": false,
            "description": "image_to_svg: stacked colour shapes (smaller file) or cut out so none overlap. Colour mode only.",
            "schema": {
              "type": "string",
              "enum": [
                "stacked",
                "cutout"
              ],
              "default": "stacked"
            }
          },
          {
            "name": "mode",
            "in": "query",
            "required": false,
            "description": "image_to_svg: smooth curves, or straight edges (smaller file).",
            "schema": {
              "type": "string",
              "enum": [
                "spline",
                "polygon"
              ],
              "default": "spline"
            }
          },
          {
            "name": "filter_speckle",
            "in": "query",
            "required": false,
            "description": "image_to_svg: drop patches smaller than this many pixels.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 16,
              "default": 4
            }
          },
          {
            "name": "color_precision",
            "in": "query",
            "required": false,
            "description": "image_to_svg: significant bits per colour channel. Lower means fewer colours.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8,
              "default": 6
            }
          },
          {
            "name": "layer_difference",
            "in": "query",
            "required": false,
            "description": "image_to_svg: smallest colour difference between layers. Higher means fewer layers.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 255,
              "default": 16
            }
          },
          {
            "name": "corner_threshold",
            "in": "query",
            "required": false,
            "description": "image_to_svg: smallest turn, in degrees, that counts as a corner.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 180,
              "default": 60
            }
          },
          {
            "name": "segment_length",
            "in": "query",
            "required": false,
            "description": "image_to_svg: curve fitting: subdivide until segments are shorter than this.",
            "schema": {
              "type": "number",
              "minimum": 3.5,
              "maximum": 10,
              "default": 4
            }
          },
          {
            "name": "splice_threshold",
            "in": "query",
            "required": false,
            "description": "image_to_svg: curve fitting: smallest angle change, in degrees, at which a curve is spliced.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 180,
              "default": 45
            }
          },
          {
            "name": "path_precision",
            "in": "query",
            "required": false,
            "description": "image_to_svg: decimal places in path coordinates. Lower means a smaller file.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 4,
              "default": 2
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "Result format. Required for image_convert (png, jpeg, webp, gif or ico). For image_resize and image_compress: same (default; keeps PNG, JPEG, WebP and GIF; BMP and TIFF become PNG, AVIF becomes WebP), png, jpeg, webp or gif.",
            "schema": {
              "type": "string",
              "enum": [
                "same",
                "png",
                "jpeg",
                "webp",
                "gif",
                "ico"
              ]
            }
          },
          {
            "name": "quality",
            "in": "query",
            "required": false,
            "description": "JPEG and lossy WebP quality. Default 80 for convert and resize, 75 for compress. For compress it cannot be combined with target_kb, and it is not accepted for GIF output.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "lossless",
            "in": "query",
            "required": false,
            "description": "image_convert: WebP only, keep every pixel. image_compress: PNG skips colour reduction, WebP is lossless; cannot be combined with quality or target_kb.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "keep_transparency",
            "in": "query",
            "required": false,
            "description": "Keep the alpha channel in PNG and WebP (and GIF for resize). JPEG has no alpha, so transparent areas are always filled.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "background",
            "in": "query",
            "required": false,
            "description": "Colour (#rrggbb) that fills transparent areas when the result is flattened. URL-encode the # as %23.",
            "schema": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$",
              "default": "#ffffff"
            }
          },
          {
            "name": "animate",
            "in": "query",
            "required": false,
            "description": "Animated GIF or WebP keeps all frames, timing and loop count when the output is GIF or WebP. false (or PNG, JPEG, ICO output) uses only the first frame.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "ico_sizes",
            "in": "query",
            "required": false,
            "description": "image_convert, ico only: comma list of square sizes from 16, 32, 48, 64, 128, 256.",
            "schema": {
              "type": "string",
              "default": "16,32,48"
            }
          },
          {
            "name": "ico_fit",
            "in": "query",
            "required": false,
            "description": "image_convert, ico only: contain fits inside the square; cover fills it and crops from the centre.",
            "schema": {
              "type": "string",
              "enum": [
                "contain",
                "cover"
              ],
              "default": "contain"
            }
          },
          {
            "name": "scale",
            "in": "query",
            "required": false,
            "description": "image_resize: percent of the original size. Give exactly one of scale, max_side, or width and/or height.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "max_side",
            "in": "query",
            "required": false,
            "description": "image_resize: the longest side, in pixels.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 16384
            }
          },
          {
            "name": "width",
            "in": "query",
            "required": false,
            "description": "image_resize: target box width in pixels.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 16384
            }
          },
          {
            "name": "height",
            "in": "query",
            "required": false,
            "description": "image_resize: target box height in pixels.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 16384
            }
          },
          {
            "name": "fit",
            "in": "query",
            "required": false,
            "description": "image_resize: inside fits within the box; cover fills and crops; contain fits on a canvas of exactly width by height. cover and contain need both width and height.",
            "schema": {
              "type": "string",
              "enum": [
                "inside",
                "cover",
                "contain"
              ],
              "default": "inside"
            }
          },
          {
            "name": "target_kb",
            "in": "query",
            "required": false,
            "description": "image_compress: aim for a file of at most this many KB (1 KB = 1024 bytes). result.target_reached is false when it cannot get there.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 20480
            }
          },
          {
            "name": "colours",
            "in": "query",
            "required": false,
            "description": "image_compress, GIF output only: palette size.",
            "schema": {
              "type": "integer",
              "enum": [
                256,
                16,
                4,
                2
              ],
              "default": 256
            }
          },
          {
            "name": "dither",
            "in": "query",
            "required": false,
            "description": "image_compress, GIF output only: how much the colour steps are spread out.",
            "schema": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "default": 1
            }
          },
          {
            "name": "lossy",
            "in": "query",
            "required": false,
            "description": "image_compress, GIF output only: how much change between frames is ignored. Lossy.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 32,
              "default": 20
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/webp": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/avif": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/gif": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/bmp": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/tiff": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/heic": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted and queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobAccepted"
                },
                "example": {
                  "job_id": "0b8f6d1c-3c1e-4c52-9d3a-6f3a2b6f2a10",
                  "status": "queued",
                  "credits_reserved": 5
                }
              }
            }
          },
          "400": {
            "description": "Invalid request. `error` is one of `invalid_op`, `invalid_params`, `invalid_timeout_sec`, `empty_body` or `unsupported_image`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unsupported_image",
                  "message": "the file is not a PNG, JPG, WebP, AVIF, GIF, BMP or TIFF image (SVG, PDF, HEIC and camera RAW files are not accepted)"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientCredits"
          },
          "413": {
            "description": "The image is over the size limit (10 MB).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "file_too_large",
                  "max_bytes": 10485760,
                  "message": "the image is 12.0 MB; the limit is 10 MB"
                }
              }
            }
          },
          "415": {
            "description": "The body was not sent as raw bytes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unsupported_media_type",
                  "message": "send the raw image bytes with Content-Type image/png, image/jpeg, image/webp, image/avif, image/gif, image/bmp or image/tiff"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "description": "Object storage is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "storage_unavailable"
                }
              }
            }
          }
        }
      }
    },
    "/v1/jobs/{id}": {
      "get": {
        "operationId": "getJob",
        "tags": [
          "Jobs"
        ],
        "summary": "Get a job",
        "description": "Returns `status` (`queued`, `running`, `succeeded`, `failed`, `timeout`), `result` (pages, bytes, timings), and once the job succeeded `download_url` and `expires_at`. A key can only read its own jobs. `download_url` is a short-lived signed link (10 minutes by default): fetch the file directly, no API key needed; request the job again for a fresh link. Results are deleted at `expires_at`; after that `download_url` is `null` and `result_expired` is `true`. Poll calls count toward the per-minute rate limit, so back off (for example 1 s growing to 5 s).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The `job_id` returned when the job was submitted.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The job.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "No such job for this key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "not_found"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/jobs/{id}/download": {
      "get": {
        "operationId": "downloadJobResult",
        "tags": [
          "Jobs"
        ],
        "summary": "Download the result through the gateway",
        "description": "Streams the result file as an attachment (`Content-Disposition: attachment`, `X-Content-Type-Options: nosniff`). This route needs the API key; the signed `download_url` in the job does not.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The result file.",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "No such job for this key (`not_found`), or the result is not available: the job did not succeed or the result was deleted (`result_not_available`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "description": "Storage unavailable (`storage_unavailable`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "operationId": "getUsage",
        "tags": [
          "Usage"
        ],
        "summary": "Get the credit balance and recent debits",
        "description": "Returns the current period, your plan, the credit balance (plan credits and top-up credits) and up to 20 recent debits.",
        "responses": {
          "200": {
            "description": "Usage.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/jobs": {
      "post": {
        "operationId": "createJob",
        "tags": [
          "Jobs"
        ],
        "summary": "Create a job from an op name",
        "description": "The generic JSON entry point: the render ops by name (html_to_pdf, url_to_pdf, url_to_html, screenshot; `POST /v1/render` is the friendlier form of these) and `chart_render`, which draws a chart from a spec in `params`. Ops that take an uploaded file are refused with `upload_required`: use `POST /v1/image-jobs` or `POST /v1/pdf-jobs`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JobRequest"
              },
              "examples": {
                "chart": {
                  "summary": "A histogram",
                  "value": {
                    "op": "chart_render",
                    "params": {
                      "type": "histogram",
                      "title": "Exam scores",
                      "x_label": "Score",
                      "data": {
                        "values": [
                          62,
                          71,
                          85,
                          90,
                          77,
                          68,
                          74,
                          88,
                          93,
                          59,
                          81,
                          76
                        ]
                      },
                      "format": "png"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted and queued. Credits are reserved now and settled when the job ends; credits for failed and timed-out jobs are returned.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobAccepted"
                }
              }
            }
          },
          "400": {
            "description": "Unknown op (`invalid_op`, with the allowed list), `upload_required`, `invalid_params`, `invalid_input_path` or `invalid_timeout_sec`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientCredits"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/v1/uploads": {
      "post": {
        "operationId": "uploadFile",
        "tags": [
          "Files"
        ],
        "summary": "Upload one file for a PDF job",
        "description": "The request body is the file itself (raw bytes), one file per request. The type is read from the content, not from the name or header: PDF, PNG, JPEG, WebP, TIFF, Office document or e-book. The returned `upload_id` is valid for `expires_in_sec` seconds and can be used once, in `POST /v1/pdf-jobs`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Upload"
                }
              }
            }
          },
          "400": {
            "description": "Empty body (`empty_body`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "413": {
            "description": "File too large (`file_too_large`, with `max_bytes`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Not a supported file type (`unsupported_file`, `unsupported_media_type`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Password-protected or DRM-protected file (`password_protected`, `drm_protected`); it is refused and not stored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "description": "Too many large uploads in progress (`busy`, retry after the `Retry-After` seconds) or storage unavailable (`storage_unavailable`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/pdf-jobs": {
      "post": {
        "operationId": "createPdfJob",
        "tags": [
          "Files"
        ],
        "summary": "PDF, e-book, Office and image-combine jobs on uploaded files",
        "description": "Upload each file with `POST /v1/uploads`, then send the upload ids here. `pdf_merge` takes 2 or more PDFs, `image_to_pdf` and `image_combine` take images in the result order, every other op takes exactly one file. `params` depends on the op (see the docs). Each upload can be used once.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PdfJobRequest"
              },
              "examples": {
                "merge": {
                  "summary": "Merge two PDFs",
                  "value": {
                    "op": "pdf_merge",
                    "params": {},
                    "files": [
                      "UPLOAD_ID_1",
                      "UPLOAD_ID_2"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted and queued. Credits are reserved now and settled when the job ends; credits for failed and timed-out jobs are returned.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobAccepted"
                }
              }
            }
          },
          "400": {
            "description": "Invalid op, params, files or timeout (`invalid_op`, `invalid_params`, `invalid_files`, `invalid_timeout_sec`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientCredits"
          },
          "404": {
            "description": "An upload does not exist, has expired, was used already or belongs to someone else (`upload_not_found`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Wrong number of files or a file this op does not accept (`too_few_files`, `too_many_files`, `wrong_file_count`, `duplicate_upload`, `unsupported_image`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/healthz": {
      "get": {
        "operationId": "getHealth",
        "tags": [
          "Health"
        ],
        "summary": "Health of the gateway",
        "description": "No API key needed. 200 when the database and the job queue store both answer, 503 when one does not. The same endpoint feeds https://aiipworld.com/status/.",
        "security": [],
        "responses": {
          "200": {
            "description": "Healthy.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          },
          "503": {
            "description": "A dependency is down.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key (sk_...)",
        "description": "Create a key in the dashboard at https://aiipworld.com and send it as `Authorization: Bearer sk_...`. The key is shown once; keep it server-side, never in browser code."
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Alternative to the Bearer header: send the same key in `x-api-key`."
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid API key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "invalid_api_key"
            }
          }
        }
      },
      "InsufficientCredits": {
        "description": "Not enough credits for this job.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "insufficient_credits",
              "required": 1,
              "balance": {
                "plan": 0,
                "topup": 0,
                "total": 0,
                "period": "2026-10"
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit for the key exceeded. Wait `Retry-After` seconds.",
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait.",
            "schema": {
              "type": "integer"
            }
          },
          "x-ratelimit-limit": {
            "description": "Requests per minute allowed for this key.",
            "schema": {
              "type": "integer"
            }
          },
          "x-ratelimit-remaining": {
            "description": "Requests left in the current window.",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "rate_limited",
              "retry_after_sec": 12
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Machine-readable error code."
          },
          "message": {
            "type": "string"
          }
        },
        "additionalProperties": true
      },
      "RenderRequest": {
        "type": "object",
        "description": "Send exactly one of `html` or `url`.",
        "properties": {
          "html": {
            "type": "string",
            "description": "HTML to render. Not allowed with `output=html`."
          },
          "url": {
            "type": "string",
            "maxLength": 2048,
            "description": "Public http or https address. Private networks, localhost and cloud metadata addresses are blocked (also after redirects)."
          },
          "output": {
            "type": "string",
            "enum": [
              "pdf",
              "png",
              "jpeg",
              "html"
            ],
            "default": "pdf",
            "description": "Result type. `html` needs `url`. `webp` is reserved and returns 501."
          },
          "options": {
            "$ref": "#/components/schemas/RenderOptions"
          },
          "timeout_sec": {
            "type": "integer",
            "minimum": 1,
            "maximum": 300,
            "default": 30,
            "description": "Hard time limit for the job."
          }
        },
        "oneOf": [
          {
            "required": [
              "html"
            ]
          },
          {
            "required": [
              "url"
            ]
          }
        ]
      },
      "RenderOptions": {
        "type": "object",
        "description": "Passed to the rendering engine. Unknown names are rejected (the job fails with invalid_input). PDF-only options apply with `output=pdf`; screenshot-only options apply with `png` or `jpeg`.",
        "properties": {
          "base_url": {
            "type": "string",
            "maxLength": 2048,
            "description": "With `html`: resolves relative URLs (html_to_pdf and screenshot)."
          },
          "wait_until": {
            "type": "string",
            "enum": [
              "load",
              "domcontentloaded",
              "networkidle",
              "commit"
            ],
            "default": "load"
          },
          "wait_for_selector": {
            "type": "string",
            "maxLength": 200
          },
          "delay_ms": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "default": 0
          },
          "user_agent": {
            "type": "string",
            "maxLength": 300
          },
          "headers": {
            "type": "object",
            "maxProperties": 20,
            "additionalProperties": {
              "type": "string",
              "maxLength": 1000
            },
            "description": "Up to 20 request headers."
          },
          "javascript": {
            "type": "boolean",
            "default": true
          },
          "color_scheme": {
            "type": "string",
            "enum": [
              "light",
              "dark"
            ]
          },
          "viewport": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "width": {
                "type": "integer",
                "minimum": 100,
                "maximum": 4000,
                "default": 1280
              },
              "height": {
                "type": "integer",
                "minimum": 100,
                "maximum": 4000,
                "default": 800
              }
            }
          },
          "format": {
            "type": "string",
            "enum": [
              "Letter",
              "Legal",
              "Tabloid",
              "Ledger",
              "A0",
              "A1",
              "A2",
              "A3",
              "A4",
              "A5",
              "A6"
            ],
            "default": "A4",
            "description": "PDF paper size."
          },
          "width": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?(px|in|cm|mm)$",
            "description": "PDF custom page width, e.g. 210mm."
          },
          "height": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?(px|in|cm|mm)$",
            "description": "PDF custom page height."
          },
          "landscape": {
            "type": "boolean",
            "default": false
          },
          "margin": {
            "type": "object",
            "additionalProperties": false,
            "description": "Per-side margins; default 10 mm on all sides.",
            "properties": {
              "top": {
                "type": "string"
              },
              "right": {
                "type": "string"
              },
              "bottom": {
                "type": "string"
              },
              "left": {
                "type": "string"
              }
            }
          },
          "print_background": {
            "type": "boolean",
            "default": true
          },
          "scale": {
            "type": "number",
            "minimum": 0.1,
            "maximum": 2,
            "default": 1
          },
          "page_ranges": {
            "type": "string",
            "pattern": "^[\\d,\\s-]{1,100}$",
            "description": "For example 1-3,5."
          },
          "display_header_footer": {
            "type": "boolean",
            "default": false
          },
          "header_template": {
            "type": "string",
            "maxLength": 65536
          },
          "footer_template": {
            "type": "string",
            "maxLength": 65536,
            "description": "Page numbers use the classes pageNumber and totalPages."
          },
          "prefer_css_page_size": {
            "type": "boolean",
            "default": false
          },
          "tagged": {
            "type": "boolean",
            "default": false
          },
          "outline": {
            "type": "boolean",
            "default": false
          },
          "media": {
            "type": "string",
            "enum": [
              "print",
              "screen"
            ],
            "description": "Default print for PDF, screen for screenshots."
          },
          "quality": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "JPEG quality (screenshots)."
          },
          "full_page": {
            "type": "boolean",
            "default": false,
            "description": "Screenshot the whole page; output height capped at 16384 px. Costs more for tall pages."
          },
          "omit_background": {
            "type": "boolean",
            "default": false,
            "description": "Transparent PNG background where the page paints none."
          },
          "device_scale_factor": {
            "type": "number",
            "minimum": 1,
            "maximum": 3,
            "default": 1
          },
          "clip": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "x",
              "y",
              "width",
              "height"
            ],
            "properties": {
              "x": {
                "type": "number",
                "minimum": 0
              },
              "y": {
                "type": "number",
                "minimum": 0
              },
              "width": {
                "type": "number",
                "minimum": 1,
                "maximum": 8000
              },
              "height": {
                "type": "number",
                "minimum": 1,
                "maximum": 16384
              }
            }
          }
        },
        "additionalProperties": false
      },
      "JobAccepted": {
        "type": "object",
        "required": [
          "job_id",
          "status",
          "credits_reserved"
        ],
        "properties": {
          "job_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued"
            ]
          },
          "credits_reserved": {
            "type": "integer",
            "description": "Credits reserved at submit; settled on the real cost when the job ends."
          }
        }
      },
      "Job": {
        "type": "object",
        "required": [
          "job_id",
          "op",
          "status"
        ],
        "properties": {
          "job_id": {
            "type": "string",
            "format": "uuid"
          },
          "op": {
            "type": "string",
            "description": "The engine operation the request was mapped to, for example html_to_pdf, url_to_pdf, url_to_html, screenshot, image_to_svg, image_convert, image_resize or image_compress."
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed",
              "timeout"
            ]
          },
          "result": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Op-specific result data once the job ended, for example pages, bytes, width, height, output format fields. Image ops add fields such as input_format, output_format, has_alpha, animated and (compress) saved_percent, target_reached."
          },
          "result_url": {
            "type": [
              "string",
              "null"
            ],
            "description": "Internal storage key of the result."
          },
          "error": {
            "type": [
              "string",
              "null"
            ],
            "description": "Failure text beginning with the error class, such as invalid_input, ssrf_blocked, navigation_failed, output_limit, memory_limit or timeout."
          },
          "error_kind": {
            "type": [
              "string",
              "null"
            ],
            "description": "Error class prefix of `error`."
          },
          "error_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "For invalid_input, the specific code."
          },
          "error_status": {
            "type": [
              "integer",
              "null"
            ],
            "description": "invalid_input is 422, timeout is 504, others 500."
          },
          "download_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Signed attachment link (10 minutes by default); null until the job succeeded or after expiry."
          },
          "preview_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Signed inline link for previews, where applicable."
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the result is deleted: 1 day Free, 7 days Starter and Pro, 30 days Business."
          },
          "result_expired": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "started_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "finished_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "duration_ms": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "period": {
            "type": "string",
            "description": "Current credit period key."
          },
          "period_start": {
            "type": "string",
            "format": "date-time"
          },
          "period_end": {
            "type": "string",
            "format": "date-time"
          },
          "period_kind": {
            "type": "string"
          },
          "plan": {
            "type": "string",
            "description": "For example free, starter, pro or business."
          },
          "credits": {
            "type": "object",
            "properties": {
              "plan": {
                "type": "integer",
                "description": "Plan credits left."
              },
              "topup": {
                "type": "integer",
                "description": "Top-up credits left (they do not expire)."
              },
              "total": {
                "type": "integer"
              },
              "period": {
                "type": "string"
              },
              "monthly_allowance": {
                "type": "integer"
              },
              "plan_used": {
                "type": "integer"
              }
            }
          },
          "recent_debits": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "job_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "op": {
                  "type": "string"
                },
                "status": {
                  "type": "string"
                },
                "credits": {
                  "type": "integer"
                },
                "settled": {
                  "type": "boolean"
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "JobRequest": {
        "type": "object",
        "required": [
          "op"
        ],
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "html_to_pdf",
              "url_to_pdf",
              "url_to_html",
              "screenshot",
              "chart_render"
            ]
          },
          "params": {
            "type": "object",
            "additionalProperties": true,
            "description": "Settings of the op: the render options plus `html` or `url`, or for `chart_render` the chart spec."
          },
          "timeout_sec": {
            "type": "integer",
            "minimum": 1,
            "maximum": 300,
            "default": 30
          }
        }
      },
      "PdfJobRequest": {
        "type": "object",
        "required": [
          "op",
          "files"
        ],
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "pdf_merge",
              "pdf_split",
              "pdf_extract",
              "pdf_rotate",
              "pdf_delete",
              "pdf_to_image",
              "image_to_pdf",
              "pdf_to_text",
              "pdf_reorder",
              "pdf_page_numbers",
              "pdf_watermark_text",
              "pdf_protect",
              "pdf_crop",
              "pdf_extract_images",
              "pdf_unlock",
              "pdf_flatten",
              "pdf_resize",
              "ebook_to_pdf",
              "office_to_pdf",
              "image_combine"
            ]
          },
          "params": {
            "type": "object",
            "additionalProperties": true
          },
          "files": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "`upload_id` values from `POST /v1/uploads`, each used once. For `pdf_merge`, `image_to_pdf` and `image_combine` the order is the result order."
          },
          "timeout_sec": {
            "type": "integer",
            "minimum": 1,
            "maximum": 60
          }
        }
      },
      "Upload": {
        "type": "object",
        "required": [
          "upload_id",
          "kind",
          "bytes",
          "expires_in_sec"
        ],
        "properties": {
          "upload_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "description": "The detected type, for example pdf, png or jpeg."
          },
          "bytes": {
            "type": "integer"
          },
          "expires_in_sec": {
            "type": "integer"
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "ok",
          "db",
          "valkey"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "db": {
            "type": "string",
            "enum": [
              "ok",
              "fail"
            ]
          },
          "valkey": {
            "type": "string",
            "enum": [
              "ok",
              "fail"
            ]
          }
        }
      }
    }
  }
}
