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

  1. Đăng ký tài khoản miễn phí tại cp.aigate.id.vn
  2. Đăng nhập qua auth.truyennghe.edu.vn
  3. Vào Dashboard → API Keys → Tạo key mới
  4. 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ểuMô tả
promptstringMô tả nội dung muốn tạo (tiếng Việt OK)
aspect_ratiostring1:1, 16:9, 9:16, 4:3, 3:4
modelstringauto (rẻ nhất), flux, sdxl, dalle3
qualitystringstandard, hd (tốn 2.5× credits)
negative_promptstringNhững gì không muốn xuất hiện
seedintegerTái tạo cùng kết quả
webhook_urlstringURL nhận callback khi xong (cho job dài)

Mã lỗi thường gặp

HTTPÝ nghĩa
401invalid_keyAPI key sai hoặc đã bị thu hồi
402insufficient_creditsKhông đủ credits — nạp thêm
422invalid_promptPrompt vi phạm chính sách nội dung
429rate_limitQuá nhiều yêu cầu — chờ vài giây
500upstream_errorProvider 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