Đưa tăng cường ảnh AI vào sản phẩm của bạn
REST API cho tăng cường AI (làm mịn da, phóng to, tự động nâng cấp, xóa nền) với webhook outbound. Xác thực bằng API key và nhận sự kiện đã ký khi job hoàn tất.
Xác thực
Mọi request được xác thực bằng API key gửi trong header x-api-key . Tạo và quản lý key trong dashboard. Key chỉ hiện đầy đủ một lần — hãy lưu an toàn.
curl https://pickimg.com/api/ai/enhance \
-H "x-api-key: pk_xxxxxxxx.your_secret_here"Tăng cường AI
/api/ai/enhanceTạo job tăng cường/api/ai/enhance/:idLấy trạng thái & kết quả job/api/ai/enhanceLiệt kê job của bạnThao tác: smooth_skin, upscale, auto_enhance, bg_remove. level: low | medium | high.
curl -X POST https://pickimg.com/api/ai/enhance \
-H "x-api-key: pk_xxxxxxxx.your_secret_here" \
-H "Content-Type: application/json" \
-d '{
"sourceUrl": "https://cdn.example.com/photo.jpg",
"operation": "smooth_skin",
"level": "medium"
}'
# Response
{ "id": "job_123", "status": "queued", "operation": "smooth_skin" }// Node.js
const res = await fetch("https://pickimg.com/api/ai/enhance", {
method: "POST",
headers: {
"x-api-key": process.env.PICKIMG_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({ sourceUrl, operation: "upscale" }),
});
const job = await res.json();Webhook
Đăng ký endpoint để nhận sự kiện khi job hoàn tất. Mỗi lần gửi đều được ký để bạn xác minh tính xác thực.
/api/webhooks/eventsLiệt kê loại sự kiện/api/webhooks/endpointsTạo endpoint/api/webhooks/deliveriesXem các lần gửiSự kiện: enhancement.queued, enhancement.completed, enhancement.failed, image.uploaded, quota.exceeded, ping.
Xác minh chữ ký
Mỗi lần gửi kèm header X-PickIMG-Signature theo định dạng t=<timestamp>,v1=<hmac>, trong đó HMAC-SHA256 được tính trên <timestamp>.<raw-body>.
import crypto from "crypto";
function verify(rawBody, header, secret) {
const [t, v1] = header.split(",").map((p) => p.split("=")[1]);
const expected = crypto
.createHmac("sha256", secret)
.update(`${t}.${rawBody}`)
.digest("hex");
return crypto.timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}Giới hạn tốc độ & hạn mức
Request và số lần tăng cường AI hàng tháng được đo theo gói. Khi vượt hạn mức API trả 403 kèm gợi ý nâng cấp. Xem bảng giá.