{
  "openapi": "3.1.0",
  "info": {
    "title": "LabelGrid API",
    "version": "1.0.0",
    "description": "Create product-label projects, generate AI drafts, and export artwork. Project, AI, and export quotas are shared with the web app."
  },
  "servers": [
    {
      "url": "/api/v1"
    }
  ],
  "security": [
    {
      "bearerKey": []
    }
  ],
  "paths": {
    "/account": {
      "get": {
        "summary": "Read plan and usage",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/projects": {
      "get": {
        "summary": "List private projects",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Project"
                  }
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a new project",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "template": {
                    "type": "string",
                    "enum": [
                      "botanical",
                      "pantry",
                      "inventory",
                      "blank"
                    ],
                    "default": "blank"
                  },
                  "design": {
                    "$ref": "#/components/schemas/Design"
                  }
                },
                "required": [
                  "title"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/projects/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read a project",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Project"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "ai": {
                          "type": "boolean"
                        },
                        "design": {
                          "oneOf": [
                            {
                              "$ref": "#/components/schemas/Design"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "size": {
                          "type": [
                            "object",
                            "null"
                          ]
                        },
                        "items": {
                          "type": [
                            "array",
                            "null"
                          ],
                          "items": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a project",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ai/drafts": {
      "post": {
        "summary": "Generate an editable AI project",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "widthMm": {
                    "type": "number",
                    "minimum": 10,
                    "maximum": 300
                  },
                  "heightMm": {
                    "type": "number",
                    "minimum": 10,
                    "maximum": 300
                  },
                  "prompt": {
                    "type": "string",
                    "minLength": 12,
                    "maxLength": 1200
                  },
                  "productName": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 50,
                    "description": "Optional exact name to preserve in the generated label."
                  },
                  "brand": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 38,
                    "description": "Optional exact brand text."
                  },
                  "volume": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 19,
                    "description": "Optional exact net weight, volume, or product size."
                  }
                },
                "required": [
                  "widthMm",
                  "heightMm",
                  "prompt"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "id"
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/projects/{id}/exports": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "summary": "Render and download a label",
        "description": "SVG uses millimeter dimensions. PNG includes 600 DPI metadata. The API renders text, lines and rectangles. Export uploaded images with the web editor.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "format": {
                    "type": "string",
                    "enum": [
                      "svg",
                      "png"
                    ],
                    "default": "svg"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Label file",
            "headers": {
              "X-LabelGrid-Exports-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "image/svg+xml": {
                "schema": {
                  "type": "string"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Create a LabelGrid API key in the workspace."
      }
    },
    "schemas": {
      "Project": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "template": {
            "type": "string"
          },
          "revision": {
            "type": "integer"
          },
          "updated_at": {
            "type": "integer",
            "description": "Unix time in milliseconds."
          }
        },
        "required": [
          "id",
          "title",
          "template",
          "revision",
          "updated_at"
        ]
      },
      "Design": {
        "type": "object",
        "properties": {
          "widthMm": {
            "type": "number",
            "minimum": 10,
            "maximum": 300
          },
          "heightMm": {
            "type": "number",
            "minimum": 10,
            "maximum": 300
          },
          "productName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50
          },
          "brand": {
            "type": "string",
            "maxLength": 38
          },
          "subtitle": {
            "type": "string",
            "maxLength": 60
          },
          "detail": {
            "type": "string",
            "maxLength": 62
          },
          "volume": {
            "type": "string",
            "maxLength": 19
          },
          "paper": {
            "type": "string",
            "pattern": "^#[a-fA-F0-9]{6}$"
          },
          "ink": {
            "type": "string",
            "pattern": "^#[a-fA-F0-9]{6}$"
          },
          "accent": {
            "type": "string",
            "pattern": "^#[a-fA-F0-9]{6}$"
          },
          "layout": {
            "type": "string",
            "enum": [
              "minimal",
              "framed",
              "band"
            ]
          },
          "typography": {
            "type": "string",
            "enum": [
              "serif",
              "sans"
            ]
          }
        },
        "required": [
          "widthMm",
          "heightMm",
          "productName"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      }
    }
  }
}
