Tài liệu
Tài liệu API
Tạo ảnh đầu tiên của bạn trong bốn bước. API có tại https://api.cheapvids.com và mọi lệnh gọi đều cần khóa API của bạn.
Bắt đầu nhanh
1. Lấy khóa API
Khóa API được mở sau lần thanh toán USDT đầu tiên của bạn. Hãy tạo một khóa ở trang nhà phát triển trong tài khoản; khóa chỉ hiển thị một lần, nên hãy lưu vào biến môi trường. Giữ khóa trên máy chủ của bạn.
2. Tạo một tác vụ
Gửi mô hình, prompt và nhóm gói cần tính phí. Tham số plan là bắt buộc: "studio" hoặc "credits". Hệ thống không bao giờ tự chuyển nhóm thay bạn.
curl https://api.cheapvids.com/v1/generations \
-H "Authorization: Bearer $CHEAPVIDS_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"plan":"credits","model":"nano-banana-2","params":{"prompt":"A lighthouse at dusk"}}'3. Đọc kết quả
Chờ bằng ?wait=60 cho đến khi tác vụ hoàn tất, rồi tải tệp từ output.url. CheapVids chuyển tiếp kết quả trong một khoảng thời gian giới hạn sau khi hoàn tất (mặc định 24 giờ), vì vậy hãy tải về ngay.
curl "https://api.cheapvids.com/v1/generations/$GENERATION_ID?wait=60" \
-H "Authorization: Bearer $CHEAPVIDS_API_KEY"
# status "completed": download output.url right away
curl -L "$OUTPUT_URL" -o result.pngimport os, uuid, requests
API = "https://api.cheapvids.com/v1"
s = requests.Session()
s.headers["Authorization"] = f"Bearer {os.environ['CHEAPVIDS_API_KEY']}"
body = {"plan": "credits", "model": "nano-banana-2", "params": {"prompt": "A lighthouse at dusk"}}
r = s.post(f"{API}/generations", json=body, headers={"Idempotency-Key": str(uuid.uuid4())}, timeout=120)
r.raise_for_status()
job = r.json()
while job["status"] not in ("completed", "failed", "cancelled"):
r = s.get(f"{API}/generations/{job['id']}", params={"wait": 60}, timeout=90)
r.raise_for_status()
job = r.json()
if job["status"] == "completed":
r = s.get(f"{API}/generations/{job['id']}/content", timeout=120)
r.raise_for_status()
open("result.png", "wb").write(r.content)import { writeFile } from "node:fs/promises";
const API = "https://api.cheapvids.com/v1";
const auth = { Authorization: "Bearer " + process.env.CHEAPVIDS_API_KEY };
async function call(path, init = {}) {
const res = await fetch(API + path, { ...init, headers: { ...auth, ...init.headers } });
if (!res.ok) throw new Error(res.status + " " + (await res.text()));
return res;
}
const body = { plan: "credits", model: "nano-banana-2", params: { prompt: "A lighthouse at dusk" } };
let job = await (await call("/generations", {
method: "POST",
headers: { "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID() },
body: JSON.stringify(body),
})).json();
while (!["completed", "failed", "cancelled"].includes(job.status)) {
job = await (await call("/generations/" + job.id + "?wait=60")).json();
}
if (job.status === "completed") {
const res = await call("/generations/" + job.id + "/content");
await writeFile("result.png", Buffer.from(await res.arrayBuffer()));
}4. Hoặc nhận webhook
Đăng ký một endpoint HTTPS để nhận các sự kiện generation.started, generation.completed và generation.failed, được ký bằng HMAC-SHA256. Mỗi sự kiện được gửi tối đa 4 lần: lần gửi đầu và 3 lần thử lại sau 10, 60 và 300 giây.
X-CheapVids-Event: generation.completed
X-CheapVids-Delivery: 0190a1b2-0000-7000-8000-000000000001
X-CheapVids-Signature: t=1760000000,v1=64e08ed860b53ecdca19eb0ef68dccefd1c7f3135a0a0e273d34a878d48b8ed5
