Trùm AI

Dành cho nhà phát triển

Tài liệu API

Gọi tạo video từ tool, web bán lại, n8n/Make hay script của bạn. Trừ tiền vào cùng số dư ví như trên web, giá y hệt bảng giá. Có webhook báo kết quả, chống trùng đơn, giới hạn IP & trần chi tiêu cho từng key.

✓ Webhook ký HMAC — không cần hỏi trạng thái liên tục✓ Idempotency-Key chống trừ tiền 2 lần✓ Lỗi hệ thống tự hoàn 100%✓ … model, 1 mã gọi duy nhất — không phải chọn server

Bắt đầu nhanh

  1. Tạo API key ở cuối trang này (cần đăng nhập, đã xác thực email).
  2. Xem danh mục model & tham số: GET /models (không cần key).
  3. Tạo đơn: POST /videos kèm callback_url để nhận kết quả tự động.
  4. Hoặc hỏi trạng thái GET /videos/{id} mỗi 5–10 giây tới khi succeeded / failed.

Địa chỉ gốc:

https://your-domain.vn/api/v1

Xác thực

Gửi key trong header X-API-Key hoặc Authorization: Bearer. Dữ liệu gửi/nhận dạng JSON.

curl https://your-domain.vn/api/v1/account -H "X-API-Key: vk_live_xxxxxxxx"

curl https://your-domain.vn/api/v1/account -H "Authorization: Bearer vk_live_xxxxxxxx"

Danh mục model & bảng giá

GET/models· không cần key · cache 60 giây

GET/models/{id}· chi tiết 1 model

POST/estimate· báo giá, không trừ tiền · cùng body với tạo video

Bảng dưới đây lấy trực tiếp từ API (giá thực tế đang áp dụng):

modeldurationaspect_ratiomedia.roleGiá
Đang tải…
curl -X POST https://your-domain.vn/api/v1/estimate -H "Content-Type: application/json" \
  -d '{"model":"kling4-std","prompt":"test","duration":5}'
# => {"object":"estimate","model":"kling4-std","cost":800,"currency":"VND","valid":true,"error":null}

Tạo video

POST/videos· trừ tiền lúc tạo · lỗi hệ thống tự hoàn

modelbắt buộcMã model ở GET /models
promptbắt buộcMô tả, 3–2.500 ký tự (tiếng Việt hoặc tiếng Anh)
durationtuỳ modelSố giây — phải nằm trong params.duration.options (nhận cả tên seconds)
aspect_ratiotuỳ chọn16:9 · 9:16 · 1:1 … theo model. Video từ ảnh: chọn khớp chiều ảnh
orientationtuỳ chọnFULL | HALF — chỉ model bắt chước chuyển động
mediatuỳ model[{ "role": "first_frame", "url": "…" }] — url lấy từ POST /uploads
callback_urltuỳ chọnhttps://… — nhận webhook khi đơn xong / lỗi
Idempotency-KeyheaderMã đơn của bạn. Gửi lại cùng mã → trả đúng đơn cũ, không trừ tiền 2 lần
curl -X POST https://your-domain.vn/api/v1/videos \
  -H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-20261205-001" \
  -d '{
    "model": "kling4-std",
    "prompt": "Cô gái mặc áo dài đi dạo phố cổ lúc hoàng hôn, máy quay tiến chậm",
    "duration": 5,
    "aspect_ratio": "9:16",
    "callback_url": "https://tool-cua-ban.vn/webhook/video"
  }'

# => 201
{ "id": "b195f7a1-…", "object": "video", "model": "kling4-std", "status": "queued",
  "progress": 0, "cost": 800, "currency": "VND", "output": null, "error": null, … }

Video từ ảnh: tải ảnh lên trước (POST /uploads) rồi đưa url vào media.

Nhận kết quả

GET/videos/{id}

GET/videos?page=1&limit=20&status=succeeded· lịch sử, mới nhất trước

