API 文件
API 沿用 OpenAI 的路徑與回應格式。Base URL:https://your-domain/v1。呼叫以美元從帳號餘額扣款,與工作室共用同一份餘額。
身分驗證
在 API 金鑰 頁面建立金鑰(格式如 sk-jg-…),並在每次請求時附上:
Authorization: Bearer sk-jg-xxxxxxxxxxxxxxxx列出模型
GET/v1/models
curl https://your-domain/v1/models \
-H "Authorization: Bearer $API_KEY"影片生成
影片生成為非同步:請求會立即回傳一個任務。請持續輪詢,直到狀態變為 completed,再取得影片。
POST/v1/videos
curl https://your-domain/v1/videos \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.5",
"prompt": "鏡頭緩緩推近,麥田裡的女孩回頭微笑,夕陽逆光",
"seconds": 5,
"resolution": "720p",
"aspect_ratio": "16:9"
}'GET/v1/videos/{id}
status 的值為 queued、in_progress、completed 或 failed 其中之一。已完成的任務會包含 video_url;失敗的任務會包含 error.message,且費用會退還。建議每 3–5 秒輪詢一次。
curl https://your-domain/v1/videos/$TASK_ID \
-H "Authorization: Bearer $API_KEY"影片完成前,GET /v1/videos/{id}/content 會回傳 409。
圖片生成
圖片端點為同步:回應會直接附上生成完成的圖片。
POST/v1/images/generations
curl https://your-domain/v1/images/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-2",
"prompt": "白色背景上的霧面玻璃香水瓶,極簡商品攝影,柔和側光",
"aspect_ratio": "1:1",
"n": 1
}'參考素材
部分模型可以同時參考圖片、影片和音訊。分別透過 images、videos、audios 傳入,並在提示詞中用 @image1、@video1、@audio1 引用——依類型分別從 1 開始編號,順序與陣列一致。我們會為不同的服務商自動轉換這些標籤。
curl https://your-domain/v1/videos \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.5",
"prompt": "@image1 從 @video1 的場景中走進房間,運鏡與 @video1 一致,背景音樂使用 @audio1",
"seconds": 5,
"aspect_ratio": "16:9",
"first_frame": "https://example.com/start.png",
"images": [
"https://example.com/character.png"
],
"videos": [
"https://example.com/camera-move.mp4"
],
"audios": [
"https://example.com/music.mp3"
],
"generate_audio": true
}'每個模型的上限與支援情況請見模型頁(例如最多 9 張圖片、3 部影片、3 段音訊)。素材數量超限時回傳 too_many_images / too_many_videos / too_many_audios;模型不支援的欄位回傳 feature_not_supported。
請求內容
影片與圖片端點共用同一種請求內容。各模型允許的值請見其模型頁面。
| 欄位 | 類型 | 說明 |
|---|---|---|
| model | string | 必填。模型 ID。 |
| prompt | string | 必填。1–8000 個字元。 |
| seconds | number | 影片長度(秒),需在模型支援的範圍內。 |
| resolution | string | 解析度,例如 720p。 |
| aspect_ratio | string | 畫面比例,例如 16:9。 |
| n | integer | 圖片張數,不可超過模型上限。 |
| images | string[] | 參考圖網址(http/https),不可超過模型上限。 |
| videos | string[] | 參考影片 URL(http/https),數量不超過模型上限。 |
| audios | string[] | 參考音訊 URL(http/https),數量不超過模型上限。 |
| first_frame | string | 影片首幀圖片 URL(模型支援時)。 |
| last_frame | string | 影片尾幀圖片 URL(模型支援時),需與 first_frame 一起使用。 |
| generate_audio | boolean | 是否同時生成聲音(模型支援時)。 |
| seed | integer | 整數隨機種子。相同的種子和參數會得到相近的結果。 |
| extra | object | 選填,模型專屬的額外參數。 |
未填寫的選填欄位會使用模型預設值。
計費與錯誤
- 計費幣別為美元。回應中的
cost_usd是本次生成的費用,為十進位字串(如"0.5000",不足一美分的價格最多保留 4 位小數)。 - 提交時會依模型價格從餘額預扣費用,生成失敗將自動退還。每一筆異動都可在「帳單」中查看。
401缺少金鑰或金鑰無效 ·402insufficient_balance:餘額不足,請先儲值再繼續 ·400使用了模型不支援的參數 ·404模型或任務不存在。- API 錯誤的格式為
{"error": {"message": "…", "type": "…", "code": "…"}}。請依code判斷錯誤類型,並將message顯示給使用者。 - 訊息會依語系顯示:請傳送
X-Locale(en、zh-CN、zh-TW、ja、ko),或使用Accept-Language。
HTTP/1.1 402 Payment Required
{
"error": {
"message": "Insufficient balance: $0.50 needed, $0.10 available",
"type": "insufficient_quota",
"code": "insufficient_balance"
}
}