# Grok Imagine Video API xAI Grok Imagine 影片生成模型完整 API 參考文件。 ## 模型版本 本 API 支援兩種模型版本: | 模型 | ID | 說明 | |-------|-----|-------------| | **Grok Imagine Text to Video** | `grok-imagine-text-to-video` | 文字生成影片 | | **Grok Imagine Image to Video** | `grok-imagine-image-to-video` | 參考圖片引導的影片動畫 | ## 快速對比 | 功能 | Text to Video | Image to Video | |---------|---------------|----------------| | 輸入 | 文字提示詞 | 參考圖片陣列 + 文字提示詞 | | 參考圖片 | 不支援 | 必填(`images`) | ## Grok Imagine Text to Video ### API 位址 ``` POST /api/v1/video/task ``` ### 請求參數 #### 必填參數 | 參數 | 類型 | 說明 | |-----------|------|-------------| | `model_name` | string | 固定值 `"grok-imagine-text-to-video"` | | `prompt` | string | 影片生成提示詞 | #### 可選參數 | 參數 | 類型 | 說明 | |-----------|------|-------------| | `duration` | number | 影片時長:`6` 或 `10` | | `resolution` | string | 輸出解析度:`"480p"` 或 `"720p"` | | `aspect_ratio` | string | 影片長寬比:`"16:9"`、`"1:1"` 或 `"9:16"` | ### 請求示例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/video/task', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ model_name: 'grok-imagine-text-to-video', prompt: 'A robot walking through a futuristic city', duration: 6, resolution: '720p', aspect_ratio: '16:9' }) }); const { data } = await response.json(); const taskId = data.task_id; ``` ## Grok Imagine Image to Video ### 請求參數 #### 必填參數 | 參數 | 類型 | 說明 | |-----------|------|-------------| | `model_name` | string | 固定值 `"grok-imagine-image-to-video"` | | `prompt` | string | 影片生成提示詞 | | `images` | string[] | 用於影片生成的參考圖片 URL 陣列 | #### 可選參數 | 參數 | 類型 | 說明 | |-----------|------|-------------| | `duration` | number | 影片時長:`6` 或 `10` | | `resolution` | string | 輸出解析度:`"480p"` 或 `"720p"` | ### 請求示例 ```javascript { model_name: 'grok-imagine-image-to-video', images: ['https://example.com/reference.jpg'], prompt: 'Camera slowly zooms in on the subject', duration: 6, resolution: '720p' } ``` ## 回應格式 ### 初始回應 兩種模型均回傳用於輪詢的 `task_id`: ```json { "code": 0, "message": "success", "data": { "task_id": "{task_id}", "response_url": "https://api.flaq.ai/api/v1/video/{task_id}", "task_status": "submitted" } } ``` ### 輪詢回應 透過 `GET /api/v1/video/{taskId}` 查詢任務狀態: ```json { "code": 0, "message": "success", "data": { "task_id": "{task_id}", "response_url": "https://api.flaq.ai/api/v1/video/{task_id}", "task_status": "succeed", "task_status_msg": null, "task_result": { "credit": 0.2, "videos": [ { "url": "https://example.com/generated-video.mp4" } ] } } } ``` ### 狀態值說明 - `submitted`:任務已提交,等待處理 - `processing`:影片生成中 - `succeed`:影片生成完成 - `failed`:影片生成失敗 ## 處理時長 典型處理時間:2 到 5 分鐘。 ## 最佳實踐 1. **創意提示詞**:Grok Imagine Video 擅長處理富有想象力、細節豐富的場景說明 2. **運動說明**:在提示詞中加入鏡頭運動和主體动作的說明 3. **圖片品質**:使用圖片轉影片功能時,請提供高品質的輸入圖片