{
  "openapi": "3.1.0",
  "info": {
    "title": "Kerf API",
    "version": "1.0.0",
    "summary": "True-shape 2D nesting and parametric flat patterns for laser, plasma and CNC cutting.",
    "description": "Send parts (DXF, SVG, CSV cut list, polygon or rectangle), get back the layout, a nested DXF/SVG and fabrication stats. Or generate flat patterns (pipe jackets, boxes, segmented elbows, reducers) for 1 credit and nest them. Units: millimetres, degrees, y up. Free tier: 100 credits a month; a nest costs max(1, ceil(instances / 10)) credits, ×2 for quality best; failures are refunded and identical requests are free. Docs: https://kerf.cerana.tech/en/docs/ . An MCP server with the same keys and credits is at https://kerf.cerana.tech/mcp .",
    "contact": {
      "name": "Cerana",
      "email": "cerana.mail@gmail.com",
      "url": "https://kerf.cerana.tech"
    },
    "termsOfService": "https://kerf.cerana.tech/en/terms/"
  },
  "servers": [
    {
      "url": "https://kerf.cerana.tech"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "nesting"
    },
    {
      "name": "jobs"
    },
    {
      "name": "results"
    },
    {
      "name": "flat-patterns"
    },
    {
      "name": "account"
    }
  ],
  "paths": {
    "/v1/nest": {
      "post": {
        "tags": [
          "nesting"
        ],
        "operationId": "nest",
        "summary": "Nest parts (synchronous)",
        "description": "Runs the nest and answers when it is done (free tier: up to ~8 s of compute). JSON or multipart.",
        "parameters": [
          {
            "name": "inline",
            "in": "query",
            "required": false,
            "description": "Comma list of result files to include in the response: svg, dxf.",
            "schema": {
              "type": "string",
              "example": "svg,dxf"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NestRequest"
              },
              "example": {
                "parts": [
                  {
                    "id": "plate",
                    "quantity": 8,
                    "polygon": [
                      [
                        0,
                        0
                      ],
                      [
                        120,
                        0
                      ],
                      [
                        120,
                        80
                      ],
                      [
                        0,
                        80
                      ]
                    ]
                  }
                ],
                "config": {
                  "sheetWidth": 600,
                  "sheetHeight": 400,
                  "spacing": 2
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/MultipartNestRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Nest result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestResponse"
                },
                "example": {
                  "id": "nst_OF7Qo4Y4zfuO3xuIrACt",
                  "cached": false,
                  "creditsCharged": 1,
                  "creditsRemaining": 99,
                  "quality": "balanced",
                  "stats": {
                    "placed": 8,
                    "total": 8,
                    "sheetsUsed": 1,
                    "utilization": 0.32,
                    "stripUtilization": 0.7773,
                    "usedWidth": 247,
                    "generations": 201,
                    "stopReason": "stale"
                  },
                  "placements": [
                    {
                      "partId": "plate",
                      "instance": 0,
                      "sheet": 0,
                      "rotation": 0,
                      "x": 5,
                      "y": 5
                    },
                    {
                      "partId": "plate",
                      "instance": 1,
                      "sheet": 0,
                      "rotation": 0,
                      "x": 5,
                      "y": 87
                    }
                  ],
                  "sheets": [
                    {
                      "index": 0,
                      "stock": 0,
                      "width": 600,
                      "height": 400,
                      "usedLength": 252,
                      "placed": 8
                    }
                  ],
                  "stocks": [
                    {
                      "index": 0,
                      "width": 600,
                      "height": 400,
                      "quantity": null,
                      "sheetsUsed": 1
                    }
                  ],
                  "fabrication": {
                    "cutLength": 3200,
                    "pierces": 8,
                    "partArea": 76800,
                    "sheetArea": 240000,
                    "materialUsedArea": 100800,
                    "utilization": 0.32,
                    "materialSaved": {
                      "method": "bbox-columns",
                      "baselineSheets": 1,
                      "baselineArea": 100800,
                      "savedArea": 0,
                      "savedPercent": 0
                    },
                    "perPart": [
                      {
                        "partId": "plate",
                        "quantity": 8,
                        "placed": 8,
                        "width": 120,
                        "height": 80,
                        "area": 9600,
                        "cutLength": 400,
                        "pierces": 1
                      }
                    ]
                  },
                  "warnings": [],
                  "sheetWidth": 600,
                  "sheetHeight": 400,
                  "results": {
                    "dxf": "https://kerf.cerana.tech/v1/nests/nst_OF7Qo4Y4zfuO3xuIrACt/dxf",
                    "svg": "https://kerf.cerana.tech/v1/nests/nst_OF7Qo4Y4zfuO3xuIrACt/svg",
                    "json": "https://kerf.cerana.tech/v1/nests/nst_OF7Qo4Y4zfuO3xuIrACt/json"
                  },
                  "durationMs": 556
                }
              }
            }
          },
          "400": {
            "description": "invalid_input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_input",
                  "message": "parts[0] (\"x\"): needs exactly one of `dxf` (base64), `svg`, `polygon` or `rect`"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits or limit_exceeded (+ waitlist)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "limit_exceeded",
                  "message": "free tier allows at most 100 part instances per nest (got 101)",
                  "waitlist": "https://kerf.cerana.tech/waitlist/?feature=large-nest"
                }
              }
            }
          },
          "413": {
            "description": "too_large (body over 5 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "unsupported_format: DWG / PDF / AI (+ waitlist)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unsupported_format",
                  "message": "part.dwg: DWG is not supported yet. Convert it to DXF or SVG, or join the waitlist for more input formats.",
                  "waitlist": "https://kerf.cerana.tech/waitlist/?feature=more-formats"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: 30 requests per minute per key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "engine_error (credits refunded, `creditsRefunded`) or internal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/jobs": {
      "post": {
        "tags": [
          "jobs"
        ],
        "operationId": "createJob",
        "summary": "Nest parts asynchronously",
        "description": "Same body as /v1/nest plus optional `webhookUrl` (https). Credits are debited at submit and refunded on failure. Webhook: POST with `Kerf-Event: nest.completed | nest.failed` and `Kerf-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, t + \".\" + body)>`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JobRequest"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/MultipartNestRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Queued (or done from cache)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobAccepted"
                },
                "example": {
                  "id": "nst_jhzSQ5NW4Yr6VnbwTFpp",
                  "status": "queued",
                  "creditsCharged": 2,
                  "creditsRemaining": 84
                }
              }
            }
          },
          "400": {
            "description": "invalid_input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_input",
                  "message": "parts[0] (\"x\"): needs exactly one of `dxf` (base64), `svg`, `polygon` or `rect`"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits or limit_exceeded (+ waitlist)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "limit_exceeded",
                  "message": "free tier allows at most 100 part instances per nest (got 101)",
                  "waitlist": "https://kerf.cerana.tech/waitlist/?feature=large-nest"
                }
              }
            }
          },
          "413": {
            "description": "too_large (body over 5 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "unsupported_format: DWG / PDF / AI (+ waitlist)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unsupported_format",
                  "message": "part.dwg: DWG is not supported yet. Convert it to DXF or SVG, or join the waitlist for more input formats.",
                  "waitlist": "https://kerf.cerana.tech/waitlist/?feature=more-formats"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: 30 requests per minute per key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "engine_error (credits refunded, `creditsRefunded`) or internal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "unavailable: queue send failed, credits refunded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/jobs/{id}": {
      "get": {
        "tags": [
          "jobs"
        ],
        "operationId": "getJob",
        "summary": "Job status (and result when done)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^nst_"
            },
            "example": "nst_OF7Qo4Y4zfuO3xuIrACt"
          }
        ],
        "responses": {
          "200": {
            "description": "Job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                },
                "example": {
                  "id": "nst_46fYR5xIQtFoLxxFUOZU",
                  "status": "done",
                  "mode": "async",
                  "source": "api",
                  "cached": false,
                  "instances": 5,
                  "creditsCharged": 1,
                  "quality": "fast",
                  "summary": "plate ×5",
                  "createdAt": "2026-12-02T08:03:43.336Z",
                  "startedAt": "2026-12-02T08:03:43.349Z",
                  "finishedAt": "2026-12-02T08:03:43.601Z",
                  "durationMs": 252,
                  "webhook": null,
                  "stats": {
                    "placed": 5,
                    "total": 5,
                    "sheetsUsed": 1,
                    "utilization": 0.125,
                    "stripUtilization": 0.7143,
                    "usedWidth": 105,
                    "generations": 201,
                    "stopReason": "stale"
                  },
                  "results": {
                    "dxf": "https://kerf.cerana.tech/v1/nests/nst_46fYR5xIQtFoLxxFUOZU/dxf",
                    "svg": "https://kerf.cerana.tech/v1/nests/nst_46fYR5xIQtFoLxxFUOZU/svg",
                    "json": "https://kerf.cerana.tech/v1/nests/nst_46fYR5xIQtFoLxxFUOZU/json"
                  }
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/nests/{id}": {
      "get": {
        "tags": [
          "results"
        ],
        "operationId": "getNest",
        "summary": "Nest result JSON with metadata",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^nst_"
            },
            "example": "nst_OF7Qo4Y4zfuO3xuIrACt"
          }
        ],
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestMeta"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "404": {
            "description": "not_found or not_ready (retry in a second)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/nests/{id}/json": {
      "get": {
        "tags": [
          "results"
        ],
        "operationId": "getNestJson",
        "summary": "Raw result JSON",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^nst_"
            },
            "example": "nst_OF7Qo4Y4zfuO3xuIrACt"
          }
        ],
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "404": {
            "description": "not_found / not_ready",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/nests/{id}/dxf": {
      "get": {
        "tags": [
          "results"
        ],
        "operationId": "getNestDxf",
        "summary": "Nested DXF (sheets side by side along +X; layers SHEET and CUT)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^nst_"
            },
            "example": "nst_OF7Qo4Y4zfuO3xuIrACt"
          }
        ],
        "responses": {
          "200": {
            "description": "DXF (AC1015)",
            "content": {
              "application/dxf": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "404": {
            "description": "not_found / not_ready",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/nests/{id}/svg": {
      "get": {
        "tags": [
          "results"
        ],
        "operationId": "getNestSvg",
        "summary": "SVG preview of all sheets",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^nst_"
            },
            "example": "nst_OF7Qo4Y4zfuO3xuIrACt"
          }
        ],
        "responses": {
          "200": {
            "description": "SVG",
            "content": {
              "image/svg+xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "404": {
            "description": "not_found / not_ready",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/flat-patterns": {
      "post": {
        "tags": [
          "flat-patterns"
        ],
        "operationId": "flatPattern",
        "summary": "Generate a flat pattern (pipe jacket, box, segmented elbow, reducer)",
        "description": "Develops a sheet-metal fitting into flat pieces: DXF (layers CUT, BEND, MARK; true ARC entities for the concentric reducer), SVG preview, per-piece numbers and `parts` ready for /v1/nest. 1 credit per request regardless of quantity. With `nest`, the parts are also nested in the same request (normal nest credits on top; on any nest error the flat-pattern credit is refunded too).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FlatPatternRequest"
              },
              "example": {
                "kind": "pipe-jacket",
                "params": {
                  "pipeOD": 168.3,
                  "insulationThickness": 50,
                  "length": 1000
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Flat pattern",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FlatPatternResponse"
                },
                "example": {
                  "id": "fpt_PxYivwQVsvTBE1PJ2DHx",
                  "kind": "pipe-jacket",
                  "quantity": 1,
                  "effective": {
                    "kind": "pipe-jacket",
                    "pipeOD": 168.3,
                    "insulationThickness": 50,
                    "jacketDiameter": null,
                    "materialThickness": 0.5,
                    "diameterBasis": "mean",
                    "insulatedDiameter": 268.3,
                    "effectiveDiameter": 268.8,
                    "length": 1000,
                    "overlap": 30,
                    "seamAllowance": 0,
                    "markLines": false,
                    "curveTolerance": 0.1,
                    "circumference": 844.46,
                    "developedWidth": 874.46,
                    "developedHeight": 1000
                  },
                  "pieces": [
                    {
                      "name": "pipe-jacket",
                      "quantity": 1,
                      "width": 874.46,
                      "height": 1000,
                      "area": 874460.105,
                      "cutLength": 3748.92,
                      "pierces": 1,
                      "bendLines": [],
                      "markLines": [],
                      "polygon": [
                        [
                          0,
                          0
                        ],
                        [
                          874.46,
                          0
                        ],
                        [
                          874.46,
                          1000
                        ],
                        [
                          0,
                          1000
                        ]
                      ],
                      "holes": []
                    }
                  ],
                  "totals": {
                    "pieces": 1,
                    "area": 874460.105,
                    "cutLength": 3748.92,
                    "pierces": 1
                  },
                  "parts": [
                    {
                      "id": "pipe-jacket",
                      "quantity": 1,
                      "polygon": [
                        [
                          0,
                          0
                        ],
                        [
                          874.46,
                          0
                        ],
                        [
                          874.46,
                          1000
                        ],
                        [
                          0,
                          1000
                        ]
                      ]
                    }
                  ],
                  "warnings": [],
                  "creditsCharged": 1,
                  "creditsRemaining": 99,
                  "results": {
                    "dxf": "https://kerf.cerana.tech/v1/flat-patterns/fpt_PxYivwQVsvTBE1PJ2DHx/dxf",
                    "svg": "https://kerf.cerana.tech/v1/flat-patterns/fpt_PxYivwQVsvTBE1PJ2DHx/svg",
                    "json": "https://kerf.cerana.tech/v1/flat-patterns/fpt_PxYivwQVsvTBE1PJ2DHx/json"
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_input",
                  "message": "parts[0] (\"x\"): needs exactly one of `dxf` (base64), `svg`, `polygon` or `rect`"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits or limit_exceeded (+ waitlist)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "limit_exceeded",
                  "message": "free tier allows at most 100 part instances per nest (got 101)",
                  "waitlist": "https://kerf.cerana.tech/waitlist/?feature=large-nest"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: 30 requests per minute per key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/flat-patterns/{id}/dxf": {
      "get": {
        "tags": [
          "flat-patterns"
        ],
        "operationId": "getFlatPatternDxf",
        "summary": "Flat-pattern DXF (pieces side by side, 10 mm apart; $INSUNITS = mm)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^fpt_"
            },
            "example": "fpt_PxYivwQVsvTBE1PJ2DHx"
          }
        ],
        "responses": {
          "200": {
            "description": "DXF (AC1015)",
            "content": {
              "application/dxf": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/flat-patterns/{id}/svg": {
      "get": {
        "tags": [
          "flat-patterns"
        ],
        "operationId": "getFlatPatternSvg",
        "summary": "SVG preview with dimensions",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^fpt_"
            },
            "example": "fpt_PxYivwQVsvTBE1PJ2DHx"
          }
        ],
        "responses": {
          "200": {
            "description": "SVG",
            "content": {
              "image/svg+xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/flat-patterns/{id}/json": {
      "get": {
        "tags": [
          "flat-patterns"
        ],
        "operationId": "getFlatPatternJson",
        "summary": "The full response JSON",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^fpt_"
            },
            "example": "fpt_PxYivwQVsvTBE1PJ2DHx"
          }
        ],
        "responses": {
          "200": {
            "description": "Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FlatPatternResponse"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "tags": [
          "account"
        ],
        "operationId": "me",
        "summary": "Account email and credits",
        "responses": {
          "200": {
            "description": "Account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                },
                "example": {
                  "email": "you@example.com",
                  "credits": 100
                }
              }
            }
          },
          "401": {
            "description": "unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized",
                  "message": "invalid or revoked API key"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "kf_live_ + 32 base62 characters",
        "description": "Create keys in the dashboard: https://kerf.cerana.tech/app/"
      }
    },
    "schemas": {
      "Point": {
        "description": "A vertex in mm: `[x, y]` or `{x, y}`.",
        "oneOf": [
          {
            "type": "array",
            "items": {
              "type": "number"
            },
            "minItems": 2,
            "maxItems": 2
          },
          {
            "type": "object",
            "properties": {
              "x": {
                "type": "number"
              },
              "y": {
                "type": "number"
              }
            },
            "required": [
              "x",
              "y"
            ],
            "additionalProperties": false
          }
        ]
      },
      "Ring": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Point"
        },
        "minItems": 3,
        "maxItems": 5000,
        "description": "Closed ring (closing vertex optional), either winding."
      },
      "Part": {
        "type": "object",
        "description": "One part type. Exactly one geometry field: `dxf`, `svg`, `polygon` or `rect`.",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "pattern": "^[\\p{L}\\p{N}_.\\- ()\\[\\]#+]+$",
            "description": "Unique part name."
          },
          "quantity": {
            "type": "integer",
            "description": "Instances to nest.",
            "minimum": 1,
            "maximum": 100
          },
          "rotate": {
            "type": "boolean",
            "description": "`false` locks this part at 0°; other parts still follow config.rotationMode. A locked part that only fits rotated is reported as unplaced. Default true."
          },
          "dxf": {
            "type": "string",
            "contentEncoding": "base64",
            "description": "DXF file, base64. Closed contours become the part, inner ones holes; arcs are written back as ARC entities."
          },
          "svg": {
            "type": "string",
            "description": "SVG document as text (or base64). Curves are flattened at 0.1 mm chord error."
          },
          "units": {
            "type": "string",
            "enum": [
              "mm",
              "cm",
              "in",
              "pt",
              "px"
            ],
            "description": "SVG: size of one user unit (overrides width/height). DXF: units to assume when the drawing declares none ($INSUNITS missing or 0): mm, cm or in. A declared $INSUNITS always wins."
          },
          "polygon": {
            "$ref": "#/components/schemas/Ring"
          },
          "holes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Ring"
            },
            "maxItems": 500
          },
          "rect": {
            "type": "array",
            "items": {
              "type": "number",
              "minimum": 0.1,
              "maximum": 20000
            },
            "minItems": 2,
            "maxItems": 2,
            "description": "[width, height] in mm."
          },
          "dwg": {
            "description": "Not supported: answered with 415 unsupported_format."
          },
          "pdf": {
            "description": "Not supported: answered with 415 unsupported_format."
          },
          "ai": {
            "description": "Not supported: answered with 415 unsupported_format."
          }
        },
        "required": [
          "id",
          "quantity"
        ],
        "additionalProperties": false
      },
      "Stock": {
        "type": "object",
        "properties": {
          "width": {
            "type": "number",
            "description": "mm",
            "minimum": 10,
            "maximum": 20000
          },
          "height": {
            "type": "number",
            "description": "mm",
            "minimum": 10,
            "maximum": 20000
          },
          "quantity": {
            "type": "integer",
            "description": "Sheets available; omitted = unlimited.",
            "minimum": 1,
            "maximum": 1000
          }
        },
        "required": [
          "width",
          "height"
        ],
        "additionalProperties": false
      },
      "Tabs": {
        "type": "object",
        "description": "Micro-joints on outer contours.",
        "properties": {
          "enabled": {
            "type": "boolean",
            "default": false
          },
          "width": {
            "type": "number",
            "description": "Joint width, mm.",
            "minimum": 0.05,
            "maximum": 10,
            "default": 0.3
          },
          "maxSpacing": {
            "type": "number",
            "description": "Max distance between joints, mm.",
            "minimum": 10,
            "maximum": 5000,
            "default": 250
          },
          "minPerContour": {
            "type": "integer",
            "description": "",
            "minimum": 1,
            "maximum": 20,
            "default": 2
          },
          "cornerClearance": {
            "type": "number",
            "description": "mm",
            "minimum": 0,
            "maximum": 100,
            "default": 3
          },
          "minHoleSize": {
            "type": "number",
            "description": "Holes smaller than this (mm) get no joints.",
            "minimum": 0,
            "maximum": 5000,
            "default": 40
          }
        },
        "additionalProperties": false
      },
      "Config": {
        "type": "object",
        "properties": {
          "sheetWidth": {
            "type": "number",
            "description": "Sheet length along x, mm.",
            "minimum": 10,
            "maximum": 20000,
            "default": 1829
          },
          "sheetHeight": {
            "type": "number",
            "description": "Sheet height along y, mm.",
            "minimum": 10,
            "maximum": 20000,
            "default": 914
          },
          "sheets": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Stock"
            },
            "minItems": 1,
            "maxItems": 5,
            "description": "Stock sizes in priority order; overrides sheetWidth/sheetHeight."
          },
          "autoWidth": {
            "type": "boolean",
            "default": false,
            "description": "Coil/strip mode."
          },
          "spacing": {
            "type": "number",
            "description": "Gap between parts, mm.",
            "minimum": 0,
            "maximum": 100,
            "default": 2
          },
          "margin": {
            "type": "number",
            "description": "Gap to the sheet edge, mm.",
            "minimum": 0,
            "maximum": 1000,
            "default": 5
          },
          "rotationMode": {
            "type": "string",
            "enum": [
              "orthogonal",
              "free"
            ],
            "default": "orthogonal"
          },
          "rotationStepDeg": {
            "type": "number",
            "description": "Degrees; clamped to 15–90.",
            "minimum": 1,
            "maximum": 90,
            "default": 15
          },
          "curveTolerance": {
            "type": "number",
            "description": "Max chord error (mm) when linearising curves; clamped to 0.05–5.",
            "minimum": 0.01,
            "maximum": 10,
            "default": 0.25
          },
          "quality": {
            "type": "string",
            "enum": [
              "fast",
              "balanced",
              "best"
            ],
            "default": "balanced",
            "description": "2 / 4 / 8 s budget; best costs 2× credits."
          },
          "timeLimitMs": {
            "type": "integer",
            "description": "Overrides quality (reported as custom); clamped to 500–8000.",
            "minimum": 0,
            "maximum": 600000
          },
          "staleGenerations": {
            "type": "integer",
            "description": "Clamped to 10–600.",
            "minimum": 1,
            "maximum": 100000,
            "default": 200
          },
          "population": {
            "type": "integer",
            "description": "Clamped to 4–30.",
            "minimum": 2,
            "maximum": 200,
            "default": 15
          },
          "mutationRate": {
            "type": "number",
            "description": "",
            "minimum": 0,
            "maximum": 1,
            "default": 0.1
          },
          "seed": {
            "type": "integer",
            "description": "Same input + seed = same layout.",
            "minimum": 0,
            "maximum": 4294967295,
            "default": 1
          },
          "tabs": {
            "$ref": "#/components/schemas/Tabs"
          }
        },
        "additionalProperties": false
      },
      "NestRequest": {
        "type": "object",
        "properties": {
          "parts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Part"
            },
            "minItems": 1,
            "maxItems": 30
          },
          "config": {
            "$ref": "#/components/schemas/Config"
          }
        },
        "required": [
          "parts"
        ],
        "additionalProperties": false
      },
      "JobRequest": {
        "type": "object",
        "properties": {
          "parts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Part"
            },
            "minItems": 1,
            "maxItems": 30
          },
          "config": {
            "$ref": "#/components/schemas/Config"
          },
          "webhookUrl": {
            "type": "string",
            "format": "uri",
            "maxLength": 2000,
            "description": "https:// URL notified with a signed POST when the job finishes."
          }
        },
        "required": [
          "parts"
        ],
        "additionalProperties": false
      },
      "MultipartNestRequest": {
        "type": "object",
        "description": "`file` (repeatable: DXF, SVG or CSV cut list), plus per-file fields keyed by the uploaded file name.",
        "properties": {
          "file": {
            "type": "array",
            "items": {
              "type": "string",
              "contentMediaType": "application/octet-stream"
            }
          },
          "config": {
            "type": "string",
            "description": "Config as a JSON string.",
            "contentMediaType": "application/json"
          },
          "parts": {
            "type": "string",
            "description": "Extra parts as a JSON array string (same shape as `parts` in JSON)."
          },
          "units": {
            "type": "string",
            "enum": [
              "mm",
              "cm",
              "in",
              "pt",
              "px",
              "auto"
            ],
            "description": "Units for every file; `units[<filename>]` for one file."
          },
          "webhookUrl": {
            "type": "string",
            "description": "POST /v1/jobs only."
          }
        },
        "patternProperties": {
          "^quantity\\[.+\\]$": {
            "type": "string",
            "pattern": "^\\d+$",
            "description": "Quantity for that file (default 1)."
          },
          "^rotate\\[.+\\]$": {
            "type": "string",
            "enum": [
              "true",
              "false",
              "0",
              "1",
              "no",
              "yes"
            ]
          },
          "^units\\[.+\\]$": {
            "type": "string",
            "enum": [
              "mm",
              "cm",
              "in",
              "pt",
              "px",
              "auto"
            ]
          }
        }
      },
      "Stats": {
        "type": "object",
        "properties": {
          "placed": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "sheetsUsed": {
            "type": "integer"
          },
          "utilization": {
            "type": "number",
            "description": "Net part area ÷ sheet area."
          },
          "stripUtilization": {
            "type": "number",
            "description": "Net part area ÷ area of the used length."
          },
          "usedWidth": {
            "type": "number",
            "description": "Length used on the last sheet, mm."
          },
          "generations": {
            "type": "integer"
          },
          "stopReason": {
            "type": "string",
            "description": "stale | time_limit | budget | empty"
          }
        },
        "required": [
          "placed",
          "total",
          "sheetsUsed",
          "utilization",
          "stripUtilization",
          "usedWidth",
          "generations",
          "stopReason"
        ]
      },
      "Placement": {
        "type": "object",
        "description": "Rotate the part's own coordinates by `rotation` degrees (counter-clockwise, about the origin), then translate by (x, y).",
        "properties": {
          "partId": {
            "type": "string"
          },
          "instance": {
            "type": "integer"
          },
          "sheet": {
            "type": "integer"
          },
          "rotation": {
            "type": "number"
          },
          "x": {
            "type": "number"
          },
          "y": {
            "type": "number"
          }
        },
        "required": [
          "partId",
          "instance",
          "sheet",
          "rotation",
          "x",
          "y"
        ]
      },
      "Sheet": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer"
          },
          "stock": {
            "type": "integer"
          },
          "width": {
            "type": "number"
          },
          "height": {
            "type": "number"
          },
          "usedLength": {
            "type": "number"
          },
          "placed": {
            "type": "integer"
          }
        },
        "required": [
          "index",
          "stock",
          "width",
          "height",
          "usedLength",
          "placed"
        ]
      },
      "StockUsage": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer"
          },
          "width": {
            "type": "number"
          },
          "height": {
            "type": "number"
          },
          "quantity": {
            "type": [
              "integer",
              "null"
            ]
          },
          "sheetsUsed": {
            "type": "integer"
          }
        },
        "required": [
          "index",
          "width",
          "height",
          "quantity",
          "sheetsUsed"
        ]
      },
      "PerPart": {
        "type": "object",
        "properties": {
          "partId": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "placed": {
            "type": "integer"
          },
          "width": {
            "type": "number"
          },
          "height": {
            "type": "number"
          },
          "area": {
            "type": "number",
            "description": "Net area of one piece, mm²."
          },
          "cutLength": {
            "type": [
              "number",
              "null"
            ],
            "description": "Per piece, mm; null when none was placed."
          },
          "pierces": {
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "required": [
          "partId",
          "quantity",
          "placed",
          "width",
          "height",
          "area",
          "cutLength",
          "pierces"
        ]
      },
      "Fabrication": {
        "type": "object",
        "properties": {
          "cutLength": {
            "type": "number",
            "description": "All placed contours, mm; true arc length for DXF arcs."
          },
          "pierces": {
            "type": "integer"
          },
          "partArea": {
            "type": "number",
            "description": "mm²"
          },
          "sheetArea": {
            "type": "number",
            "description": "mm²"
          },
          "materialUsedArea": {
            "type": "number",
            "description": "mm²"
          },
          "utilization": {
            "type": "number"
          },
          "materialSaved": {
            "type": "object",
            "properties": {
              "method": {
                "const": "bbox-columns"
              },
              "baselineSheets": {
                "type": "integer"
              },
              "baselineArea": {
                "type": "number"
              },
              "savedArea": {
                "type": "number"
              },
              "savedPercent": {
                "type": "number"
              }
            },
            "required": [
              "method",
              "baselineSheets",
              "baselineArea",
              "savedArea",
              "savedPercent"
            ]
          },
          "perPart": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PerPart"
            }
          }
        },
        "required": [
          "cutLength",
          "pierces",
          "partArea",
          "sheetArea",
          "materialUsedArea",
          "utilization",
          "materialSaved",
          "perPart"
        ]
      },
      "ResultUrls": {
        "type": "object",
        "description": "Owner-only downloads (same Authorization header), kept 30 days.",
        "properties": {
          "dxf": {
            "type": "string",
            "format": "uri"
          },
          "svg": {
            "type": "string",
            "format": "uri"
          },
          "json": {
            "type": "string",
            "format": "uri"
          }
        },
        "required": [
          "dxf",
          "svg",
          "json"
        ]
      },
      "NestResult": {
        "type": "object",
        "properties": {
          "quality": {
            "type": "string",
            "enum": [
              "fast",
              "balanced",
              "best",
              "custom"
            ]
          },
          "stats": {
            "$ref": "#/components/schemas/Stats"
          },
          "placements": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Placement"
            }
          },
          "sheets": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Sheet"
            }
          },
          "stocks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StockUsage"
            }
          },
          "fabrication": {
            "$ref": "#/components/schemas/Fabrication"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Unplaced parts, unitless or inch DXF drawings, skipped entities, ignored open chains, …"
          },
          "sheetWidth": {
            "type": "number"
          },
          "sheetHeight": {
            "type": "number"
          }
        },
        "required": [
          "quality",
          "stats",
          "placements",
          "sheets",
          "stocks",
          "fabrication",
          "warnings",
          "sheetWidth",
          "sheetHeight"
        ]
      },
      "NestResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/NestResult"
          }
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^nst_"
          },
          "cached": {
            "type": "boolean",
            "description": "true = served from cache, 0 credits."
          },
          "creditsCharged": {
            "type": "integer"
          },
          "creditsRemaining": {
            "type": "integer"
          },
          "results": {
            "$ref": "#/components/schemas/ResultUrls"
          },
          "durationMs": {
            "type": "integer"
          },
          "svg": {
            "type": "string",
            "description": "Only with ?inline=svg."
          },
          "dxf": {
            "type": "string",
            "contentEncoding": "base64",
            "description": "Only with ?inline=dxf."
          }
        },
        "required": [
          "id",
          "cached",
          "creditsCharged",
          "creditsRemaining",
          "results",
          "durationMs"
        ]
      },
      "NestMeta": {
        "allOf": [
          {
            "$ref": "#/components/schemas/NestResult"
          }
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "const": "done"
          },
          "cached": {
            "type": "boolean"
          },
          "instances": {
            "type": "integer"
          },
          "creditsCharged": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "results": {
            "$ref": "#/components/schemas/ResultUrls"
          }
        },
        "required": [
          "id",
          "status",
          "cached",
          "instances",
          "creditsCharged",
          "createdAt",
          "results"
        ]
      },
      "JobAccepted": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "done"
            ],
            "description": "done (+ cached: true, 0 credits) when the same input was computed before."
          },
          "cached": {
            "type": "boolean"
          },
          "creditsCharged": {
            "type": "integer"
          },
          "creditsRemaining": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "status",
          "creditsCharged",
          "creditsRemaining"
        ]
      },
      "Job": {
        "type": "object",
        "description": "When status is done, every NestResult field plus `results` is included as well.",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "done",
              "failed"
            ]
          },
          "mode": {
            "type": "string",
            "enum": [
              "sync",
              "async"
            ]
          },
          "source": {
            "type": "string",
            "enum": [
              "api",
              "playground"
            ]
          },
          "cached": {
            "type": "boolean"
          },
          "instances": {
            "type": "integer"
          },
          "creditsCharged": {
            "type": "integer"
          },
          "quality": {
            "type": [
              "string",
              "null"
            ]
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "startedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "finishedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "durationMs": {
            "type": [
              "integer",
              "null"
            ]
          },
          "webhook": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string"
                  },
                  "status": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "pending",
                      "delivered",
                      "failed",
                      null
                    ]
                  },
                  "attempts": {
                    "type": "integer"
                  }
                },
                "required": [
                  "url",
                  "status",
                  "attempts"
                ]
              }
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ],
            "description": "failed jobs only"
          },
          "creditsRefunded": {
            "type": "integer",
            "description": "failed jobs only"
          },
          "results": {
            "$ref": "#/components/schemas/ResultUrls"
          }
        },
        "required": [
          "id",
          "status",
          "mode",
          "source",
          "cached",
          "instances",
          "creditsCharged",
          "createdAt",
          "webhook"
        ]
      },
      "Me": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string"
          },
          "credits": {
            "type": "integer"
          }
        },
        "required": [
          "email",
          "credits"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "invalid_input",
              "unauthorized",
              "insufficient_credits",
              "limit_exceeded",
              "not_found",
              "not_ready",
              "too_large",
              "unsupported_format",
              "rate_limited",
              "engine_error",
              "internal",
              "unavailable"
            ]
          },
          "message": {
            "type": "string"
          },
          "waitlist": {
            "type": "string",
            "format": "uri",
            "description": "402 / 415: waitlist for the missing feature."
          },
          "creditsRequired": {
            "type": "integer",
            "description": "402 insufficient_credits"
          },
          "creditsRemaining": {
            "type": "integer",
            "description": "402 insufficient_credits"
          },
          "creditsRefunded": {
            "type": "integer",
            "description": "500 engine_error"
          },
          "id": {
            "type": "string",
            "description": "500 engine_error: the refunded job"
          }
        },
        "required": [
          "error",
          "message"
        ]
      },
      "PipeJacketParams": {
        "type": "object",
        "properties": {
          "pipeOD": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Bare pipe outside diameter, mm. Required unless jacketDiameter is given."
          },
          "insulationThickness": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "description": "Insulation thickness, mm. Insulated OD = pipeOD + 2 × this.",
            "default": 0
          },
          "jacketDiameter": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Inside diameter of the cladding, mm; overrides pipeOD + insulation."
          },
          "materialThickness": {
            "type": "number",
            "minimum": 0,
            "maximum": 20,
            "description": "Sheet thickness t, mm.",
            "default": 0.5
          },
          "diameterBasis": {
            "type": "string",
            "enum": [
              "inside",
              "mean",
              "outside"
            ],
            "default": "mean",
            "description": "Diameter the development uses: inside = insulated OD, mean = + t, outside = + 2t. Reported as effective.effectiveDiameter."
          },
          "overlap": {
            "type": "number",
            "minimum": 0,
            "maximum": 500,
            "description": "Overlap (搭接) added past the longitudinal seam on one side, cut parallel to the seam, mm.",
            "default": 30
          },
          "seamAllowance": {
            "type": "number",
            "minimum": 0,
            "maximum": 200,
            "description": "Added along the generatrix at both circumferential edges, mm.",
            "default": 0
          },
          "markLines": {
            "type": "boolean",
            "default": false,
            "description": "Draw reference lines on layer MARK (overlap boundary, gore centre line, tangent line)."
          },
          "curveTolerance": {
            "type": "number",
            "minimum": 0.01,
            "maximum": 5,
            "default": 0.1,
            "description": "Max chord error (mm) for sampled curves and for the polygons in `parts`."
          },
          "length": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 20000,
            "description": "Jacket length along the pipe, mm."
          }
        },
        "required": [
          "length"
        ],
        "additionalProperties": false
      },
      "BoxParams": {
        "type": "object",
        "properties": {
          "overlap": {
            "type": "number",
            "minimum": 0,
            "maximum": 500,
            "description": "Overlap (搭接) added past the longitudinal seam on one side, cut parallel to the seam, mm.",
            "default": 30
          },
          "seamAllowance": {
            "type": "number",
            "minimum": 0,
            "maximum": 200,
            "description": "Added along the generatrix at both circumferential edges, mm.",
            "default": 0
          },
          "markLines": {
            "type": "boolean",
            "default": false,
            "description": "Draw reference lines on layer MARK (overlap boundary, gore centre line, tangent line)."
          },
          "curveTolerance": {
            "type": "number",
            "minimum": 0.01,
            "maximum": 5,
            "default": 0.1,
            "description": "Max chord error (mm) for sampled curves and for the polygons in `parts`."
          },
          "width": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Face width, mm (laid out as given; no bend deduction)."
          },
          "height": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Face height, mm."
          },
          "length": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 20000,
            "description": "Sleeve length, mm."
          },
          "endCaps": {
            "type": "boolean",
            "default": false,
            "description": "Add 2 end caps (width × height + capFlange)."
          },
          "pipeHoleDiameter": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Hole in each end cap, mm (centred)."
          },
          "pipeHoleOffset": {
            "type": "object",
            "properties": {
              "x": {
                "type": "number"
              },
              "y": {
                "type": "number"
              }
            },
            "additionalProperties": false,
            "description": "Hole offset from the cap centre, mm."
          },
          "capFlange": {
            "type": "number",
            "minimum": 0,
            "maximum": 500,
            "description": "Flange added on every cap side, corners notched, mm.",
            "default": 0
          }
        },
        "required": [
          "width",
          "height",
          "length"
        ],
        "additionalProperties": false
      },
      "SegmentedElbowParams": {
        "type": "object",
        "properties": {
          "pipeOD": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Bare pipe outside diameter, mm. Required unless jacketDiameter is given."
          },
          "insulationThickness": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "description": "Insulation thickness, mm. Insulated OD = pipeOD + 2 × this.",
            "default": 0
          },
          "jacketDiameter": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Inside diameter of the cladding, mm; overrides pipeOD + insulation."
          },
          "materialThickness": {
            "type": "number",
            "minimum": 0,
            "maximum": 20,
            "description": "Sheet thickness t, mm.",
            "default": 0.5
          },
          "diameterBasis": {
            "type": "string",
            "enum": [
              "inside",
              "mean",
              "outside"
            ],
            "default": "mean",
            "description": "Diameter the development uses: inside = insulated OD, mean = + t, outside = + 2t. Reported as effective.effectiveDiameter."
          },
          "overlap": {
            "type": "number",
            "minimum": 0,
            "maximum": 500,
            "description": "Overlap (搭接) added past the longitudinal seam on one side, cut parallel to the seam, mm.",
            "default": 30
          },
          "seamAllowance": {
            "type": "number",
            "minimum": 0,
            "maximum": 200,
            "description": "Added along the generatrix at both circumferential edges, mm.",
            "default": 0
          },
          "markLines": {
            "type": "boolean",
            "default": false,
            "description": "Draw reference lines on layer MARK (overlap boundary, gore centre line, tangent line)."
          },
          "curveTolerance": {
            "type": "number",
            "minimum": 0.01,
            "maximum": 5,
            "default": 0.1,
            "description": "Max chord error (mm) for sampled curves and for the polygons in `parts`."
          },
          "bendRadius": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 50000,
            "description": "Centreline bend radius R, mm; must exceed the effective radius."
          },
          "angle": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 180,
            "description": "Total bend angle, degrees."
          },
          "segments": {
            "type": "integer",
            "minimum": 2,
            "maximum": 40,
            "description": "Pieces n: n − 2 middle gores + 2 half-gore end pieces; angle / (n − 1) ≤ 90°."
          },
          "tangentLength": {
            "type": "number",
            "minimum": 0,
            "maximum": 20000,
            "description": "Straight extension on each end piece, mm.",
            "default": 0
          }
        },
        "required": [
          "bendRadius",
          "angle",
          "segments"
        ],
        "additionalProperties": false
      },
      "ReducerParams": {
        "type": "object",
        "properties": {
          "overlap": {
            "type": "number",
            "minimum": 0,
            "maximum": 500,
            "description": "Overlap (搭接) added past the longitudinal seam on one side, cut parallel to the seam, mm.",
            "default": 30
          },
          "seamAllowance": {
            "type": "number",
            "minimum": 0,
            "maximum": 200,
            "description": "Added along the generatrix at both circumferential edges, mm.",
            "default": 0
          },
          "markLines": {
            "type": "boolean",
            "default": false,
            "description": "Draw reference lines on layer MARK (overlap boundary, gore centre line, tangent line)."
          },
          "curveTolerance": {
            "type": "number",
            "minimum": 0.01,
            "maximum": 5,
            "default": 0.1,
            "description": "Max chord error (mm) for sampled curves and for the polygons in `parts`."
          },
          "type": {
            "type": "string",
            "enum": [
              "concentric",
              "eccentric"
            ],
            "default": "concentric"
          },
          "largeDiameter": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Bare OD at the large end, mm."
          },
          "smallDiameter": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Bare OD at the small end, mm."
          },
          "insulationThickness": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "description": "Insulation at both ends, mm.",
            "default": 0
          },
          "largeInsulationThickness": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "description": "Overrides insulationThickness at the large end."
          },
          "smallInsulationThickness": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "description": "Overrides insulationThickness at the small end."
          },
          "largeJacketDiameter": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Cladding inside diameter at the large end; overrides OD + insulation."
          },
          "smallJacketDiameter": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000,
            "description": "Cladding inside diameter at the small end."
          },
          "materialThickness": {
            "type": "number",
            "minimum": 0,
            "maximum": 20,
            "description": "Sheet thickness t, mm.",
            "default": 0.5
          },
          "diameterBasis": {
            "type": "string",
            "enum": [
              "inside",
              "mean",
              "outside"
            ],
            "default": "mean",
            "description": "Diameter the development uses: inside = insulated OD, mean = + t, outside = + 2t. Reported as effective.effectiveDiameter."
          },
          "height": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 20000,
            "description": "Axial length, mm."
          },
          "divisions": {
            "type": "integer",
            "minimum": 12,
            "maximum": 720,
            "default": 48,
            "description": "Eccentric only: triangulation divisions."
          }
        },
        "required": [
          "height"
        ],
        "additionalProperties": false
      },
      "FlatPatternOutput": {
        "type": "object",
        "properties": {
          "dxf": {
            "type": "boolean",
            "default": true
          },
          "svg": {
            "type": "boolean",
            "default": true
          },
          "inline": {
            "type": "boolean",
            "default": false,
            "description": "Also return `svg` (text) and `dxf` (base64) in the response."
          }
        },
        "additionalProperties": false
      },
      "FlatPatternRequest": {
        "description": "`params` depends on `kind`. 1 credit per request, whatever the quantity; `nest` adds the normal nest credits.",
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "kind": {
                "const": "pipe-jacket"
              },
              "params": {
                "$ref": "#/components/schemas/PipeJacketParams"
              },
              "quantity": {
                "type": "integer",
                "description": "How many fittings; multiplies every piece.",
                "minimum": 1,
                "maximum": 100,
                "default": 1
              },
              "output": {
                "$ref": "#/components/schemas/FlatPatternOutput"
              },
              "nest": {
                "$ref": "#/components/schemas/Config",
                "description": "Optional: nest the generated parts (same object as /v1/nest config)."
              }
            },
            "required": [
              "kind",
              "params"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "const": "box"
              },
              "params": {
                "$ref": "#/components/schemas/BoxParams"
              },
              "quantity": {
                "type": "integer",
                "description": "How many fittings; multiplies every piece.",
                "minimum": 1,
                "maximum": 100,
                "default": 1
              },
              "output": {
                "$ref": "#/components/schemas/FlatPatternOutput"
              },
              "nest": {
                "$ref": "#/components/schemas/Config",
                "description": "Optional: nest the generated parts (same object as /v1/nest config)."
              }
            },
            "required": [
              "kind",
              "params"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "const": "segmented-elbow"
              },
              "params": {
                "$ref": "#/components/schemas/SegmentedElbowParams"
              },
              "quantity": {
                "type": "integer",
                "description": "How many fittings; multiplies every piece.",
                "minimum": 1,
                "maximum": 100,
                "default": 1
              },
              "output": {
                "$ref": "#/components/schemas/FlatPatternOutput"
              },
              "nest": {
                "$ref": "#/components/schemas/Config",
                "description": "Optional: nest the generated parts (same object as /v1/nest config)."
              }
            },
            "required": [
              "kind",
              "params"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "const": "reducer"
              },
              "params": {
                "$ref": "#/components/schemas/ReducerParams"
              },
              "quantity": {
                "type": "integer",
                "description": "How many fittings; multiplies every piece.",
                "minimum": 1,
                "maximum": 100,
                "default": 1
              },
              "output": {
                "$ref": "#/components/schemas/FlatPatternOutput"
              },
              "nest": {
                "$ref": "#/components/schemas/Config",
                "description": "Optional: nest the generated parts (same object as /v1/nest config)."
              }
            },
            "required": [
              "kind",
              "params"
            ],
            "additionalProperties": false
          }
        ]
      },
      "FlatSegment": {
        "type": "array",
        "items": {
          "type": "array",
          "items": {
            "type": "number"
          },
          "minItems": 2,
          "maxItems": 2
        },
        "minItems": 2,
        "maxItems": 2,
        "description": "[[x1, y1], [x2, y2]] in the piece frame, mm."
      },
      "FlatPiece": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "pipe-jacket | box-sleeve | box-cap | elbow-gore | elbow-end | reducer"
          },
          "quantity": {
            "type": "integer",
            "description": "Per piece × request quantity."
          },
          "width": {
            "type": "number",
            "description": "Bounding box, mm."
          },
          "height": {
            "type": "number",
            "description": "Bounding box, mm."
          },
          "area": {
            "type": "number",
            "description": "Net area of one piece, mm² (exact for arcs, holes subtracted)."
          },
          "cutLength": {
            "type": "number",
            "description": "Outline + holes of one piece, mm (true arc length)."
          },
          "pierces": {
            "type": "integer"
          },
          "bendLines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FlatSegment"
            },
            "description": "Fold lines (DXF layer BEND)."
          },
          "markLines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FlatSegment"
            },
            "description": "Reference lines (DXF layer MARK)."
          },
          "polygon": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "number"
              }
            },
            "description": "Outer ring, mm, counter-clockwise, bbox min at (0, 0); curves sampled at curveTolerance."
          },
          "holes": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              }
            }
          }
        },
        "required": [
          "name",
          "quantity",
          "width",
          "height",
          "area",
          "cutLength",
          "pierces",
          "bendLines",
          "markLines",
          "polygon",
          "holes"
        ]
      },
      "FlatTotals": {
        "type": "object",
        "properties": {
          "pieces": {
            "type": "integer"
          },
          "area": {
            "type": "number",
            "description": "mm²"
          },
          "cutLength": {
            "type": "number",
            "description": "mm"
          },
          "pierces": {
            "type": "integer"
          }
        },
        "required": [
          "pieces",
          "area",
          "cutLength",
          "pierces"
        ]
      },
      "FlatResultUrls": {
        "type": "object",
        "description": "Owner-only downloads (same Authorization header), kept 30 days; null when that output was switched off.",
        "properties": {
          "dxf": {
            "type": [
              "string",
              "null"
            ]
          },
          "svg": {
            "type": [
              "string",
              "null"
            ]
          },
          "json": {
            "type": "string"
          }
        },
        "required": [
          "dxf",
          "svg",
          "json"
        ]
      },
      "FlatPatternResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^fpt_"
          },
          "kind": {
            "type": "string",
            "enum": [
              "pipe-jacket",
              "box",
              "segmented-elbow",
              "reducer"
            ]
          },
          "quantity": {
            "type": "integer"
          },
          "effective": {
            "type": "object",
            "description": "Every resolved parameter incl. defaults, the insulated and effective diameters, and per kind: circumference (pipe-jacket, elbow), bendCount (box), jointAngle / throatLength / heelLength (elbow), cone {slantHeight, outerRadius, innerRadius, sweepDeg, apexHeight, apexInPattern} (concentric reducer), oblique {apexHeight, developedAngleDeg, largeEdgeLength, smallEdgeLength} (eccentric)."
          },
          "pieces": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FlatPiece"
            }
          },
          "totals": {
            "$ref": "#/components/schemas/FlatTotals"
          },
          "parts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Part"
            },
            "description": "Ready to POST to /v1/nest as `parts` (polygon + holes + quantity)."
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "creditsCharged": {
            "type": "integer",
            "description": "1, plus the nest credits when `nest` was given."
          },
          "creditsRemaining": {
            "type": "integer"
          },
          "results": {
            "$ref": "#/components/schemas/FlatResultUrls"
          },
          "nest": {
            "$ref": "#/components/schemas/NestResponse",
            "description": "Only when `nest` was given."
          },
          "svg": {
            "type": "string",
            "description": "output.inline only."
          },
          "dxf": {
            "type": "string",
            "contentEncoding": "base64",
            "description": "output.inline only."
          }
        },
        "required": [
          "id",
          "kind",
          "quantity",
          "effective",
          "pieces",
          "totals",
          "parts",
          "warnings",
          "creditsCharged",
          "creditsRemaining",
          "results"
        ]
      }
    }
  }
}