queuedĐã nhận, đang xếp hàng gửi đi
processingĐang render — progress là % hoàn thành
succeededXong — link MP4 ở output.url (chỉ lưu 3 giờ — xem expires_at, hãy tải về hệ thống của bạn ngay)
failedLỗi — error.code: system_error (đã hoàn tiền) · invalid_input (đã hoàn tiền) · content_policy (KHÔNG hoàn)
{
  "id": "b195f7a1-…", "object": "video", "model": "kling4-std",
  "status": "succeeded", "progress": 100, "cost": 800, "currency": "VND", "refunded": false,
  "idempotency_key": "order-20261205-001",
  "output": { "url": "https://…/outputs/2026-12-05/b195f7a1-….mp4", "expires_at": "2026-12-08T…" },
  "error": null, "created_at": "…", "completed_at": "…"
}

Webhook (khuyên dùng)

Truyền callback_url khi tạo đơn → khi đơn succeeded hoặc failed, hệ thống POST về địa chỉ đó (body giống GET /videos/{id}). Server của bạn trả HTTP 2xx là xong; nếu lỗi sẽ gửi lại tối đa 6 lần (30 giây → ~16 phút).

Mỗi webhook có chữ ký X-Webhook-Signature = sha256=HMAC_SHA256(webhook_secret, timestamp + "." + body) và X-Webhook-Timestamp. Luôn kiểm chữ ký trước khi tin dữ liệu:

// Node.js (Express) — dùng express.text({ type: '*/*' }) để giữ nguyên body gốc
import crypto from "node:crypto";
app.post("/webhook/video", express.text({ type: "*/*" }), (req, res) => {
  const ts = req.get("X-Webhook-Timestamp");
  const expected = "sha256=" + crypto.createHmac("sha256", process.env.WEBHOOK_SECRET)
    .update(ts + "." + req.body).digest("hex");
  if (req.get("X-Webhook-Signature") !== expected || Math.abs(Date.now() / 1000 - ts) > 300)
    return res.status(401).end();
  const { event, data } = JSON.parse(req.body); // event: video.succeeded | video.failed
  // … lưu data.output.url …
  res.sendStatus(200);
});
# Python (Flask)
import hmac, hashlib, os, time
@app.post("/webhook/video")
def hook():
    ts = request.headers["X-Webhook-Timestamp"]
    body = request.get_data(as_text=True)
    expected = "sha256=" + hmac.new(os.environ["WEBHOOK_SECRET"].encode(), f"{ts}.{body}".encode(), hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, request.headers["X-Webhook-Signature"]) or abs(time.time() - int(ts)) > 300:
        return "", 401
    payload = request.get_json()
    return "", 200

callback_url phải là https và trỏ tới địa chỉ công khai (không nhận localhost / IP nội bộ).

Tải file đầu vào (ảnh / video / âm thanh)

POST/uploads· trả link tải lên có hạn 10 phút

JPG, PNG, WEBP, MP4, MP3, WAV — tối đa 50MB/file. Bước 1 xin link, bước 2 PUT file lên đúng link đó, bước 3 dùng url trong media.

# 1) Xin link tải lên
curl -X POST https://your-domain.vn/api/v1/uploads -H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \
  -d '{"content_type":"image/jpeg","size":183204}'
# => {"upload_url":"https://…","method":"PUT","headers":{"content-type":"image/jpeg"},"url":"https://…/inputs/….jpg","expires_in":600}

# 2) Đẩy file lên
curl -X PUT "<upload_url>" -H "Content-Type: image/jpeg" --data-binary @anh-mau.jpg

# 3) Dùng url ở bước 1 trong media
"media": [{ "role": "first_frame", "url": "https://…/inputs/….jpg" }]

Số dư & số luồng chạy song song

GET/account

{
  "object": "account", "currency": "VND", "balance": 254000, "held": 1600,
  "concurrency": { "limit": 6, "running": 2 },
  "key": { "name": "Tool render", "prefix": "vk_live_QG2n", "daily_limit": 500000, "spent_today": 12800 }
}

