Bắt đầu nhanh
Tạo ảnh AI đầu tiên của bạn trong 60 giây. Mọi ngôn ngữ. Mọi platform.
Bước 1: Lấy API Key
- Đăng ký tài khoản miễn phí tại cp.aigate.id.vn
- Đăng nhập qua auth.truyennghe.edu.vn
- Vào Dashboard → API Keys → Tạo key mới
- Sao chép key (dạng
aig_xxxxxxxxxxxxxxxx)
⚠️ Lưu ý bảo mật: API key chỉ hiển thị một lần khi tạo. Hãy lưu vào file .env hoặc trình quản lý secret — không bao giờ commit vào git.
Bước 2: Gọi API đầu tiên
Tạo một ảnh từ prompt văn bản:
Bằng curl (terminal)
curl -X POST https://api.aigate.id.vn/v1/generate/image \
-H "Authorization: Bearer aig_YOUR_KEY_HERE" \
-H "Content-Type: application/json" \
-d '{
"prompt": "phong thủy ngôi nhà mặt tiền, ánh sáng vàng buổi sáng",
"aspect_ratio": "16:9",
"model": "auto"
}'
Phản hồi mẫu:
{
"ok": true,
"id": "img_a8b3f9c2",
"url": "https://cdn.aigate.id.vn/img/a8b3f9c2.png",
"credits_used": 10,
"credits_remaining": 90,
"model_used": "flux-schnell",
"duration_ms": 4231
}
Bằng JavaScript / Node.js
const resp = await fetch('https://api.aigate.id.vn/v1/generate/image', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.AIGATE_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'phong thủy ngôi nhà mặt tiền, ánh sáng vàng',
aspect_ratio: '16:9'
})
});
const data = await resp.json();
console.log('Ảnh tại:', data.url);
Bằng PHP
<?php
$ch = curl_init('https://api.aigate.id.vn/v1/generate/image');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AIGATE_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'phong thủy ngôi nhà mặt tiền',
'aspect_ratio' => '16:9',
]),
]);
$data = json_decode(curl_exec($ch), true);
echo "Ảnh tại: " . $data['url'];
Bằng Python
import os, requests
resp = requests.post(
'https://api.aigate.id.vn/v1/generate/image',
headers={'Authorization': f'Bearer {os.environ["AIGATE_KEY"]}'},
json={
'prompt': 'phong thủy ngôi nhà mặt tiền',
'aspect_ratio': '16:9'
}
)
print('Ảnh tại:', resp.json()['url'])
Bước 3: Kiểm tra số dư credits
curl https://api.aigate.id.vn/v1/account/balance \
-H "Authorization: Bearer aig_YOUR_KEY_HERE"
{
"balance": 90,
"tier": "free",
"expires_at": null
}
Tham số phổ biến
| Tham số | Kiểu | Mô tả |
|---|---|---|
prompt | string | Mô tả nội dung muốn tạo (tiếng Việt OK) |
aspect_ratio | string | 1:1, 16:9, 9:16, 4:3, 3:4 |
model | string | auto (rẻ nhất), flux, sdxl, dalle3… |
quality | string | standard, hd (tốn 2.5× credits) |
negative_prompt | string | Những gì không muốn xuất hiện |
seed | integer | Tái tạo cùng kết quả |
webhook_url | string | URL nhận callback khi xong (cho job dài) |
Mã lỗi thường gặp
| HTTP | Mã | Ý nghĩa |
|---|---|---|
| 401 | invalid_key | API key sai hoặc đã bị thu hồi |
| 402 | insufficient_credits | Không đủ credits — nạp thêm |
| 422 | invalid_prompt | Prompt vi phạm chính sách nội dung |
| 429 | rate_limit | Quá nhiều yêu cầu — chờ vài giây |
| 500 | upstream_error | Provider lỗi — thử lại sau 30s |
Tiếp theo
👉 Xác thực & quản lý API key — bảo mật key, tạo nhiều key, đặt giới hạn
👉 Tham chiếu sinh ảnh đầy đủ — tất cả tham số, models, examples