Đư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. Không dùng Bearer token trên public API.
curl https://pickimg.com/api/ai/enhance \
-H "x-api-key: YOUR_API_KEY"Phạm vi (scope)
Mỗi key mang các scope. Thiếu scope bắt buộc sẽ trả 403.
image:readĐọc job và nguồn ảnhimage:writeTải lên và xử lý ảnhai:enhanceTải nguồn, tạo và poll job AIwebhook:manageTạo và xem webhook outboundKey mới mặc định image:read, image:write và ai:enhance. webhook:manage cần bật thêm.
Lỗi HTTP
Dùng các mã này khi viết retry và luồng nâng cấp.
| 401 | Thiếu hoặc sai API key. |
| 403 | Key thiếu scope cần thiết. Hết hạn mức tăng cường hoặc lưu trữ tháng — job bị chặn, không tính overage. |
| 429 | Vượt RPM theo từng key. Đợi rồi gửi lại. |
Phản hồi 429 gồm Retry-After, X-RateLimit-Limit, X-RateLimit-Remaining.
Tăng cường AI
/api/ai/uploadTải ảnh nguồn/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ạnPOST /api/ai/upload dùng multipart field file (JPEG, PNG, WebP hoặc AVIF, tối đa 20MB) và trả { url } cho sourceUrl.
Thao tác: smooth_skin, upscale, auto_enhance, bg_remove. level: low | medium | high.
Poll GET đến khi status là queued, processing, completed, failed.
Upload, enhance, poll
# 1. Upload a source image (multipart field: file, max 20MB)
curl -X POST https://pickimg.com/api/ai/upload \
-H "x-api-key: YOUR_API_KEY" \
-F "file=@./photo.jpg"
# { "url": "https://cdn.example.com/uploads/..." }
# 2. Queue enhancement
curl -X POST https://pickimg.com/api/ai/enhance \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"sourceUrl": "https://cdn.example.com/uploads/photo.jpg",
"operation": "smooth_skin",
"level": "medium"
}'
# { "id": "job_123", "status": "queued", "operation": "smooth_skin" }
# 3. Poll until completed or failed
curl https://pickimg.com/api/ai/enhance/job_123 \
-H "x-api-key: YOUR_API_KEY"
# { "id": "job_123", "status": "completed", "resultUrl": "https://cdn.example.com/out.jpg" }// Node.js
const key = process.env.PICKIMG_KEY;
const form = new FormData();
form.append("file", blob, "photo.jpg");
const uploaded = await fetch("https://pickimg.com/api/ai/upload", {
method: "POST",
headers: { "x-api-key": key },
body: form,
}).then((r) => r.json());
const job = await fetch("https://pickimg.com/api/ai/enhance", {
method: "POST",
headers: {
"x-api-key": key,
"Content-Type": "application/json",
},
body: JSON.stringify({
sourceUrl: uploaded.url,
operation: "upscale",
}),
}).then((r) => r.json());
const poll = await fetch(`https://pickimg.com/api/ai/enhance/${job.id}`, {
headers: { "x-api-key": key },
}).then((r) => r.json());SDK chính thức (v0.1.0)
JavaScript (@pickimg/sdk) và Python (pickimg) bọc upload → enhance → poll. Cài từ clone repo cho đến khi publish npm/PyPI. Không đưa token vào source.
# From a clone of the pickimg repo (v0.1.0)
pnpm add ./sdk/js
pip install ./sdk/python
# After npm / PyPI publish:
# npm install @pickimg/sdk
# pip install pickimgimport { PickimgClient } from "@pickimg/sdk";
const client = new PickimgClient({ apiKey: process.env.PICKIMG_API_KEY! });
// 1. Upload
const { url } = await client.uploadImage(file);
// 2. Enhance
const job = await client.enhance({ sourceUrl: url, operation: "smooth_skin" });
// 3. Poll
const done = await client.waitForEnhancement(job.id);
console.log(done.resultUrl);from pickimg import PickimgClient
client = PickimgClient(api_key="YOUR_KEY")
# 1. Upload
with open("photo.jpg", "rb") as fh:
upload = client.upload_image(fh)
# 2. Enhance
job = client.enhance(source_url=upload["url"], operation="smooth_skin")
# 3. Poll
done = client.wait_for_enhancement(job.id)
print(done.result_url)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, job.completed, upload.finished.
job.completed cũng được gửi cùng image.completed và enhancement.completed. upload.finished cũng được gửi cùng image.uploaded. Dùng alias nếu muốn một handler cho cả hai loại job.
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
RPM tính theo từng API key (trần gói). Số lần AI tháng và dung lượng dùng chung mọi key cùng tài khoản.
| Gói | RPM | AI / tháng | Lưu trữ | API key |
|---|---|---|---|---|
| Free | 30 | 50 | 1 GB | 1 |
| Personal | 120 | 2,000 | 50 GB | 3 |
| Business | 600 | 20,000 | 500 GB | 15 |
| Enterprise | tùy chỉnh | tùy chỉnh | tùy chỉnh | tùy chỉnh |
Hết hạn mức trả 403. RPM trả 429 kèm Retry-After. Hạn mức Enterprise là tùy chỉnh — liên hệ sales, không giả định số self-serve.
Khi vượt hạn mức API trả 403 kèm gợi ý nâng cấp. Xem bảng giá.