Xác thực
Mọi yêu cầu gửi tới địa chỉ gốc dưới đây. Tạo API key ở trang API cho nhà phát triển (cần đăng nhập), rồi gửi kèm trong header X-API-Key hoặc Authorization: Bearer.
https://bestai.io.vn/api
curl https://bestai.io.vn/api/v1/models \ -H "X-API-Key: cmsnt_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- Key chỉ hiện đầy đủ một lần khi tạo. Mất key thì thu hồi và tạo key mới.
- Chỉ dùng key ở máy chủ của bạn, không nhúng vào mã chạy trên trình duyệt hay ứng dụng di động.
- Dữ liệu gửi và nhận ở dạng JSON (trừ API tải file dùng multipart/form-data).
Luồng gọi API
- Chọn model:
GET /v1/models— mỗi model có mã (id) nhưgpt-image-2,kling-2.6,seedream-5.0và danh sách tham số (params). - Gửi Input:
POST /v1/generationsvới{ "model": "...", ...tham số }— hệ thống trừ tiền và trả về id tác vụ. - Nhận Output:
GET /v1/generations/{id}mỗi 5–10 giây tới khi status là succeeded, rồi lấy link file trong output.files.
Mã model theo tên model gốc. Cùng một model có nhiều chế độ thì thêm tác vụ phía sau, vd kling-2.6/first-last-frame (ảnh đầu + ảnh cuối). Tham số đặt tên snake_case theo quy ước phổ biến: prompt, aspect_ratio, resolution, duration, image_url, voice...
Danh mục model
/v1/models?output=imageKhông cần keyDanh sách model đang mở bán. Lọc tuỳ chọn theo output (image | video | audio | text) hoặc type (nhóm menu).
/v1/models/{id}Không cần keyChi tiết một model với đầy đủ tham số đầu vào (danh sách lựa chọn dài như giọng đọc chỉ có ở API này).
{
"id": "gemini-image",
"object": "model",
"name": "Gemini Image · 2K/4K, khuyên dùng",
"type": "image",
"output": "image", // image | video | audio | text
"pricing": { "mode": "fixed", "base": 1500, "per_unit": 0, "unit": null, "min": 0, "currency": "VND" },
"params": [
{ "name": "prompt", "type": "string", "required": true, "description": "Mô tả", "max": 20000 },
{ "name": "aspect_ratio", "type": "enum", "required": false, "default": "1:1",
"options": [{ "value": "1:1", "label": "1:1" }, { "value": "16:9", "label": "16:9" }] },
{ "name": "image_url", "type": "file_url", "file_type": "image", "required": false, "description": "Ảnh mẫu" }
]
}Ý nghĩa các trường của params:
| Trường | Ý nghĩa |
|---|---|
| type | string · integer · number · boolean · enum · file_url (URL file, xem phần tải file) |
| required / default | Bắt buộc hay không, giá trị dùng khi bỏ trống. |
| options | Giá trị hợp lệ của enum (value gửi lên API, label là nhãn hiển thị). |
| min / max | Giới hạn số; với string là độ dài tối đa. |
| multiple / max_files | Tham số file nhận mảng nhiều URL. |
| only_if | Tham số chỉ có hiệu lực khi tham số khác có giá trị nằm trong danh sách. |
| options_by | Lựa chọn thay đổi theo giá trị tham số khác. |
| combinations | duration và resolution chỉ nhận các tổ hợp liệt kê ở đây. |
Input: tạo tác vụ
/v1/generationsBody là JSON phẳng: model + các tham số của model đó ở cùng cấp. Tham số sai tên hoặc không có trong params bị từ chối (400) để bạn phát hiện lỗi sớm.
curl -X POST https://bestai.io.vn/api/v1/generations \
-H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \
-d '{
"model": "gemini-image",
"prompt": "Một chú mèo phi hành gia",
"size": "1:1",
"n": "1"
}'Kết quả trả ngay đối tượng generation (status queued / processing). Tiền được trừ lúc tạo, lỗi thì tự hoàn lại.
Output: kết quả
/v1/generations/{id}Nhận id (uuid) hoặc mã tác vụ (code). Hỏi lại mỗi 5–10 giây cho tới khi status là succeeded, failed hoặc cancelled.
{
"id": "3f1c...-uuid",
"object": "generation",
"code": "T8KQ2M4X",
"model": "gemini-image",
"status": "succeeded",
"progress": 100,
"cost": 1500, // số tiền VND đã trừ
"currency": "VND",
"refunded": false,
"output": {
"type": "image",
"files": [{ "url": "https://bestai.io.vn/uploads/ai/outputs/....png", "type": "image", "name": "image.png" }],
"text": null // chỉ có với model trả văn bản
},
"error": null,
"created_at": "2026-10-30T08:00:00.000Z",
"completed_at": "2026-10-30T08:00:41.000Z"
}| status | Ý nghĩa |
|---|---|
| queued | Đã nhận, đang gửi sang máy chủ AI |
| processing | Đang xử lý; progress là phần trăm hoàn thành (nếu có) |
| succeeded | Xong; kết quả nằm trong output.files (và output.text) |
| failed | Lỗi; lý do ở error, tiền tự hoàn lại vào số dư (refunded = true) |
| cancelled | Đã huỷ, tiền được hoàn lại vào số dư |
Nên tải file kết quả về hệ thống của bạn: file trên máy chủ có thể được dọn sau một thời gian.
Báo giá
/v1/generations/estimateCùng body với tạo tác vụ, chỉ tính số tiền (VND) sẽ trừ, không chạy và không trừ tiền.
# => { "object": "estimate", "model": "gemini-image", "cost": 1500, "currency": "VND" }Tải file đầu vào
Tham số kiểu file_url (vd image_url, video_url, reference_image_urls) nhận một trong hai:
- Link công khai http(s) tới file (ảnh PNG/JPG/WEBP, video MP4/MOV/WEBM, âm thanh MP3/WAV/M4A) — máy chủ tự tải về, tối đa 10 file mỗi lần gọi.
- URL trả về từ API tải file dưới đây (file nằm trên máy tính / máy chủ của bạn).
/account/ai/uploadscurl -X POST https://bestai.io.vn/api/account/ai/uploads \
-H "X-API-Key: $API_KEY" \
-F "file=@./anh-mau.jpg"
# => { "url": "https://bestai.io.vn/uploads/ai/inputs/...", "name": "anh-mau.jpg", "mimeType": "image/jpeg", "size": 183204 }Lịch sử tác vụ
/v1/generations?page=1&limit=20&status=succeeded&model={id}Mới nhất trước, có phân trang: { "object": "list", "data": [...], "meta": { "total", "page", "limit", "totalPages" } }.
Số dư tài khoản
/account/credits{
"credits": 54000, // số dư ví hiện có (VND)
"concurrency": 3, // số tác vụ được chạy cùng lúc
"totalUsed": 126000, // tổng tiền đã dùng (VND)
...
}Lỗi & giới hạn
Lỗi trả mã HTTP 4xx/5xx kèm thông báo đọc được: { "statusCode": 400, "message": "...", "error": "Bad Request" }
| Mã | Ý nghĩa |
|---|---|
| 400 | Thiếu / sai tham số, tổ hợp không hợp lệ, số dư không đủ |
| 401 | Key sai, hết hạn hoặc đã thu hồi |
| 403 | Key không được gọi API này |
| 404 | Model hoặc tác vụ không tồn tại / model đang tạm dừng |
| 409 | Đang chạy quá số luồng của gói |
| 429 | Gọi quá nhanh, chờ rồi thử lại |
Giới hạn tốc độ: tạo tác vụ 20 lần/phút, báo giá và hỏi trạng thái 120 lần/phút, tải file 30 lần/phút.
Ví dụ hoàn chỉnh
Node.js (18+)
const BASE = "https://bestai.io.vn/api";
const headers = { "X-API-Key": process.env.API_KEY, "Content-Type": "application/json" };
async function call(path, init = {}) {
const res = await fetch(BASE + path, { ...init, headers });
const body = await res.json();
if (!res.ok) throw new Error(body.message);
return body;
}
// 1) gửi input
let gen = await call("/v1/generations", {
method: "POST",
body: JSON.stringify({"model":"gemini-image","prompt":"Một chú mèo phi hành gia","size":"1:1","n":"1"}),
});
// 2) hỏi trạng thái tới khi xong
while (["queued", "processing"].includes(gen.status)) {
await new Promise((r) => setTimeout(r, 5000));
gen = await call("/v1/generations/" + gen.id);
}
if (gen.status !== "succeeded") throw new Error(gen.error ?? gen.status);
console.log(gen.output.files.map((f) => f.url));Python 3
import os, time, requests
BASE = "https://bestai.io.vn/api"
H = {"X-API-Key": os.environ["API_KEY"]}
def call(method, path, **kw):
r = requests.request(method, BASE + path, headers=H, timeout=60, **kw)
body = r.json()
if not r.ok:
raise RuntimeError(body.get("message"))
return body
gen = call("POST", "/v1/generations", json={"model":"gemini-image","prompt":"Một chú mèo phi hành gia","size":"1:1","n":"1"})
while gen["status"] in ("queued", "processing"):
time.sleep(5)
gen = call("GET", f"/v1/generations/{gen['id']}")
if gen["status"] != "succeeded":
raise RuntimeError(gen.get("error") or gen["status"])
print([f["url"] for f in gen["output"]["files"]])Model hiện có
Bấm vào mã model để xem bảng Input (tham số, giá trị hỗ trợ) và Output của model đó.
| model | Tên | output | Tham số | Giá |
|---|---|---|---|---|
| edit-multi-2k | Sửa & Ghép Đa Ảnh AI 2K | image | image_url, image2_url, image3_url, image4_url, prompt, aspect, n | 99 ₫ / ảnh |
| gemini-3-pro-image/edit-2 | Gemini 3 Pro Image · chi tiết cao | image | image_urls, prompt, size | Theo tham số |
| gemini-3-pro-image/image | Gemini 3 Pro Image · chi tiết cao | image | prompt, size, n | Theo tham số |
| gemini-3.1-flash-image/edit-2 | Gemini 3.1 Flash Image · nhanh, nét | image | image_urls, prompt, size | Theo tham số |
| gemini-3.1-flash-image/image | Gemini 3.1 Flash Image · nhanh, nét | image | prompt, size, n | Theo tham số |
| gemini-3.1-flash-lite-image | Gemini 3.1 Flash Lite Image · siêu tốc | image | prompt, size, n | Theo tham số |
| gemini-3.1-flash-lite-image/edit | Gemini 3.1 Flash Lite Image · siêu tốc | image | image_urls, prompt, size | Theo tham số |
| gemini-image | Gemini Image · 2K/4K, khuyên dùng | image | prompt, size, n | Theo tham số |
| gemini-image/edit | Gemini Image · 2K/4K, khuyên dùng | image | image_urls, prompt, size | Theo tham số |
| gemini-nano-banana-2.1 | Gemini Nano Banana 2.1 · 2K/4K | image | prompt, size, n | Theo tham số |
| gemini-nano-banana-2.1/edit | Gemini Nano Banana 2.1 · 2K/4K | image | image_urls, prompt, size | Theo tham số |
| gpt-image-2-lowcost | GPT Image 2.0 -Ảnh AI Studio 4K | image | prompt, aspect_ratio, resolution, image_url, image2_url | Theo tham số |
| gpt-image-2.5-flare/edit-3 | GPT 2.5 Flare · chất lượng cao, nhanh | image | image_urls, prompt, size | Theo tham số |
| gpt-image-2.5-flare/image-2 | GPT Image 2.5 Flare - Chất lượng cao | image | prompt, size, n | Theo tham số |
| gpt-image-2.5-sunburst/edit-3 | GPT 2.5 Sunburst · sửa ảnh chính xác | image | image_urls, prompt, size | Theo tham số |
| gpt-image-2.5-sunburst/image-2 | GPT Image 2.5 Sunburst · Chính xác | image | prompt, size, n | Theo tham số |
| gpt-image-2.6-flare | GPT Image 2.6 Flare · tạo, sửa nhanh | image | prompt, size, n | Theo tham số |
| gpt-image-2.6-flare/edit | GPT 2.6 Flare · tạo, sửa nhanh | image | image_urls, prompt, size | Theo tham số |
| gpt-image-2.6-sunburst | GPT Image 2.6 Sunburst · nhiều chi tiết | image | prompt, size, n | Theo tham số |
| gpt-image-2.6-sunburst/edit | GPT 2.6 Sunburst · nhiều chi tiết | image | image_urls, prompt, size | Theo tham số |
| gpt-image-2/edit-3 | GPT 2 | image | image_urls, prompt, size | Theo tham số |
| gpt-image-2/image-3 | GPT Image 2 | image | prompt, size, n | Theo tham số |
| image-2k-eco | Tạo Ảnh AI Siêu Nét - Banana 2K | image | prompt, aspect, n | 79 ₫ / ảnh |
| muse-image/edit-2 | Muse | image | image_urls, prompt, size | Theo tham số |
| muse-image/image | Muse Image | image | prompt, size, n | Theo tham số |
| nano-2/image-outfit | Nano 2 | image | image_url, garment_url, outfit_part, background, prompt, aspect_ratio, resolution | Theo tham số |
| nano-banana2-lowcost | Nano Banana 2 Low-Cost (Ảnh AI 4K) | image | prompt, aspect_ratio, resolution, image_url, image2_url | Theo tham số |
| nano-image-to-image | Ghép & Chỉnh sửa Ảnh AI Nano Banana | image | image_url, image2_url, image3_url, image4_url, prompt, aspect, model_variant, n | 89 ₫ / ảnh |
| nano-pro/image-outfit | Nano Pro | image | image_url, garment_url, outfit_part, background, prompt, aspect_ratio, resolution | Theo tham số |
| nano-text-to-image | Tạo Ảnh AI Nano Banana | image | prompt, aspect, model_variant, n | 89 ₫ / ảnh |
| seedream-5.0 | Seedream 5.0 | image | prompt, reference_image_urls, aspect_ratio | Theo tham số |
| seedream-5.0/image-outfit | Seedream 5.0 | image | image_url, garment_url, outfit_part, background, prompt, aspect_ratio | Theo tham số |
| seedream-5.0/image-upscale | Seedream 5.0 | image | image_url, prompt | Theo tham số |
| virtual-tryon | Thay Đồ Ảnh AI · Giữ Nguyên Mặt & Nền | image | image_url, garment_url, outfit_part, background, aspect, n, prompt | 99 ₫ / ảnh |
| wf-upscale-ultra | Ultra Fast Upscale 4K | image | image_url | Theo tham số |
| google-omni-1.1-flash | Google Omni 1.1 Flash | video | prompt, image_urls, quality, duration, aspect_ratio, n | Theo tham số |
| grok-video-1.5 | Grok Video 1.5 | video | prompt, image_urls, quality, duration, aspect_ratio, n | Theo tham số |
| grok-video-3 | Grok Video · Grok Imagine Video 1.5 | video | image_url, prompt, duration, resolution | Theo tham số |
| grok-video/image-to-video | Grok Video · Grok Imagine Video 1.5 | video | image_url, prompt, duration, resolution | Theo tham số |
| image-to-video-1080p | Ảnh thành Video 1080p | video | image_url, image2_url, prompt, aspect, audio_mode | 888 ₫ |
| image-to-video-15s-1080p | Ảnh thành Video 1080p - 15s | video | image_url, image2_url, prompt, aspect, audio_mode | 1.250 ₫ |
| image-to-video-15s-720p | Ảnh thành Video 720p - 15s | video | image_url, image2_url, prompt, aspect, audio_mode | 999 ₫ |
| image-to-video-720p | Ảnh thành Video 720p | video | image_url, image2_url, prompt, aspect, audio_mode | 777 ₫ |
| kling-2.6 | Kling 2.6 Pro | video | image_url, prompt, duration, resolution | Theo tham số |
| kling-3.0 | Kling 3.0 Master | video | image_url, prompt, duration, resolution | Theo tham số |
| kling-4.0 | Kling 4.0 | video | image_url, prompt | Theo tham số |
| kling-4.0/kling1k-i2v | Kling 4.0 · 720p · 6s | video | image_url, prompt | Theo tham số |
| kling-4.0/kling1k-i2v-2 | Kling 4.0 · 1080p · 4s | video | image_url, prompt | Theo tham số |
| minimax-h3-enhanced | Minimax H3-RH Enhanced (Video 1080p • Tối đa 20s) | video | prompt, duration, aspect_ratio, resolution, image_url, image2_url, video_url, audio_url | Theo tham số |
| motion-photo-bg-10s | Motion Control Nền Ảnh 720p - Tối đa 10s | video | image_url, video_url | Theo tham số |
| motion-photo-bg-20s | Motion Control Nền Ảnh 720p - Tối đa 20s | video | image_url, video_url, text | Theo tham số |
| motion-v2 | Motion control V2 - Trên 10s | video | image_url, video_url, quality, duration, orientation, keep_audio | Theo tham số |
| text-to-video-1080p | Văn bản thành Video 1080p | video | prompt, aspect, audio_mode | 249 ₫ |
| text-to-video-15s-1080p | Văn bản thành Video 1080p - 15s | video | prompt, aspect, audio_mode | 1.250 ₫ |
| text-to-video-15s-720p | Văn bản thành Video 720p - 15s | video | prompt, aspect, audio_mode | 999 ₫ |
| text-to-video-720p | Văn bản thành Video 720p | video | prompt, aspect, audio_mode | 199 ₫ |
| vae-h3 | VAE H3 · Ảnh thành video (Có tiếng) | video | image_url, prompt, duration, resolution | Theo tham số |
| vae-motion-control-7 | VAE motion control 7 | video | duration, resolution, aspect_ratio, image_url, video_url, prompt | Theo tham số |
| vae-motion-control-8 | VAE motion control 8 (Khuyên dùng - Tạo video nét) | video | duration, resolution, aspect_ratio, image_url, video_url, prompt | Theo tham số |
| video-3 | Chuyển văn bản hoặc ảnh thành video | video | prompt, image_urls, duration, size | Theo tham số |
| eleven-speech | ElevenLabs Speech (Lồng Tiếng & Giọng Đọc AI ) | audio | prompt, voice | Theo tham số |
API cũ (vẫn hoạt động)
Tích hợp trước đây theo mã công cụ vẫn chạy bình thường: POST /account/ai/tools/{key}/run với { "input": {...} }, POST /account/ai/tools/{key}/quote, GET /account/ai/tasks/{id}. Danh mục mã công cụ: GET /public/ai/tools. Tích hợp mới nên dùng API /v1 ở trên.