{
  "openapi": "3.1.0",
  "info": {
    "title": "LlamaGen Comic API",
    "version": "1.0.0",
    "description": "Create comics, manga, webtoons, storyboards, and consistent-character visual stories with LlamaGen.",
    "contact": {
      "name": "LlamaGen developer support",
      "email": "support@llamagen.ai",
      "url": "https://llamagen.ai/comic-api/docs"
    }
  },
  "servers": [
    {
      "url": "https://api.llamagen.ai/v1",
      "description": "Production API"
    },
    {
      "url": "https://llamagen.ai/api/v1",
      "description": "Production API through llamagen.ai"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/comics/generations": {
      "post": {
        "operationId": "createComicGeneration",
        "summary": "Create a comic generation",
        "description": "Creates a new comic generation from a prompt and optional references.",
        "tags": ["Comics"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateComicGenerationRequest"
              },
              "examples": {
                "manga": {
                  "summary": "Manga scene",
                  "value": {
                    "prompt": "A quiet cyberpunk ramen shop where two rivals meet before a tournament.",
                    "style": "manga",
                    "fixPanelNum": 4
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generation created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ComicGeneration"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/comics/generations/{generationID}": {
      "get": {
        "operationId": "getComicGeneration",
        "summary": "Get comic generation status",
        "description": "Returns the status, panels, generated assets, and errors for an existing comic generation.",
        "tags": ["Comics"],
        "parameters": [
          {
            "name": "generationID",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "panel",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Generation status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ComicGeneration"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateComicGenerationPanel",
        "summary": "Regenerate a panel or continue a comic",
        "description": "Updates a single panel or continues an existing comic generation.",
        "tags": ["Comics"],
        "parameters": [
          {
            "name": "generationID",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateComicGenerationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generation updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ComicGeneration"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/comics/usage": {
      "get": {
        "operationId": "getComicApiUsage",
        "summary": "Get Comic API usage",
        "description": "Returns API usage, plan state, and remaining credits for the authenticated token.",
        "tags": ["Usage"],
        "responses": {
          "200": {
            "description": "Usage state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/comics/upload": {
      "post": {
        "operationId": "uploadComicReference",
        "summary": "Upload a comic reference asset",
        "description": "Uploads an image or reference file for use in comic generation.",
        "tags": ["Files"],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Uploaded file URL",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileUpload"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "403": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "413": {
            "$ref": "#/components/responses/PayloadTooLarge"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "LlamaGen API token"
      }
    },
    "schemas": {
      "CreateComicGenerationRequest": {
        "type": "object",
        "required": ["prompt"],
        "properties": {
          "prompt": {
            "type": "string",
            "description": "Story, scene, or panel prompt."
          },
          "style": {
            "type": "string",
            "description": "Optional art direction."
          },
          "fixPanelNum": {
            "type": "integer",
            "minimum": 1,
            "maximum": 40,
            "description": "Optional requested panel count."
          },
          "size": {
            "type": "string",
            "description": "Optional image size or aspect ratio."
          },
          "images": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "description": "Optional reference image URLs."
          }
        },
        "additionalProperties": true
      },
      "UpdateComicGenerationRequest": {
        "type": "object",
        "properties": {
          "action": {
            "type": "string",
            "enum": ["continueWrite", "regeneratePanel"]
          },
          "pageIndex": {
            "type": "integer",
            "minimum": 0
          },
          "panelIndex": {
            "type": "integer",
            "minimum": 0
          },
          "panelPrompt": {
            "type": "string"
          },
          "images": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          }
        },
        "additionalProperties": true
      },
      "ComicGeneration": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "description": "Generation lifecycle state."
          },
          "artwork": {
            "type": "object",
            "additionalProperties": true
          },
          "panels": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "usage": {
            "$ref": "#/components/schemas/UsageDelta"
          }
        },
        "additionalProperties": true
      },
      "Usage": {
        "type": "object",
        "properties": {
          "apiUsageCount": {
            "type": "integer"
          },
          "apiMaxUsage": {
            "type": "integer"
          },
          "credits": {
            "type": "integer"
          },
          "isPaidPlan": {
            "type": "boolean"
          }
        },
        "additionalProperties": true
      },
      "UsageDelta": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "integer"
          },
          "unit": {
            "type": "string",
            "default": "credits"
          }
        },
        "additionalProperties": true
      },
      "FileUpload": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer",
            "example": 200
          },
          "fileUrl": {
            "type": "string",
            "format": "uri"
          }
        },
        "required": ["fileUrl"],
        "additionalProperties": true
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          },
          "message": {
            "type": "string"
          },
          "error": {
            "type": "object",
            "additionalProperties": true
          },
          "docsUrl": {
            "type": "string",
            "format": "uri"
          }
        },
        "additionalProperties": true
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid bearer token",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "PayloadTooLarge": {
        "description": "Uploaded file is too large",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit or plan limit reached",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            },
            "description": "Seconds to wait before retrying, when available."
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InternalError": {
        "description": "Internal server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Comics",
      "description": "Comic generation and editing endpoints."
    },
    {
      "name": "Usage",
      "description": "Usage, plan, and credit visibility."
    },
    {
      "name": "Files",
      "description": "Reference asset upload endpoints."
    }
  ]
}
