POST
https://api.haiphongdeveloper.com/api/v1/image/generate
Endpoint tạo ảnh AI tốc độ cao. Cho phép truyền đồng thời câu lệnh Prompt và 1–3 ảnh mẫu đầu vào (input_images) để AI trích xuất đặc trưng và tạo tác phẩm chất lượng cao nhất.
Headers: Authorization: Bearer <YOUR_API_TOKEN> | Content-Type: application/json
Engine / Model: ken-image-hd (Tự động tối ưu qua 9Router Hub)
Bảng giá & Quy đổi: 0.08 Lúa (80 VNĐ) / lần tạo ảnh (1 Lúa = 1.000 VNĐ)
Tham số Body:
prompt: (String, bắt buộc) Câu lệnh mô tả bức ảnh muốn tạo.
input_images: (Array of Strings, tùy chọn) Mảng 1-3 ảnh đầu vào hỗ trợ cả Link URL hoặc Chuỗi Base64 Data URI (data:image/png;base64,...).
size: (String, tùy chọn) Kích thước ảnh: "1024x1024", "512x512", "1024x768", "768x1024", "2048x2048".
Cách 1: Python Gọi API với Link URL Ảnh (input_images):
import requests
url = "https://api.haiphongdeveloper.com/api/v1/image/generate"
headers = {
"Authorization": "Bearer YOUR_API_TOKEN",
"Content-Type": "application/json"
}
payload = {
"prompt": "A yellow pikachu character wearing sunglasses and riding a skateboard on sunny beach, anime 8k",
"input_images": [
"https://api.haiphongdeveloper.com/input_sample.png"
],
"size": "1024x1024"
}
response = requests.post(url, headers=headers, json=payload)
data = response.json()
print("Kết quả:", data["data"]["image_url"])
Cách 2: Python Gọi API Truyền File Ảnh Cục Bộ (Base64 Encode vào input_images):
import base64
import requests
# 1. Đọc và chuyển ảnh từ máy tính sang Base64
with open("my_character.png", "rb") as f:
base64_str = base64.b64encode(f.read()).decode("utf-8")
image_data_uri = f"data:image/png;base64,{base64_str}"
url = "https://api.haiphongdeveloper.com/api/v1/image/generate"
headers = {
"Authorization": "Bearer YOUR_API_TOKEN",
"Content-Type": "application/json"
}
# 2. Gửi Base64 trực tiếp vào mảng input_images
payload = {
"prompt": "A majestic golden dragon flying over ancient mountains in deep space, 8k ultra detailed",
"input_images": [
image_data_uri
],
"size": "1024x1024"
}
response = requests.post(url, headers=headers, json=payload)
print("Kết quả:", response.json()["data"]["image_url"])
Cách 3: Node.js (JavaScript) Đọc File Base64 & Gọi API:
const fs = require('fs');
const axios = require('axios');
async function generateWithLocalImage() {
const base64Img = fs.readFileSync('input.jpg').toString('base64');
const dataUri = `data:image/jpeg;base64,${base64Img}`;
const res = await axios.post('https://api.haiphongdeveloper.com/api/v1/image/generate', {
prompt: 'Chibi 3D cute character with soft cinematic lighting, 8k',
input_images: [dataUri],
size: '1024x1024'
}, {
headers: { 'Authorization': 'Bearer YOUR_API_TOKEN' }
});
console.log('Ảnh tạo thành công:', res.data.data.image_url);
}
generateWithLocalImage();
Cách 4: cURL Terminal (URL hoặc Base64):
curl -X POST 'https://api.haiphongdeveloper.com/api/v1/image/generate' \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"prompt": "A majestic dragon in space, 8k ultra detailed",
"input_images": [
"https://api.haiphongdeveloper.com/input_sample.png"
],
"size": "1024x1024"
}'