Tài liệu hướng dẫn tích hợp API
Tìm hiểu cách tích hợp hệ sinh thái AI của Kira vào các ứng dụng, SDK, và phần mềm của bên thứ ba.
1. Giới thiệu nền tảng Kira AI
Kira AI là cổng kết nối API tập trung, bảo mật và có hiệu năng cao, kết nối trực tiếp đến các dòng mô hình ngôn ngữ lớn (LLM) hàng đầu hiện nay. Nền tảng được tối ưu hóa chi phí vượt trội, cung cấp giải pháp kết nối White-Label thuần khiết giúp nhà phát triển dễ dàng tích hợp trí tuệ nhân tạo đa dạng vào ứng dụng của mình mà không bị giới hạn bởi một nhà cung cấp đơn lẻ.
Hệ thống hỗ trợ 2 phương thức giao tiếp chính: Trò chuyện trực tuyến (Web Client) trực tiếp trên trình duyệt và Cổng API kết nối ngoài tương thích hoàn toàn 100% với định dạng chuẩn OpenAI, giúp dễ dàng tích hợp và mở rộng các mô hình AI thông minh vào các phần mềm viết sẵn.
Kira AI cung cấp tệp cấu hình Skill tích hợp sẵn giúp các trợ lý AI lập trình của bạn (như Cursor, Cline, Roo Code, Claude Dev,...) hiểu rõ cấu trúc API, các model được hỗ trợ, và sinh mã kết nối chuẩn xác nhất.
Tải về file cấu hình Skill (kira-ai-api.zip)2. Quản lý API key & xác thực
Để tích hợp Kira AI vào các công cụ như Cursor, LibreChat, NextChat, OpenWebUI, Obsidian,... bạn cần tạo API Key tại tab Quản lý API key trong màn hình Console của tài khoản.
Tạo khóa API riêng cho từng ứng dụng, phân quyền mô hình và theo dõi lượt dùng token tại Console Lập trình viên.
- - API Base URL:
https://kiraai.vn/api/v1 - - Authorization Header:
Bearer KIRA_API_KEY_CUA_BAN - - Định danh Model:
kira-mini-1.0(Miễn phí),kira-3.5-pro,kira-3.5-flash,kira-2.5-pro,kira-2.5-flash,kira-3.0-image,kira-2.0-image,kira-3.0-video,kira-3.0-video-flash,kira-3.0-flash-tts,kira-2.0-flash-tts
3. Hướng dẫn sử dụng chat API
API chat hỗ trợ trò chuyện, phân tích dữ liệu, sinh code tự động. Bạn có thể sử dụng các thư viện SDK OpenAI của
bất cứ ngôn ngữ nào bằng cách đổi baseURL.
| Tên mô hình | Mã định danh (Model ID) | Thể loại | Biểu phí |
|---|
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://kiraai.vn/api/v1",
apiKey: "YOUR_KIRA_API_KEY"
});
const completion = await openai.chat.completions.create({
model: "kira-3.5-flash",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Xin chào Kira AI!" }
]
});
console.log(completion.choices[0].message.content);
4. Gửi hình ảnh cho model phân tích (Vision)
Các model hỗ trợ vision cho phép bạn gửi hình ảnh kèm theo tin nhắn để AI phân tích, mô tả hoặc trích xuất thông tin.
Kira AI hỗ trợ đầy đủ định dạng image_url theo chuẩn OpenAI, bao gồm cả URL công khai và base64.
Gửi trực tiếp liên kết ảnh từ internet (hỗ trợ JPG, PNG, GIF, WebP).
Gửi dữ liệu ảnh dạng data:image/jpeg;base64,... cho ảnh tải từ thiết bị.
Đính kèm đồng thời nhiều bức ảnh trong một lượt tin nhắn để phân tích, so sánh.
const completion = await openai.chat.completions.create({
model: "kira-3.5-flash",
messages: [
{
role: "user",
content: [
{ type: "text", text: "Mô tả chi tiết hình ảnh này" },
{
type: "image_url",
image_url: {
url: "https://example.com/photo.jpg"
}
}
]
}
]
});
console.log(completion.choices[0].message.content);
import fs from "fs";
// Đọc file ảnh và chuyển sang base64
const imageBuffer = fs.readFileSync("./photo.jpg");
const base64Image = imageBuffer.toString("base64");
const completion = await openai.chat.completions.create({
model: "kira-3.5-flash",
messages: [
{
role: "user",
content: [
{ type: "text", text: "Ảnh này chụp gì?" },
{
type: "image_url",
image_url: {
url: `data:image/jpeg;base64,${base64Image}`
}
}
]
}
]
});
import base64
from openai import OpenAI
client = OpenAI(
base_url="https://kiraai.vn/api/v1",
api_key="YOUR_KIRA_API_KEY"
)
# Cách 1: Gửi URL ảnh
response = client.chat.completions.create(
model="kira-3.5-flash",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Mô tả hình ảnh này"},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/photo.jpg"
}
}
]
}
]
)
print(response.choices[0].message.content)
5. Hướng dẫn tạo hình ảnh (Text-to-Image và Image-to-Image)
Hệ sinh thái tạo ảnh của Kira AI cung cấp khả năng sáng tạo hình ảnh nghệ thuật độ phân giải cao, hỗ trợ cả hai phương thức: tạo ảnh mới từ mô tả văn bản (Text-to-Image) và chỉnh sửa, biến đổi phong cách dựa trên ảnh mẫu (Image-to-Image) thông qua endpoint /images/generations.
5.1. Tạo hình ảnh từ mô tả văn bản (Text-to-Image)
Chuyển đổi ý tưởng sáng tạo bằng ngôn ngữ tự nhiên thành hình ảnh sống động với độ phân giải cao và chi tiết phong phú.
- - Mô hình:
kira-3.0-image(tốc độ cao, cực nhanh) hoặckira-2.0-image(ổn định lâu dài) - - Tỷ lệ ảnh (aspect_ratio):
"1:1","16:9","9:16","4:3","3:4" - - Định dạng trả về: Chuỗi base64 trong trường
data[0].b64_json(chuẩn PNG), có thể lưu trực tiếp thành tệp hình ảnh hoặc hiển thị trong thẻ HTML dạngdata:image/png;base64,....
curl -X POST https://kiraai.vn/api/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_KIRA_API_KEY" \
-d '{
"model": "kira-3.0-image",
"prompt": "A beautiful cyber-punk city in rain, neon light reflections, high resolution",
"aspect_ratio": "16:9"
}'
{
"created": 1726000000,
"model": "kira-3.0-image",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA... [chuỗi Base64 của ảnh]",
"mime_type": "image/png"
}
],
"description": null
}
import fs from "fs";
const response = await fetch("https://kiraai.vn/api/v1/images/generations", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_KIRA_API_KEY"
},
body: JSON.stringify({
model: "kira-3.0-image",
prompt: "A beautiful cyber-punk city in rain, neon light reflections, high resolution",
aspect_ratio: "16:9"
})
});
const result = await response.json();
const buffer = Buffer.from(result.data[0].b64_json, "base64");
fs.writeFileSync("output.png", buffer);
console.log("✅ Đã lưu hình ảnh vào output.png");
import requests
import base64
response = requests.post(
"https://kiraai.vn/api/v1/images/generations",
headers={"Authorization": "Bearer YOUR_KIRA_API_KEY"},
json={
"model": "kira-3.0-image",
"prompt": "A beautiful cyber-punk city in rain, neon light reflections, high resolution",
"aspect_ratio": "16:9"
}
)
data = response.json()
image_bytes = base64.b64decode(data["data"][0]["b64_json"])
with open("output.png", "wb") as f:
f.write(image_bytes)
print("✅ Đã lưu hình ảnh vào output.png")
5.2. Biến đổi và tạo hình ảnh từ ảnh mẫu (Image-to-Image)
Tính năng Image-to-Image cho phép bạn truyền một hoặc nhiều hình ảnh đầu vào (ảnh gốc, ảnh phác thảo, phối cảnh thiết kế) cùng với câu lệnh (prompt) để AI biến đổi phong cách nghệ thuật, chỉnh sửa chi tiết, thêm/bớt vật thể hoặc vẽ lại ảnh mới mà vẫn giữ nguyên bố cục của bức ảnh gốc.
- - Endpoint:
POST https://kiraai.vn/api/v1/images/generations - - Mô hình khuyến nghị:
kira-3.0-image(tốc độ cao) hoặckira-2.0-image - - reference_images: Mảng chứa các đối tượng ảnh tham chiếu. Mỗi đối tượng gồm:
mime_type: Định dạng ảnh (ví dụ:"image/jpeg","image/png","image/webp").data: Chuỗi ảnh đã mã hoá Base64 (chuỗi thuần, không bao gồm tiền tốdata:...;base64,).
- - prompt: Mô tả cách bạn muốn AI chỉnh sửa hoặc vẽ lại bức ảnh (ví dụ: "Biến bức ảnh này thành tranh vẽ sơn dầu cổ điển phong cách Phục Hưng").
- - aspect_ratio: Tùy chọn tỷ lệ khung hình đầu ra:
"1:1","16:9","9:16","4:3","3:4". - - Định dạng trả về: Chuỗi base64 trong
data[0].b64_json(ảnh PNG chuẩn).
curl -X POST https://kiraai.vn/api/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_KIRA_API_KEY" \
-d '{
"model": "kira-3.0-image",
"prompt": "Transform this portrait into an anime Cyberpunk warrior with glowing neon armor and futuristic city background",
"aspect_ratio": "1:1",
"reference_images": [
{
"mime_type": "image/jpeg",
"data": "/9j/4AAQSkZJRgABAQE... [chuỗi Base64 của ảnh gốc]"
}
]
}'
import fs from "fs";
const API_KEY = "YOUR_KIRA_API_KEY";
const BASE_URL = "https://kiraai.vn/api/v1";
// 1. Đọc file ảnh gốc và chuyển sang Base64
const imageBuffer = fs.readFileSync("input.jpg");
const base64Image = imageBuffer.toString("base64");
// 2. Gửi yêu cầu Image-to-Image
const response = await fetch(`${BASE_URL}/images/generations`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
model: "kira-3.0-image",
prompt: "Transform this room sketch into a luxury Scandinavian interior design with warm wooden furniture and morning sunlight",
aspect_ratio: "16:9",
reference_images: [
{
mime_type: "image/jpeg",
data: base64Image
}
]
})
});
const result = await response.json();
if (result.error) {
throw new Error(result.error.message || "Lỗi tạo ảnh");
}
// 3. Lưu ảnh kết quả mới ra file
const outputBuffer = Buffer.from(result.data[0].b64_json, "base64");
fs.writeFileSync("output_transformed.png", outputBuffer);
console.log("✅ Image-to-Image hoàn tất! Đã lưu file output_transformed.png");
import requests
import base64
API_KEY = "YOUR_KIRA_API_KEY"
BASE_URL = "https://kiraai.vn/api/v1"
# 1. Đọc và mã hoá ảnh đầu vào thành Base64
with open("input.jpg", "rb") as f:
base64_data = base64.b64encode(f.read()).decode("utf-8")
# 2. Gửi yêu cầu Image-to-Image
response = requests.post(
f"{BASE_URL}/images/generations",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"model": "kira-3.0-image",
"prompt": "Transform this sketch into a photorealistic 3D rendering with studio lighting",
"aspect_ratio": "16:9",
"reference_images": [
{
"mime_type": "image/jpeg",
"data": base64_data
}
]
}
)
result = response.json()
if "error" in result:
print(f"❌ Lỗi: {result['error']}")
else:
output_bytes = base64.b64decode(result["data"][0]["b64_json"])
with open("output_transformed.png", "wb") as f:
f.write(output_bytes)
print("✅ Image-to-Image hoàn tất! Đã lưu output_transformed.png")
6. Hướng dẫn sử dụng text to speech API (TTS)
API Text-to-Speech (TTS) của Kira AI cho phép bạn chuyển đổi văn bản viết thành các tệp âm thanh giọng nói tự
nhiên, chất lượng cao. API tương thích hoàn toàn với định dạng chuẩn OpenAI tại endpoint
/audio/speech.
- - API Endpoint:
POST https://kiraai.vn/api/v1/audio/speech - - Tham số body bắt buộc:
input(văn bản cần chuyển sang âm thanh),model(kira-3.0-flash-tts: tối ưu ngữ điệu & phát âm tiếng Việt chuẩn phòng thu hoặckira-2.0-flash-tts: tối ưu tốc độ phản hồi),voice(tên giọng đọc). - - Giọng đọc hỗ trợ (Kira voices):
Kore,Fenrir,Puck,Charon,Aoede. - * Hỗ trợ tự động map từ các giọng chuẩn của OpenAI:
alloy(Kore),echo(Fenrir),fable(Puck),onyx(Charon),nova(Aoede).
curl -X POST https://kiraai.vn/api/v1/audio/speech \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_KIRA_API_KEY" \
-d '{
"model": "kira-3.0-flash-tts",
"input": "Chào mừng bạn đến với hệ sinh thái trí tuệ nhân tạo Kira AI.",
"voice": "alloy"
}' --output output.mp3
import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://kiraai.vn/api/v1",
apiKey: "YOUR_KIRA_API_KEY"
});
const mp3 = await openai.audio.speech.create({
model: "kira-3.0-flash-tts",
voice: "alloy",
input: "Chào mừng bạn đến với hệ sinh thái trí tuệ nhân tạo Kira AI."
});
const buffer = Buffer.from(await mp3.arrayBuffer());
await fs.promises.writeFile("output.mp3", buffer);
console.log("✅ Đã lưu tệp âm thanh vào output.mp3");
# Cách 1: Sử dụng thư viện requests
import requests
response = requests.post(
"https://kiraai.vn/api/v1/audio/speech",
headers={"Authorization": "Bearer YOUR_KIRA_API_KEY"},
json={
"model": "kira-3.0-flash-tts",
"input": "Chào mừng bạn đến với hệ sinh thái trí tuệ nhân tạo Kira AI.",
"voice": "alloy"
}
)
with open("output.mp3", "wb") as f:
f.write(response.content)
print("✅ Đã lưu tệp âm thanh vào output.mp3")
# Cách 2: Sử dụng OpenAI SDK
# from openai import OpenAI
# client = OpenAI(base_url="https://kiraai.vn/api/v1", api_key="YOUR_KIRA_API_KEY")
# response = client.audio.speech.create(model="kira-3.0-flash-tts", voice="alloy", input="...")
# response.stream_to_file("output.mp3")
7. Hướng dẫn tạo video AI (Text-to-Video và Image-to-Video)
Kira AI hỗ trợ tạo video chuyển động nghệ thuật bằng trí tuệ nhân tạo thông qua cả hai hình thức: tạo video từ mô tả kịch bản văn bản (Text-to-Video) và tạo chuyển động từ hình ảnh tĩnh có sẵn (Image-to-Video).
kira-3.0-video
Dựng chuyển động video độ phân giải cao và chân thực từ kịch bản văn bản (tiến trình LRO kết xuất chuẩn cinematic).
kira-3.0-video-flash
Miễn phí
Mô hình video thế hệ mới, tốc độ xử lý siêu tốc, hỗ trợ tùy biến khung hình và thời lượng linh hoạt.
7.1. Tạo video từ mô tả văn bản (Text-to-Video)
Khởi tạo và kết xuất video nghệ thuật chuẩn MP4 từ câu lệnh kịch bản ngôn ngữ tự nhiên.
- - API Endpoint khởi tạo:
POST https://kiraai.vn/api/v1/videos/generations - - API Endpoint kiểm tra (Polling):
GET https://kiraai.vn/api/v1/videos/operations/:id - - Tham số body khởi tạo:
prompt(mô tả cảnh quay video),model(kira-3.0-videohoặckira-3.0-video-flash),aspect_ratio("16:9","9:16","1:1"- mặc định:"16:9"),duration_seconds(4,6,8- mặc định:6giây). - - Định dạng trả về: Tệp video định dạng MP4 (
video/mp4) được mã hoá Base64 trong trườngdata[0].b64_jsonkhi tác vụ hoàn thành (done: true).
POST /videos/generations để bắt đầu tác vụ và nhận về id (Operation ID).Bước 2: Gửi
GET /videos/operations/:id định kỳ (mỗi 5–10 giây) để kiểm tra trạng thái cho đến khi done: true rồi lưu video.
curl -X POST https://kiraai.vn/api/v1/videos/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_KIRA_API_KEY" \
-d '{
"model": "kira-3.0-video",
"prompt": "Drone shot flying over a futuristic cyberpunk city with neon waterfalls at sunset",
"aspect_ratio": "16:9",
"duration_seconds": 6
}'
{
"id": "7821992019481726000",
"status": "processing",
"created": 1726000000,
"model": "kira-3.0-video"
}
curl -X GET https://kiraai.vn/api/v1/videos/operations/7821992019481726000 \
-H "Authorization: Bearer YOUR_KIRA_API_KEY"
{
"id": "7821992019481726000",
"status": "completed",
"done": true,
"data": [
{
"b64_json": "AAAAIGZ0eXBpc29t... [chuỗi Base64 video MP4]",
"mime_type": "video/mp4"
}
]
}
import fs from "fs";
const API_KEY = "YOUR_KIRA_API_KEY";
const BASE_URL = "https://kiraai.vn/api/v1";
// 1. Khởi tạo tác vụ tạo video
console.log("🎬 Đang gửi yêu cầu tạo video...");
const initRes = await fetch(`${BASE_URL}/videos/generations`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
model: "kira-3.0-video",
prompt: "Drone shot flying over a futuristic cyberpunk city with neon waterfalls at sunset",
aspect_ratio: "16:9",
duration_seconds: 6
})
});
const initData = await initRes.json();
const operationId = initData.id;
console.log(`⏳ Đã nhận Operation ID: ${operationId}, đang tiến hành dựng video...`);
// 2. Định kỳ kiểm tra trạng thái mỗi 10 giây
while (true) {
await new Promise(resolve => setTimeout(resolve, 10000));
const checkRes = await fetch(`${BASE_URL}/videos/operations/${operationId}`, {
headers: { "Authorization": `Bearer ${API_KEY}` }
});
const statusData = await checkRes.json();
if (statusData.done) {
if (statusData.error) {
throw new Error(`Lỗi tạo video: ${statusData.error}`);
}
const videoBuffer = Buffer.from(statusData.data[0].b64_json, "base64");
fs.writeFileSync("output.mp4", videoBuffer);
console.log("✅ Video đã hoàn thành! Đã lưu tệp output.mp4");
break;
} else {
console.log("⏳ AI đang xử lý khung hình, vui lòng chờ...");
}
}
import requests
import base64
import time
API_KEY = "YOUR_KIRA_API_KEY"
BASE_URL = "https://kiraai.vn/api/v1"
headers = {"Authorization": f"Bearer {API_KEY}"}
# 1. Gửi yêu cầu khởi tạo video
print("🎬 Đang gửi yêu cầu tạo video...")
init_res = requests.post(
f"{BASE_URL}/videos/generations",
headers=headers,
json={
"model": "kira-3.0-video",
"prompt": "Drone shot flying over a futuristic cyberpunk city with neon waterfalls at sunset",
"aspect_ratio": "16:9",
"duration_seconds": 6
}
)
init_data = init_res.json()
operation_id = init_data.get("id")
print(f"⏳ Đã nhận Operation ID: {operation_id}. Đang tiến hành dựng video...")
# 2. Định kỳ kiểm tra trạng thái mỗi 10 giây
while True:
time.sleep(10)
poll_res = requests.get(f"{BASE_URL}/videos/operations/{operation_id}", headers=headers)
status_data = poll_res.json()
if status_data.get("done"):
if status_data.get("error"):
print(f"❌ Lỗi tạo video: {status_data.get('error')}")
break
video_bytes = base64.b64decode(status_data["data"][0]["b64_json"])
with open("output.mp4", "wb") as f:
f.write(video_bytes)
print("✅ Video đã dựng xong! Đã lưu tệp output.mp4")
break
else:
print("⏳ AI đang xử lý khung hình, vui lòng chờ thêm giây lát...")
7.2. Tạo video chuyển động từ hình ảnh tĩnh (Image-to-Video)
Tính năng Image-to-Video cho phép bạn cung cấp một bức ảnh tĩnh đầu vào (ảnh chụp chân dung, phong cảnh, sản phẩm thương mại hoặc nhân vật nghệ thuật) kết hợp với mô tả góc máy và chuyển động. AI sẽ giữ lại toàn vẹn thần thái, đường nét và phong cách của ảnh gốc, đồng thời thổi sức sống vào bức ảnh bằng các chuyển động mượt mà, chân thực ở định dạng video MP4.
- - API Endpoint khởi tạo:
POST https://kiraai.vn/api/v1/videos/generations - - API Endpoint kiểm tra (Polling):
GET https://kiraai.vn/api/v1/videos/operations/:id - - Mô hình hỗ trợ:
kira-3.0-videohoặckira-3.0-video-flash - - reference_images: Mảng chứa đối tượng ảnh tĩnh đầu vào:
mime_type: Định dạng ảnh ("image/jpeg","image/png","image/webp").data: Chuỗi Base64 thuần túy của bức ảnh cần tạo chuyển động.
- - prompt: Mô tả hướng chuyển động của máy quay hoặc hành động nhân vật (ví dụ: "Cinematic slow motion, camera orbits around the model, wind blowing through hair, realistic lighting").
- - duration_seconds: Thời lượng video:
4,6, hoặc8giây (mặc định:6). - - aspect_ratio: Tỷ lệ khung hình:
"16:9","9:16","1:1"(nên đặt khớp với tỷ lệ của ảnh gốc). - - Định dạng trả về: Tệp video MP4 (
video/mp4) dạng Base64 trongdata[0].b64_jsonkhidone: true.
curl -X POST https://kiraai.vn/api/v1/videos/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_KIRA_API_KEY" \
-d '{
"model": "kira-3.0-video-flash",
"prompt": "Camera pans slowly across the landscape, clouds drifting gracefully across the sky, cinematic lighting, 4k ultra realistic",
"aspect_ratio": "16:9",
"duration_seconds": 6,
"reference_images": [
{
"mime_type": "image/jpeg",
"data": "/9j/4AAQSkZJRgABAQE... [chuỗi Base64 của ảnh gốc]"
}
]
}'
import fs from "fs";
const API_KEY = "YOUR_KIRA_API_KEY";
const BASE_URL = "https://kiraai.vn/api/v1";
// 1. Đọc ảnh tĩnh đầu vào và chuyển sang Base64
const imageBuffer = fs.readFileSync("photo.jpg");
const base64Photo = imageBuffer.toString("base64");
console.log("🎬 Đang gửi ảnh và khởi tạo tác vụ Image-to-Video...");
const initRes = await fetch(`${BASE_URL}/videos/generations`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
model: "kira-3.0-video-flash",
prompt: "Cinematic slow camera zoom in, subject subtly smiles, natural eye blinking, gentle breeze moving hair, high production quality",
aspect_ratio: "16:9",
duration_seconds: 6,
reference_images: [
{
mime_type: "image/jpeg",
data: base64Photo
}
]
})
});
const initData = await initRes.json();
if (initData.error) {
throw new Error(initData.error.message || "Lỗi khởi tạo video");
}
const operationId = initData.id;
console.log(`⏳ Đã nhận Operation ID: ${operationId}, đang render video từ ảnh mẫu...`);
// 2. Polling kiểm tra trạng thái mỗi 10 giây
while (true) {
await new Promise(resolve => setTimeout(resolve, 10000));
const checkRes = await fetch(`${BASE_URL}/videos/operations/${operationId}`, {
headers: { "Authorization": `Bearer ${API_KEY}` }
});
const statusData = await checkRes.json();
if (statusData.done) {
if (statusData.error) {
throw new Error(`Lỗi tạo video: ${statusData.error}`);
}
const videoBuffer = Buffer.from(statusData.data[0].b64_json, "base64");
fs.writeFileSync("output_image_to_video.mp4", videoBuffer);
console.log("✅ Image-to-Video đã hoàn thành! Đã lưu tệp output_image_to_video.mp4");
break;
} else {
console.log("⏳ AI đang xử lý khung hình chuyển động từ ảnh...");
}
}
import requests
import base64
import time
API_KEY = "YOUR_KIRA_API_KEY"
BASE_URL = "https://kiraai.vn/api/v1"
headers = {"Authorization": f"Bearer {API_KEY}"}
# 1. Đọc ảnh tĩnh thành Base64
with open("photo.jpg", "rb") as f:
photo_base64 = base64.b64encode(f.read()).decode("utf-8")
# 2. Gửi yêu cầu khởi tạo Image-to-Video
print("🎬 Đang gửi ảnh và bắt đầu tạo video...")
init_res = requests.post(
f"{BASE_URL}/videos/generations",
headers=headers,
json={
"model": "kira-3.0-video-flash",
"prompt": "Gentle cinematic camera motion, natural fluid movement, realistic depth of field, 4k",
"aspect_ratio": "16:9",
"duration_seconds": 6,
"reference_images": [
{
"mime_type": "image/jpeg",
"data": photo_base64
}
]
}
)
init_data = init_res.json()
if "error" in init_data:
print(f"❌ Lỗi: {init_data['error']}")
exit(1)
operation_id = init_data["id"]
print(f"⏳ Operation ID: {operation_id}. Đang xử lý chuyển động video...")
# 3. Polling kiểm tra kết quả
while True:
time.sleep(10)
poll_res = requests.get(f"{BASE_URL}/videos/operations/{operation_id}", headers=headers)
status_data = poll_res.json()
if status_data.get("done"):
if status_data.get("error"):
print(f"❌ Lỗi tạo video: {status_data.get('error')}")
break
video_bytes = base64.b64decode(status_data["data"][0]["b64_json"])
with open("output_image_to_video.mp4", "wb") as f:
f.write(video_bytes)
print("✅ Video đã render xong! Đã lưu output_image_to_video.mp4")
break
else:
print("⏳ Đang dựng video từ ảnh, vui lòng chờ...")
8. Hướng dẫn cấu hình Kira AI cho Codex (CLI & Desktop app)
Codex (bao gồm Codex CLI và Codex Desktop app) là trợ lý lập trình chuyên sâu của OpenAI, cho phép đọc hiểu toàn bộ workspace, phân tích codebase, tự động sinh code, tạo và chỉnh sửa file, cũng như thực thi lệnh shell trực tiếp.
Kira AI cung cấp cổng kết nối chuẩn OpenAI Responses API (endpoint /api/v1/responses), hỗ trợ đầy đủ Server-Sent Events (SSE) streaming và cơ chế tool calling native/custom, giúp Codex hoạt động mượt mà và tự động thao tác file chính xác 100%.
Mở tệp cấu hình của Codex tại đường dẫn ~/.codex/config.toml (trên macOS / Linux: ~/.codex/config.toml, trên Windows: %USERPROFILE%\.codex\config.toml) và thêm cấu hình nhà cung cấp Kira AI:
# Khai báo nhà cung cấp mặc định (viết thường toàn bộ: "kiraai")
model_provider = "kiraai"
model = "gpt-5.6-sol" # Khuyên dùng: gpt-5.6-sol, gpt-5.6-luna hoặc gpt-oss-120b
model_reasoning_effort = "medium"
approval_policy = "never"
# Định nghĩa provider Kira AI kết nối qua Responses API
[model_providers.kiraai]
name = "kiraai"
base_url = "https://kiraai.vn/api/v1"
wire_api = "responses"
env_key = "OPENAI_API_KEY"
# Cấp quyền tin cậy cho thư mục dự án (để Codex tự động tạo file và chạy lệnh shell)
[projects."/duong/dan/den/thu/muc/du/an"]
trust_level = "trusted"
Lấy API key tại trang quản trị Kira AI (dạng kira_...) và lưu vào hệ thống:
# Thêm biến môi trường vào ~/.zshrc (hoặc ~/.bashrc)
echo 'export OPENAI_API_KEY="kira_api_key_cua_ban"' >> ~/.zshrc
source ~/.zshrc
// Mở tệp ~/.codex/auth.json và dán nội dung:
{
"OPENAI_API_KEY": "kira_api_key_cua_ban"
}
model_provider = "kiraai" phải viết thường 100%, khớp chính xác với tiêu đề section [model_providers.kiraai].approval_policy = "never" để Codex tự động thực thi các công cụ (tạo file, chạy lệnh terminal) mà không bị treo do chờ phê duyệt thủ công.[projects."/duong/dan/thu/muc"] với trust_level = "trusted" cho thư mục bạn đang làm việc để mở khóa toàn bộ quyền thao tác file.config.toml hoặc thêm API key.9. Hướng dẫn User Management API (quản trị tài khoản)
Bộ RESTful Management API v1 cho phép lập trình viên tự động hóa việc kiểm tra số dư VND/Token, tạo & quản lý khóa API Key, và tra cứu chi tiết Lịch sử sử dụng tiêu thụ token một cách nhanh chóng.
/api/auth/login): Có toàn quyền (bao gồm Tạo/Sửa/Xóa API Key).- API Key phụ (
kira_...): Dùng đọc số dư (/profile), tra cứu lịch sử tiêu dùng (/usage/logs) và gọi AI.
Gửi yêu cầu GET đến /api/v1/user/profile để nhận số dư VND, số dư Token, hạn mức ngày và lượng token đã dùng trong ngày:
curl -X GET https://kiraai.vn/api/v1/user/profile \
-H "Authorization: Bearer YOUR_API_KEY_HOAC_JWT"
Gửi yêu cầu GET đến /api/v1/user/usage/logs (hỗ trợ tham số page, limit, key_id, model) để lấy danh sách tiêu tốn token tương tự bảng lịch sử trên website:
const res = await fetch('https://kiraai.vn/api/v1/user/usage/logs?page=1&limit=20', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
const data = await res.json();
console.log(data.logs); // Mảng chi tiết: timestamp, model, prompt_tokens, completion_tokens, tokens_used, cost_vnd...
- Danh sách key: GET /api/v1/user/keys
- Tạo key mới: POST /api/v1/user/keys (Body: {"name": "Key Zalo Bot"})
- Sửa tên / Đổi trạng thái: PATCH /api/v1/user/keys/:id (Body: {"status": "inactive"})
- Xóa key: DELETE /api/v1/user/keys/:id
curl -X POST https://kiraai.vn/api/v1/user/keys \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "App Mobile Key"}'
10. Tài liệu API bổ trợ (mô hình & giọng đọc)
Kira AI cung cấp các API bổ trợ hữu ích giúp bạn truy vấn động Danh sách mô hình đang hoạt động và danh sách giọng đọc của hệ thống Text-to-Speech (TTS).
Gửi yêu cầu GET đến endpoint /models để nhận về mảng chứa cấu hình chi tiết của tất cả mô hình
bao gồm: ID, tên hiển thị, thể loại, trạng thái và đơn giá:
Tra cứu context window, trạng thái hoạt động (uptime), biểu phí token và nhà phân phối của từng mô hình.
curl -X GET https://kiraai.vn/api/v1/models \
-H "Authorization: Bearer YOUR_KIRA_API_KEY"
Gửi yêu cầu GET đến endpoint /audio/voices để nhận về danh sách giọng đọc được hỗ trợ cùng thông
tin mô tả chi tiết ngôn ngữ, giới tính:
| Tên giọng đọc | Mã Voice ID (OpenAI) | Giọng gốc (Kira) | Giới tính & vùng miền |
|---|---|---|---|
|
Alloy
|
alloy
|
Kore
|
Nữ (Bắc) |
|
Echo
|
echo
|
Fenrir
|
Nam (Bắc) |
|
Fable
|
fable
|
Puck
|
Nữ (Nam) |
|
Onyx
|
onyx
|
Charon
|
Nam (Nam) |
|
Nova
|
nova
|
Aoede
|
Nữ (Bắc) |
|
Shimmer
|
shimmer
|
Kore
|
Nữ (Bắc) |
curl -X GET https://kiraai.vn/api/v1/audio/voices