{
    "openapi": "3.0.3",
    "info": {
        "title": "AI Tin Tức: API tạo video tin từ link bài báo",
        "version": "1.0.0",
        "description": "Gửi đường link bài báo (hoặc nội dung bài), nhận video dọc 1080x1920 có giọng đọc, phụ đề, hình minh hoạ và dòng ghi nguồn. Tính điểm ví AI Đỉnh theo độ dài thật của video (30 giây: 3000 điểm; 60 giây: 5000 điểm; 90 giây: 8000 điểm), y như tạo trên trang. Tệp video giữ 30 ngày, bạn cần tải về máy chủ của bạn."
    },
    "servers": [
        {
            "url": "https://aitintuc.com/api/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "paths": {
        "/videos": {
            "post": {
                "summary": "Tạo một video",
                "operationId": "createVideo",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "schema": {
                            "type": "string",
                            "maxLength": 100
                        },
                        "description": "Cùng khoá và cùng thân thì trả lại việc cũ, không trừ điểm lần hai."
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/VideoCreate"
                            }
                        }
                    }
                },
                "responses": {
                    "202": {
                        "description": "Đã nhận việc",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Video"
                                }
                            }
                        }
                    },
                    "200": {
                        "description": "Việc đã có (gọi lặp)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Video"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Khoá sai",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "402": {
                        "description": "Thiếu điểm",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Idempotency-Key đã dùng cho thân khác",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Tham số sai hoặc không đọc được bài",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Quá nhịp",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "451": {
                        "description": "Nội dung bị từ chối",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Máy bận",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "get": {
                "summary": "Danh sách video",
                "operationId": "listVideos",
                "parameters": [
                    {
                        "name": "limit",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 50,
                            "default": 20
                        }
                    },
                    {
                        "name": "cursor",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "queued",
                                "writing",
                                "rendering",
                                "done",
                                "failed"
                            ]
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Danh sách",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Video"
                                            }
                                        },
                                        "has_more": {
                                            "type": "boolean"
                                        },
                                        "next_cursor": {
                                            "type": "string",
                                            "nullable": true
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/videos/{id}": {
            "parameters": [
                {
                    "name": "id",
                    "in": "path",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "get": {
                "summary": "Xem một video",
                "operationId": "getVideo",
                "responses": {
                    "200": {
                        "description": "Video",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Video"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Không thấy",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Ẩn một video",
                "operationId": "deleteVideo",
                "responses": {
                    "200": {
                        "description": "Đã ẩn"
                    },
                    "409": {
                        "description": "Video đang làm",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/account": {
            "get": {
                "summary": "Số dư điểm, gói, giới hạn",
                "operationId": "getAccount",
                "responses": {
                    "200": {
                        "description": "Tài khoản"
                    }
                }
            }
        },
        "/voices": {
            "get": {
                "summary": "Danh sách giọng đọc",
                "operationId": "listVoices",
                "responses": {
                    "200": {
                        "description": "Danh sách"
                    }
                }
            }
        },
        "/music": {
            "get": {
                "summary": "Danh sách nhạc nền",
                "operationId": "listMusic",
                "responses": {
                    "200": {
                        "description": "Danh sách"
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "Khoá dạng atk_…, tạo tại trang Khoá API và tự động."
            }
        },
        "schemas": {
            "VideoCreate": {
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "Đường link bài báo. Gửi url HOẶC text."
                    },
                    "text": {
                        "type": "string",
                        "description": "Nội dung bài, 500 đến 20.000 ký tự."
                    },
                    "title": {
                        "type": "string",
                        "description": "Tít bài (dùng với text)."
                    },
                    "source": {
                        "type": "string",
                        "description": "Tên nguồn hiện trên video (dùng với text)."
                    },
                    "duration": {
                        "type": "integer",
                        "enum": [
                            30,
                            60,
                            90
                        ],
                        "default": 60,
                        "description": "Độ dài tối đa (giây). Tính điểm theo độ dài thật."
                    },
                    "language": {
                        "type": "string",
                        "enum": [
                            "vi",
                            "en"
                        ],
                        "default": "vi"
                    },
                    "voice": {
                        "type": "string",
                        "description": "Mã giọng từ GET /voices. Bỏ trống thì dùng giọng đầu của ngôn ngữ."
                    },
                    "images": {
                        "type": "string",
                        "enum": [
                            "ai",
                            "article"
                        ],
                        "default": "ai"
                    },
                    "music": {
                        "type": "string",
                        "default": "none",
                        "description": "\"none\" hoặc mã từ GET /music."
                    },
                    "callback_url": {
                        "type": "string",
                        "description": "Địa chỉ công khai nhận webhook khi video xong hoặc hỏng."
                    },
                    "external_id": {
                        "type": "string",
                        "maxLength": 120
                    }
                }
            },
            "Video": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "queued",
                            "writing",
                            "rendering",
                            "done",
                            "failed"
                        ]
                    },
                    "progress": {
                        "type": "object",
                        "properties": {
                            "step": {
                                "type": "integer"
                            },
                            "steps": {
                                "type": "integer"
                            },
                            "message": {
                                "type": "string"
                            }
                        }
                    },
                    "created_at": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "source_url": {
                        "type": "string"
                    },
                    "source_title": {
                        "type": "string"
                    },
                    "duration": {
                        "type": "integer"
                    },
                    "language": {
                        "type": "string"
                    },
                    "voice": {
                        "type": "string"
                    },
                    "images": {
                        "type": "string"
                    },
                    "music": {
                        "type": "string"
                    },
                    "external_id": {
                        "type": "string",
                        "nullable": true
                    },
                    "price_max": {
                        "type": "integer",
                        "description": "Điểm đã giữ lúc nhận việc (theo bậc độ dài đã chọn)."
                    },
                    "plan_credit_used": {
                        "type": "boolean"
                    },
                    "charged": {
                        "type": "integer",
                        "description": "Điểm thật sự tính sau khi hoàn phần chênh."
                    },
                    "refunded": {
                        "type": "integer"
                    },
                    "video_url": {
                        "type": "string"
                    },
                    "download_url": {
                        "type": "string"
                    },
                    "thumbnail_url": {
                        "type": "string"
                    },
                    "duration_actual": {
                        "type": "number"
                    },
                    "size_mb": {
                        "type": "number"
                    },
                    "title": {
                        "type": "string"
                    },
                    "caption": {
                        "type": "string"
                    },
                    "hashtags": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "script": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "start": {
                                    "type": "number",
                                    "nullable": true
                                },
                                "end": {
                                    "type": "number",
                                    "nullable": true
                                },
                                "text": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "source_credit": {
                        "type": "string"
                    },
                    "expires_at": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}