Mỗi tài khoản chạy song song tối đa 6 video (web + API cộng chung). Đơn thứ 7 trả 429 too_many_jobs — hãy xếp hàng phía tool và gửi tiếp khi có đơn xong. Cần nhiều luồng hơn cho dự án lớn? Liên hệ để nâng gói.

Lỗi & giới hạn

Lỗi trả mã HTTP kèm JSON: { "error": "thông báo tiếng Việt", "code": "mã_máy_đọc" }

400—Thiếu / sai kiểu dữ liệu
401invalid_api_keyKey sai hoặc đã thu hồi
402insufficient_creditSố dư không đủ
403ip_not_allowed · account_lockedIP không nằm trong danh sách của key · tài khoản bị khoá
404model_not_found · not_foundModel hoặc đơn không tồn tại
409busyĐang xử lý 1 yêu cầu khác của tài khoản — thử lại sau 1 giây
422invalid_params · content_blocked · invalid_callback_urlTham số sai luật model · nội dung bị chặn trước khi gửi (không mất tiền)
429too_many_jobs · daily_limit · key_daily_limit · rate_limitedQuá số luồng · quá giới hạn ngày · key chạm trần chi tiêu · gọi quá nhanh
503capacityHệ thống đang quá tải, thử lại sau ít phút

Tần suất: tạo đơn 120 lần/phút/key · hỏi trạng thái 3.000 lần/phút/key · tải file 360 lần/phút/key.

Ví dụ hoàn chỉnh

// Node.js 18+
const BASE = "https://your-domain.vn/api/v1";
const H = { "X-API-Key": process.env.API_KEY, "Content-Type": "application/json" };

async function call(path, init = {}) {
  const res = await fetch(BASE + path, { ...init, headers: { ...H, ...(init.headers || {}) } });
  const body = await res.json();
  if (!res.ok) throw new Error(`[${res.status} ${body.code ?? ""}] ${body.error}`);
  return body;
}

let v = await call("/videos", {
  method: "POST",
  headers: { "Idempotency-Key": "order-demo-001" },
  body: JSON.stringify({ model: "kling4-std", prompt: "Chú mèo phi hành gia trên mặt trăng", duration: 5, aspect_ratio: "16:9" }),
});
while (v.status === "queued" || v.status === "processing") {
  await new Promise((r) => setTimeout(r, 5000));
  v = await call("/videos/" + v.id);
}
if (v.status !== "succeeded") throw new Error(v.error?.message);
console.log(v.output.url);
# Python 3
import os, time, requests
BASE = "https://your-domain.vn/api/v1"
H = {"X-API-Key": os.environ["API_KEY"]}

def call(method, path, **kw):
    r = requests.request(method, BASE + path, headers={**H, **kw.pop("headers", {})}, timeout=60, **kw)
    body = r.json()
    if not r.ok:
        raise RuntimeError(f"[{r.status_code} {body.get('code','')}] {body.get('error')}")
    return body

v = call("POST", "/videos", headers={"Idempotency-Key": "order-demo-001"},
         json={"model": "kling4-std", "prompt": "Chú mèo phi hành gia trên mặt trăng", "duration": 5, "aspect_ratio": "16:9"})
while v["status"] in ("queued", "processing"):
    time.sleep(5)
    v = call("GET", f"/videos/{v['id']}")
print(v["output"]["url"] if v["status"] == "succeeded" else v["error"])

Bảo mật key

  • Key chỉ hiện 1 lần khi tạo — hệ thống chỉ lưu bản băm, nhân viên cũng không xem được.
  • Chỉ dùng key ở máy chủ của bạn. Không nhúng vào web chạy trên trình duyệt / app điện thoại (request từ trình duyệt web khác sẽ bị chặn).
  • Đặt danh sách IP và trần chi tiêu/ngày cho từng key — lỡ lộ key cũng không mất quá số tiền bạn cho phép.
  • Nghi lộ key? Bấm Thu hồi — có hiệu lực ngay lập tức, rồi tạo key mới.

API key của bạn

Đăng nhập hoặc tạo tài khoản để lấy API key.