{
  "openapi": "3.0.0",
  "info": {
    "title": "PoYo AI API",
    "description": "Professional Image, Video, and 3D Generation APIs",
    "version": "1.0.0",
    "contact": {
      "email": "support@poyo.ai"
    }
  },
  "servers": [
    {
      "url": "https://api.poyo.ai",
      "description": "Production server"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/api/generate/submit": {
      "post": {
        "summary": "Submit Generation Task",
        "description": "Submit an image or video generation task. This endpoint supports multiple models for both image and video generation.",
        "operationId": "submitGenerationTask",
        "tags": ["Generation"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SubmitRequest"
              },
              "examples": {
                "gpt-4o-image": {
                  "summary": "GPT-4o Image Generation",
                  "value": {
                    "model": "gpt-4o-image",
                    "callback_url": "https://your-domain.com/callback",
                    "input": {
                      "prompt": "A serene mountain landscape at sunset with vibrant colors",
                      "size": "1:1",
                      "n": 1
                    }
                  }
                },
                "gpt-4o-image-edit": {
                  "summary": "GPT-4o Image Edit",
                  "value": {
                    "model": "gpt-4o-image-edit",
                    "callback_url": "https://your-domain.com/callback",
                    "input": {
                      "prompt": "Replace the sky with a starry night sky",
                      "image_urls": ["https://example.com/original-image.jpg"],
                      "mask_url": "https://example.com/mask.png",
                      "size": "1:1"
                    }
                  }
                },
                "nano-banana": {
                  "summary": "Nano Banana Image Generation",
                  "value": {
                    "model": "nano-banana",
                    "callback_url": "https://your-domain.com/callback",
                    "input": {
                      "prompt": "A cyberpunk street scene with neon signs and rain",
                      "size": "16:9"
                    }
                  }
                },
                "nano-banana-edit": {
                  "summary": "Nano Banana Image Edit",
                  "value": {
                    "model": "nano-banana-edit",
                    "callback_url": "https://your-domain.com/callback",
                    "input": {
                      "prompt": "Add colorful flowers in the foreground",
                      "image_urls": ["https://example.com/landscape.jpg"],
                      "size": "16:9"
                    }
                  }
                },
                "sora-2": {
                  "summary": "Sora 2 Video Generation",
                  "value": {
                    "model": "sora-2",
                    "callback_url": "https://your-domain.com/callback",
                    "input": {
                      "prompt": "A time-lapse of a bustling city street transitioning from day to night",
                      "duration": 15,
                      "aspect_ratio": "16:9"
                    }
                  }
                },
                "sora-2-pro": {
                  "summary": "Sora 2 Pro Video Generation",
                  "value": {
                    "model": "sora-2-pro",
                    "callback_url": "https://your-domain.com/callback",
                    "input": {
                      "prompt": "A cinematic drone shot flying through a misty forest at dawn",
                      "duration": 25,
                      "aspect_ratio": "16:9"
                    }
                  }
                },
                "veo3.1-fast": {
                  "summary": "VEO 3.1 Fast Video Generation",
                  "value": {
                    "model": "veo3.1-fast",
                    "callback_url": "https://your-domain.com/callback",
                    "input": {
                      "prompt": "A peaceful stream flowing through a lush green forest",
                      "duration": 8,
                      "aspect_ratio": "16:9"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task submitted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubmitResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/generate/status/{task_id}": {
      "get": {
        "summary": "Get task status",
        "description": "Query the status and results of a generation task",
        "operationId": "getTaskStatus",
        "tags": ["Task Management"],
        "parameters": [
          {
            "name": "task_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique task identifier"
          }
        ],
        "responses": {
          "200": {
            "description": "Task status retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatusResponse"
                }
              }
            }
          },
          "404": {
            "description": "Task not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "All API endpoints require Bearer Token authentication.\n\nCreate an API key: sign in to PoYo, open **Dashboard → API Key** at [poyo.ai/dashboard/api-key](https://poyo.ai/dashboard/api-key), and click to create a key.\n\nAdd it to the request header:\n\n```\nAuthorization: Bearer YOUR_API_KEY\n```"
      }
    },
    "schemas": {
      "SubmitRequest": {
        "type": "object",
        "required": ["model"],
        "properties": {
          "model": {
            "type": "string",
            "description": "Model identifier for image or video generation"
          },
          "callback_url": {
            "type": "string",
            "format": "uri",
            "description": "Webhook callback URL for result notifications",
            "example": "https://your-domain.com/callback"
          },
          "input": {
            "type": "object",
            "required": ["prompt"],
            "description": "Input parameters for generation",
            "properties": {
              "prompt": {
                "type": "string",
                "description": "Generation prompt describing the desired output. Prompt limits are model-specific; see each model page for exact limits.",
                "maxLength": 20000,
                "example": "A beautiful sunset over the ocean"
              },
              "image_urls": {
                "type": "array",
                "items": {
                  "type": "string",
                  "format": "uri"
                },
                "description": "Reference image URLs (for image editing or image-to-video)",
                "example": []
              },
              "size": {
                "type": "string",
                "description": "Image size (e.g., '1:1')",
                "example": "1:1"
              },
              "n": {
                "type": "integer",
                "description": "Number of images to generate",
                "minimum": 1,
                "maximum": 4,
                "example": 1
              },
              "duration": {
                "type": "integer",
                "description": "Video duration in seconds",
                "example": 15
              },
              "aspect_ratio": {
                "type": "string",
                "description": "Video aspect ratio",
                "example": "16:9"
              },
              "mask_url": {
                "type": "string",
                "format": "uri",
                "description": "Mask image URL for editing",
                "example": "https://example.com/mask.png"
              }
            }
          }
        }
      },
      "SubmitResponse": {
        "type": "object",
        "required": ["code", "data"],
        "properties": {
          "code": {
            "type": "integer",
            "example": 200,
            "description": "Business status code. `200` means success; any other value means the request failed. Always check this field: some validation errors return HTTP 200 with `code: 400` in the body.\n\n- `200`: Success\n- `400`: Invalid request parameters\n- `401`: Missing or invalid API key\n- `402`: Insufficient credits\n- `403`: Permission denied\n- `404`: Resource not found\n- `408`: Request timeout\n- `429`: Rate limit exceeded\n- `500`: Internal server error\n- `502`: Upstream service error\n- `503`: Service unavailable\n\nSee [Error Codes](/api-manual/error-codes) for details.",
            "enum": [200, 400, 401, 402, 403, 404, 408, 429, 500, 502, 503]
          },
          "data": {
            "type": "object",
            "required": ["task_id", "status", "created_time"],
            "properties": {
              "task_id": {
                "type": "string",
                "example": "task-unified-1757165031-uyujaw3d",
                "description": "Unique task identifier for status tracking"
              },
              "status": {
                "type": "string",
                "enum": ["not_started", "running", "finished", "failed"],
                "example": "not_started",
                "description": "Task status. Always `not_started` right after submission. Use [Query Task Status](/api-manual/task-management/status) or `callback_url` to get later states.\n\n- `not_started`: Queued, waiting to be processed\n- `running`: Being generated\n- `finished`: Completed; results are in `files` or `output`\n- `failed`: Failed; details are in `error_message`"
              },
              "created_time": {
                "type": "string",
                "format": "date-time",
                "example": "2025-11-12T10:30:00",
                "description": "ISO 8601 timestamp when the task was created"
              }
            }
          }
        },
        "example": {
          "code": 200,
          "data": {
            "task_id": "task-unified-1757165031-uyujaw3d",
            "status": "not_started",
            "created_time": "2025-11-12T10:30:00"
          }
        }
      },
      "StatusResponse": {
        "type": "object",
        "required": ["code", "data"],
        "properties": {
          "code": {
            "type": "integer",
            "example": 200,
            "description": "Business status code. `200` means success; any other value means the request failed. Always check this field: some validation errors return HTTP 200 with `code: 400` in the body.\n\n- `200`: Success\n- `400`: Invalid request parameters\n- `401`: Missing or invalid API key\n- `402`: Insufficient credits\n- `403`: Permission denied\n- `404`: Resource not found\n- `408`: Request timeout\n- `429`: Rate limit exceeded\n- `500`: Internal server error\n- `502`: Upstream service error\n- `503`: Service unavailable\n\nSee [Error Codes](/api-manual/error-codes) for details.",
            "enum": [200, 400, 401, 402, 403, 404, 408, 429, 500, 502, 503]
          },
          "data": {
            "type": "object",
            "required": ["task_id", "status", "credits_amount", "files", "created_time", "progress"],
            "properties": {
              "task_id": {
                "type": "string",
                "example": "task-unified-1757165031-uyujaw3d",
                "description": "Unique task identifier"
              },
              "status": {
                "type": "string",
                "enum": ["not_started", "running", "finished", "failed"],
                "example": "finished",
                "description": "Task status.\n\n- `not_started`: Queued, waiting to be processed\n- `running`: Being generated\n- `finished`: Completed; results are in `files` or `output`\n- `failed`: Failed; details are in `error_message`"
              },
              "credits_amount": {
                "type": "number",
                "example": 2,
                "description": "Credits charged for the task"
              },
              "output": {
                "type": "object",
                "additionalProperties": true,
                "description": "Optional structured model output. Omni Moderation returns the complete OpenAI moderation response here after the task finishes; its files array is empty."
              },
              "files": {
                "type": "array",
                "description": "Generated media files (populated when status is finished)",
                "items": {
                  "type": "object",
                  "required": ["file_url", "file_type"],
                  "properties": {
                    "file_url": {
                      "type": "string",
                      "format": "uri",
                      "example": "https://storage.poyo.ai/generated/image-abc123.jpg",
                      "description": "Direct URL to the generated file (valid for 24 hours)"
                    },
                    "file_type": {
                      "type": "string",
                      "enum": ["image", "video", "3d", "other"],
                      "example": "image",
                      "description": "Type of generated file: 'image', 'video', '3d', or 'other'"
                    },
                    "label": {
                      "type": "string",
                      "description": "Optional file label, commonly used for 3D outputs"
                    },
                    "format": {
                      "type": "string",
                      "description": "Optional file format, such as glb, fbx, obj, png, or mp4"
                    },
                    "content_type": {
                      "type": "string",
                      "description": "Optional MIME type of the generated file"
                    },
                    "file_name": {
                      "type": "string",
                      "description": "Optional file name"
                    },
                    "file_size": {
                      "type": "integer",
                      "description": "Optional file size in bytes"
                    }
                  }
                },
                "example": [
                  {
                    "file_url": "https://storage.poyo.ai/generated/image-abc123.jpg",
                    "file_type": "image"
                  }
                ]
              },
              "created_time": {
                "type": "string",
                "format": "date-time",
                "example": "2025-11-12T10:30:00",
                "description": "ISO 8601 timestamp of task creation"
              },
              "progress": {
                "type": "integer",
                "minimum": 0,
                "maximum": 100,
                "example": 100,
                "description": "Completion percentage"
              },
              "error_message": {
                "type": "string",
                "nullable": true,
                "example": null,
                "description": "Error description (when status is failed)"
              }
            }
          }
        },
        "example": {
          "code": 200,
          "data": {
            "task_id": "task-unified-1757165031-uyujaw3d",
            "status": "finished",
            "credits_amount": 2,
            "files": [
              {
                "file_url": "https://storage.poyo.ai/generated/image-abc123.jpg",
                "file_type": "image"
              }
            ],
            "created_time": "2025-11-12T10:30:00",
            "progress": 100,
            "error_message": null
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer",
            "enum": [200, 400, 401, 402, 403, 404, 408, 429, 500, 502, 503],
            "description": "Business status code. `200` means success; any other value means the request failed. Always check this field: some validation errors return HTTP 200 with `code: 400` in the body.\n\n- `200`: Success\n- `400`: Invalid request parameters\n- `401`: Missing or invalid API key\n- `402`: Insufficient credits\n- `403`: Permission denied\n- `404`: Resource not found\n- `408`: Request timeout\n- `429`: Rate limit exceeded\n- `500`: Internal server error\n- `502`: Upstream service error\n- `503`: Service unavailable\n\nSee [Error Codes](/api-manual/error-codes) for details."
          },
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
