APIKO
影片系列

Kling 4.0 Flash API

  • 支援文字、首幀圖片、參考圖片和參考影片,產生 3–20 秒、720p 的影片。
  • 首幀使用 first_image_url。使用參考素材時,傳入 reference_image_urls 或 reference_videos。
  • 透過 POST /v1/videos 建立任務。輪詢 GET /v1/videos/{id} 直到完成,再下載含簽章的影片。
  • 有參考影片時,先將所有參考影片的總時長無條件進位至整秒。計費秒數 = 輸出時長 + max(進位後的總時長, 輸出時長)。價格見模型頁。
POST
/
v1
/
videos
TASK_ID=$(curl https://api.apiko.app/v1/videos \
  -H "Authorization: Bearer $APIKO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "kling-4.0-flash",
  "duration": 5,
  "resolution": "720p",
  "aspect_ratio": "16:9",
  "prompt": "A street vendor at a night market looks up and says in a warm voice: \"Fresh noodles, hot and ready.\" Steam rises, neon signs reflect on wet pavement, handheld camera, one continuous shot."
}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')

while :; do
  TASK=$(curl -s https://api.apiko.app/v1/videos/$TASK_ID \
    -H "Authorization: Bearer $APIKO_API_KEY")
  printf '%s\n' "$TASK"
  printf '%s' "$TASK" | grep -qE '"status": *"(completed|failed)"|"error": *\{' && break
  sleep 5
done
{
  "id": "task_abc123",
  "object": "video",
  "model": "kling-4.0-flash",
  "status": "completed",
  "progress": 100,
  "video_url": "https://api.apiko.app/v1/tasks/task_abc123/artifacts/video/content?access=…"
}

鑑權

Authorization
string必填
所有請求都使用 Bearer 鑑權:Authorization: Bearer <API_KEY>。
在主控台 → API Keys 建立 Key。
Routes
string
  • POST /v1/videos — 建立影片任務
  • GET /v1/videos/{id} — 查詢任務並讀取 video_url
  • GET /v1/tasks/{id} — 以通用任務格式查詢同一任務

請求體

application/json
model
string預設:kling-4.0-flash必填
使用此公開模型 ID,原樣填寫。
可用選項: kling-4.0-flash
範例:"kling-4.0-flash"
prompt
string必填
影片描述。請在提示詞中寫出所需的對白和聲音。
最小長度: 1
最大長度: 8000
範例:"A paper boat drifting across a calm lake at sunrise"
aspect_ratio
enum<string>預設:adaptive
傳入首幀時,成片比例由首幀決定。
可用選項: adaptive, 16:9, 9:16, 1:1, 21:9
範例:"adaptive"
resolution
enum<string>預設:720p
影片輸出解析度,取值比對時不區分大小寫。
可用選項: 720p
範例:"720p"
duration
integer預設:5
輸出時長(秒),也可用 OpenAI 的 seconds 欄位。
影片長度,單位為秒。
範圍: 3 ≤ x ≤ 20
範例:5
first_image_url
string<uri>
一張首幀圖片的公開 HTTPS 位址。首幀和參考素材二選一。
  • 首幀決定成片比例。使用首幀時請單獨傳入。
  • 僅接受公開的 HTTPS URL;不接受檔案和 base64。
範例:"https://example.com/first-frame.png"
reference_image_urls
string<uri>[]
參考圖的公開 HTTPS 位址。寬和高均至少為 300 像素,寬高比須在 2:5 到 5:2 之間。
僅接受公開的 HTTPS URL;不接受檔案和 base64。
數量: 1–10
範例:["https://example.com/reference.png"]
reference_videos
string<uri>[]
參考影片的公開 HTTPS 位址。每段至少 3 秒,合計最多 20 秒。計費時長為輸出時長加上輸出時長與輸入總時長的較大值。提交時預扣輸出時長加 20 秒。
  • 每段至少 3 秒,合計最多 20 秒。提交時按輸出時長加 20 秒預扣;結算時將參考影片的總時長無條件進位至整秒。
  • 僅接受公開的 HTTPS URL;不接受檔案和 base64。
數量: 1–5
範例:["https://example.com/reference.mp4"]
callback_url
string<uri>
選填,接收任務完成通知的公開 HTTPS 位址。
  • 任務完成後,APIKO 會 POST 與 GET /v1/tasks/{id} 相同的 JSON,並帶請求頭 X-Apiko-Task-Id,最多重試 3 次。
  • 回調不帶簽名:請重新查詢任務確認結果。
範例:"https://your-domain.com/webhooks/apiko-task"

響應

200 - application/json

請求被接受時扣費;以 failed 結束的任務全額退款。

id
string
影片任務 ID。使用 GET /v1/videos/{id} 或 GET /v1/tasks/{id} 查詢。
範例:"task_abc123"
status
enum<string>
任務狀態。每 5~10 秒輪詢一次,直到變為 completed 或 failed。
可用選項: queued, in_progress, completed, failed
progress
integer
進度範圍為 0 到 100。
video_url
string<uri>
任務為 completed 時,GET /v1/videos/{id} 返回 APIKO 簽名連結,保留 24 小時。GET /v1/tasks/{id} 會在 data[0].url 返回同一連結。

錯誤

application/json

錯誤格式為 { "error": { "message", "type", "param", "code" } };大多數 message 末尾帶請求 id,聯繫支持時請提供。

400
error
請求無效。請修正請求後再試;該請求不會扣費。
  • 本頁未列出的欄位,例如 seed is not supported。
  • 取值超出列出的選項或範圍,例如 duration must be an integer from …。
  • 缺少或為空的 prompt(prompt is required)。
  • 參考 URL 不是公開 HTTPS 位址(… must be a public HTTPS URL)。
401
error
API Key 缺失或無效(Invalid token)。
403
error
餘額不足(code: "insufficient_user_quota")。請前往主控台 → Billing 充值。
404
error
GET /v1/videos/{id} 或 GET /v1/tasks/{id} 查詢不存在或屬於其他使用者的任務(Task not found)。
503
error
模型存在,但此刻沒有可用線路:No available channel for model …(code: "model_not_found")。請稍後以退避方式重試,或換一個模型。model 缺失或拼寫錯誤時回傳 404,訊息相同;這種情況請檢查模型 ID,不要重試。