跳到主要内容
开发者 API

将 AI 图像增强嵌入您的产品

用于 AI 增强(磨皮、放大、自动增强、去背景)的 REST API,并提供一流的出站 Webhook。使用 API 密钥认证,并在任务完成时接收已签名事件。

身份验证

每个请求都通过 x-api-key 请求头中的 API 密钥进行身份验证。在控制台中创建和管理密钥。密钥仅完整显示一次 — 请妥善保存。

curl https://pickimg.com/api/ai/enhance \
  -H "x-api-key: pk_xxxxxxxx.your_secret_here"

AI 增强

POST/api/ai/enhance创建增强任务
GET/api/ai/enhance/:id获取任务状态与结果
GET/api/ai/enhance列出您的任务

操作: 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

注册端点以在任务完成时接收事件。每次投递都会签名,便于您验证真实性。

GET/api/webhooks/events列出可用事件类型
POST/api/webhooks/endpoints创建端点
GET/api/webhooks/deliveries查看投递记录

事件: enhancement.queued, enhancement.completed, enhancement.failed, image.uploaded, quota.exceeded, ping.

验证签名

投递包含 X-PickIMG-Signature 请求头,格式为 t=<timestamp>,v1=<hmac>, 其中 HMAC-SHA256 基于 <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));
}

速率限制与配额

请求与每月 AI 增强次数按套餐计量。超出配额时 API 返回 403 并提示升级。详见 定价.