{
  "openapi": "3.1.0",
  "info": {
    "title": "mj-v8.1-upload-paint 인터페이스",
    "description": "Midjourney V8.1 고급 편집 인터페이스",
    "license": {
      "name": "MIT"
    },
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.evolink.ai",
      "description": "프로덕션"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "이미지 생성",
      "description": "AI 이미지 생성 관련 인터페이스"
    }
  ],
  "paths": {
    "/v1/images/generations": {
      "post": {
        "tags": [
          "이미지 생성"
        ],
        "summary": "mj-v8.1-upload-paint 인터페이스",
        "description": "- 이미지를 업로드하여 캔버스에서 고급 편집, 마스크 영역 지정 및 위치 조정 지원\n- mj-v8.1-edit와 유사하지만, 기존 작업에 의존하지 않고 이미지를 직접 전달\n- 비동기 처리 모드, 반환된 작업 ID로 [조회](/ko/api-manual/task-management/get-task-detail)",
        "operationId": "createImageGeneration",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageGenerationRequest"
              },
              "examples": {
                "upload_paint_example": {
                  "summary": "고급 편집",
                  "value": {
                    "model": "mj-v8.1-upload-paint",
                    "prompt": "Beautiful mountain scenery background",
                    "image_urls": [
                      "https://example.com/photo.jpg"
                    ],
                    "model_params": {
                      "mask": {
                        "areas": [
                          {
                            "width": 100,
                            "height": 100,
                            "points": [
                              10,
                              10,
                              10,
                              100,
                              100,
                              100,
                              100,
                              10
                            ]
                          }
                        ]
                      },
                      "canvas": {
                        "width": 1024,
                        "height": 1024
                      },
                      "img_pos": {
                        "width": 512,
                        "height": 512,
                        "x": 256,
                        "y": 256
                      },
                      "speed": "fast"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "작업 생성 성공",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageGenerationResponse"
                }
              }
            }
          },
          "400": {
            "description": "잘못된 요청 매개변수",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "invalid_request",
                    "message": "Invalid request parameters",
                    "type": "invalid_request_error"
                  }
                }
              }
            }
          },
          "401": {
            "description": "미인증, 토큰 무효 또는 만료",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "unauthorized",
                    "message": "Invalid or expired token",
                    "type": "authentication_error"
                  }
                }
              }
            }
          },
          "402": {
            "description": "쿼터 부족, 충전하세요",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "insufficient_quota",
                    "message": "Insufficient quota. Please top up your account.",
                    "type": "insufficient_quota"
                  }
                }
              }
            }
          },
          "403": {
            "description": "접근 거부",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "model_access_denied",
                    "message": "Token does not have access to model: mj-v8.1-upload-paint",
                    "type": "invalid_request_error"
                  }
                }
              }
            }
          },
          "429": {
            "description": "요청 속도 제한 초과",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "rate_limit_exceeded",
                    "message": "Too many requests, please try again later",
                    "type": "rate_limit_error"
                  }
                }
              }
            }
          },
          "500": {
            "description": "내부 서버 오류",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "error": {
                    "code": "internal_error",
                    "message": "Internal server error",
                    "type": "api_error"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ImageGenerationRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt",
          "image_urls",
          "model_params"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "모델 이름",
            "enum": [
              "mj-v8.1-upload-paint"
            ],
            "default": "mj-v8.1-upload-paint",
            "example": "mj-v8.1-upload-paint"
          },
          "prompt": {
            "type": "string",
            "description": "편집 프롬프트",
            "maxLength": 1024,
            "example": "Beautiful mountain scenery background"
          },
          "image_urls": {
            "type": "array",
            "description": "입력 이미지 URL (첫 번째가 사용됨)",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "maxItems": 1,
            "example": [
              "https://example.com/photo.jpg"
            ]
          },
          "model_params": {
            "type": "object",
            "description": "고급 편집 매개변수",
            "required": [
              "mask",
              "canvas",
              "img_pos"
            ],
            "properties": {
              "mask": {
                "type": "object",
                "description": "다시 그릴 마스크 영역 (다각형 좌표 또는 마스크 이미지)\n\n**방법 1 - 다각형 좌표:**\n```json\n{ \"areas\": [{ \"width\": 100, \"height\": 100, \"points\": [10, 10, 10, 100, 100, 100, 100, 10] }] }\n```\n\n**방법 2 - 마스크 이미지 (알파 채널: 불투명 = 다시 그리기, 투명 = 보존, 일반적인 inpaint 마스크와 반대):**\n```json\n{ \"url\": \"https://example.com/mask.png\" }\n```",
                "properties": {
                  "areas": {
                    "type": "array",
                    "description": "다각형 영역 목록",
                    "items": {
                      "type": "object",
                      "properties": {
                        "width": {
                          "type": "integer",
                          "description": "영역 너비"
                        },
                        "height": {
                          "type": "integer",
                          "description": "영역 높이"
                        },
                        "points": {
                          "type": "array",
                          "description": "다각형 꼭짓점 좌표 (x1,y1,x2,y2,...)",
                          "items": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "마스크 이미지 URL (알파 채널: 불투명 = 다시 그리기, 투명 = 보존, 일반적인 inpaint 마스크와 반대). 이미지 크기는 참조 이미지의 픽셀 크기와 완전히 일치해야 합니다."
                  }
                }
              },
              "canvas": {
                "type": "object",
                "description": "캔버스 크기. ⚠️ 캔버스 가로세로 비율(width/height)은 업로드한 이미지의 가로세로 비율과 일치해야 하며, 그렇지 않으면 작업이 실패합니다(status: failed, 실행 오류).",
                "required": [
                  "width",
                  "height"
                ],
                "properties": {
                  "width": {
                    "type": "integer",
                    "description": "캔버스 너비",
                    "example": 1024
                  },
                  "height": {
                    "type": "integer",
                    "description": "캔버스 높이",
                    "example": 1024
                  }
                }
              },
              "img_pos": {
                "type": "object",
                "description": "캔버스 내 이미지의 위치 및 크기. 이미지가 캔버스를 가득 채우면(img 너비/높이 = canvas 너비/높이) 순수 편집/다시 그리기이고, 이미지가 캔버스보다 작으면 외부 확장 그리기(outpaint, 주변 빈 영역이 프롬프트에 따라 생성됨)입니다.",
                "required": [
                  "width",
                  "height",
                  "x",
                  "y"
                ],
                "properties": {
                  "width": {
                    "type": "integer",
                    "description": "렌더링 너비",
                    "example": 512
                  },
                  "height": {
                    "type": "integer",
                    "description": "렌더링 높이",
                    "example": 512
                  },
                  "x": {
                    "type": "integer",
                    "description": "왼쪽 상단 수평 오프셋",
                    "example": 256
                  },
                  "y": {
                    "type": "integer",
                    "description": "왼쪽 상단 수직 오프셋",
                    "example": 256
                  }
                }
              },
              "speed": {
                "type": "string",
                "description": "속도 모드",
                "enum": [
                  "fast"
                ],
                "default": "fast",
                "example": "fast"
              }
            }
          },
          "callback_url": {
            "type": "string",
            "description": "작업 완료 후 HTTPS 콜백 주소\n\n**콜백 시점:**\n- 작업 완료(completed), 실패(failed) 또는 취소(cancelled) 시 트리거\n- 과금 확인 완료 후 전송\n\n**보안 제한:**\n- HTTPS 프로토콜만 지원\n- 내부 네트워크 IP 주소로의 콜백 금지 (127.0.0.1, 10.x.x.x, 172.16-31.x.x, 192.168.x.x 등)\n- URL 길이 최대 `2048`자\n\n**콜백 메커니즘:**\n- 타임아웃: `10`초\n- 실패 후 최대 `3`회 재시도 (실패 후 `1`초/`2`초/`4`초에 각각 재시도)\n- 콜백 응답 형식은 작업 조회 인터페이스 반환 형식과 동일\n- 콜백 주소가 2xx 상태 코드를 반환하면 성공, 기타 상태 코드는 재시도 트리거",
            "format": "uri",
            "example": "https://your-domain.com/webhooks/image-task-completed"
          }
        }
      },
      "ImageGenerationResponse": {
        "type": "object",
        "properties": {
          "created": {
            "type": "integer",
            "description": "작업 생성 타임스탬프",
            "example": 1757165031
          },
          "id": {
            "type": "string",
            "description": "작업 ID",
            "example": "task-unified-1757165031-mjv81"
          },
          "model": {
            "type": "string",
            "description": "실제 사용된 모델 이름"
          },
          "object": {
            "type": "string",
            "enum": [
              "image.generation.task"
            ],
            "description": "작업 유형"
          },
          "progress": {
            "type": "integer",
            "description": "작업 진행률 (0-100)",
            "minimum": 0,
            "maximum": 100,
            "example": 0
          },
          "status": {
            "type": "string",
            "description": "작업 상태",
            "enum": [
              "pending",
              "processing",
              "completed",
              "failed"
            ],
            "example": "pending"
          },
          "task_info": {
            "$ref": "#/components/schemas/TaskInfo"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "audio",
              "video"
            ],
            "example": "image"
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "오류 코드 식별자"
              },
              "message": {
                "type": "string",
                "description": "오류 메시지"
              },
              "type": {
                "type": "string",
                "description": "오류 유형"
              }
            }
          }
        }
      },
      "TaskInfo": {
        "type": "object",
        "properties": {
          "can_cancel": {
            "type": "boolean",
            "description": "작업 취소 가능 여부",
            "example": true
          },
          "estimated_time": {
            "type": "integer",
            "description": "예상 완료 시간(초)",
            "minimum": 0,
            "example": 45
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "billing_rule": {
            "type": "string",
            "enum": [
              "per_call",
              "per_token",
              "per_second"
            ],
            "example": "per_call"
          },
          "credits_reserved": {
            "type": "number",
            "description": "예상 소비 크레딧",
            "minimum": 0,
            "example": 1.8
          },
          "user_group": {
            "type": "string",
            "example": "default"
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "##모든 인터페이스는 Bearer Token 인증이 필요합니다##\n\n**API Key 발급:**\n\n[API Key 관리 페이지](https://evolink.ai/dashboard/keys)에서 API Key를 발급받으세요\n\n**요청 헤더에 다음을 추가하세요:**\n```\nAuthorization: Bearer YOUR_API_KEY\n```"
      }
    }
  }
}