返回 Pixelle-Video
api-overview.md
根目录 / docs / en / reference / api-overview.md
1 # API Overview
2
3 Pixelle-Video provides both Python SDK and HTTP REST API.
4
5 ---
6
7 ## Python SDK
8
9 ### PixelleVideoCore
10
11 Main service class providing video generation functionality.
12
13 ```python
14 from pixelle_video.service import PixelleVideoCore
15
16 pixelle = PixelleVideoCore()
17 await pixelle.initialize()
18 ```
19
20 ### generate_video()
21
22 Primary method for generating videos.
23
24 **Parameters**:
25
26 - `text` (str): Topic or complete script
27 - `mode` (str): Generation mode ("generate" or "fixed")
28 - `n_scenes` (int): Number of scenes
29 - `title` (str, optional): Video title
30 - `tts_workflow` (str): TTS workflow
31 - `media_workflow` (str): Media generation workflow (image or video)
32 - `frame_template` (str): Video template
33 - `template_params` (dict, optional): Custom template parameters
34 - `bgm_path` (str, optional): BGM file path
35 - `bgm_volume` (float): BGM volume (0.0-1.0)
36
37 **Returns**: `VideoResult` object
38
39 ---
40
41 ## HTTP REST API
42
43 Start the API server:
44
45 ```bash
46 uv run uvicorn api.app:app --host 0.0.0.0 --port 8000
47 ```
48
49 ### Video Generation - Synchronous
50
51 `POST /api/video/generate/sync`
52
53 Generate video synchronously, waits until completion. Suitable for small videos (< 30 seconds).
54
55 **Request Body**:
56
57 ```json
58 {
59 "text": "Why you should develop a reading habit",
60 "mode": "generate",
61 "n_scenes": 5,
62 "frame_template": "1080x1920/image_default.html",
63 "template_params": {
64 "accent_color": "#3498db",
65 "background": "https://example.com/custom-bg.jpg"
66 },
67 "title": "The Power of Reading"
68 }
69 ```
70
71 **Response**:
72
73 ```json
74 {
75 "success": true,
76 "message": "Success",
77 "video_url": "http://localhost:8000/api/files/xxx/final.mp4",
78 "duration": 45.5,
79 "file_size": 12345678
80 }
81 ```
82
83 ### Video Generation - Asynchronous
84
85 `POST /api/video/generate/async`
86
87 Generate video asynchronously, returns task ID immediately. Suitable for large videos.
88
89 **Response**:
90
91 ```json
92 {
93 "success": true,
94 "message": "Task created successfully",
95 "task_id": "abc123"
96 }
97 ```
98
99 ### Query Task Status
100
101 `GET /api/tasks/{task_id}`
102
103 **Response**:
104
105 ```json
106 {
107 "task_id": "abc123",
108 "status": "completed",
109 "result": {
110 "video_url": "http://localhost:8000/api/files/xxx/final.mp4",
111 "duration": 45.5,
112 "file_size": 12345678
113 }
114 }
115 ```
116
117 ---
118
119 ## Request Parameters
120
121 | Parameter | Type | Required | Description |
122 |-----------|------|----------|-------------|
123 | `text` | string | Yes | Topic or complete script |
124 | `mode` | string | No | `"generate"` (AI generates) or `"fixed"` (use text as-is) |
125 | `n_scenes` | int | No | Number of scenes (1-20), only used in generate mode |
126 | `title` | string | No | Video title (auto-generated if not provided) |
127 | `frame_template` | string | No | Template path, e.g., `1080x1920/image_default.html` |
128 | `template_params` | object | No | Custom template parameters (colors, backgrounds, etc.) |
129 | `media_workflow` | string | No | Media workflow (image or video generation) |
130 | `tts_workflow` | string | No | TTS workflow |
131 | `ref_audio` | string | No | Reference audio path for voice cloning |
132 | `prompt_prefix` | string | No | Image style prefix |
133 | `bgm_path` | string | No | BGM file path |
134 | `bgm_volume` | float | No | BGM volume (0.0-1.0, default 0.3) |
135
136 ---
137
138 ## More Information
139
140 API documentation is also available via Swagger UI: `http://localhost:8000/docs`
141
142
142 lines MARKDOWN