證件照製作 API
PixMiller REST API · v1
發送人像;API 移除人像背景,切換到標準證件照底色,並按請求的規格裁剪。
此端點正在預覽中——路由和參數正在最終確定,上線前可能會有變動。慣例(X-Api-Key 認證、JSON 回應)與正式去背景 API 一致。
POST
https://api.pixmiller.com/v1/id-photo
1
認證與請求
在請求標頭的
X-Api-Key: YOUR_API_KEY 中傳送您的密鑰。在帳號頁面創建和管理密鑰。
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
image_file
|
file | 必填 | 人像照 — 正面、光線均勻 |
spec
|
string | 必填 | 規格:1 吋 / 2 吋 / us_passport / cn_visa … |
bg_color
|
string | 選填 | 背景:white(預設)/ blue / red |
2
程式碼範例
選一個語言並複製——直接就能跑。1curl -X POST "https://api.pixmiller.com/v1/id-photo" \2 -H "X-Api-Key: YOUR_API_KEY" \3 -F "[email protected]" \4 -F "spec=1inch" \5 -F "bg_color=blue"
1import requests23resp = requests.post(4 "https://api.pixmiller.com/v1/id-photo",5 headers={"X-Api-Key": "YOUR_API_KEY"},6 files={"image_file": open("face.jpg", "rb")},7 data={"spec": "1inch", "bg_color": "blue"},8)9print(resp.json()["url"])
1import fs from "node:fs";23const form = new FormData();4form.append("image_file", new Blob([fs.readFileSync("face.jpg")]), "face.jpg");5form.append("spec", "1inch");6form.append("bg_color", "blue");7const resp = await fetch("https://api.pixmiller.com/v1/id-photo", {8 method: "POST",9 headers: { "X-Api-Key": "YOUR_API_KEY" },10 body: form,11});12console.log((await resp.json()).url);
3
回應
1{2 "url": "https://cdn.pixmiller.com/result/8Kd2pQ.png"3}
url
處理後圖片的臨時 URL(原始圖片會在 3 天後自動刪除)。
4
錯誤
錯誤返回對應的狀態碼和以下格式的 JSON 主體 {"errors":{"code":"…","message":"…"}}.
400
validation error
缺少或無效的 image_file、檔案過大,或圖片來源衝突。
401
authentication_failed
缺少或無效的 X-Api-Key 標頭。
402
not_enough_credit
請求了 size=full,但帳戶已無高畫質點數。
422
invalid_image
無法處理此圖片 — 圖片過小、格式不支援或解碼失敗。
429
throttled
超出速率限制。請放慢速度,並在 Retry-After 標頭後重試。