DRAEVADEVELOPERS
Background Removal
DRAEVA / Public API

Background Removal örnekleri

const key = process.env.DRAEVAAPIKEY; if (!key) throw new Error("DRAEVAAPIKEY is missing");

Node.js / TypeScript

ts
import { readFile, writeFile } from "node:fs/promises";

const key = process.env.DRAEVA_API_KEY;
if (!key) throw new Error("DRAEVA_API_KEY is missing");

const bytes = await readFile("garment.jpg");
const form = new FormData();
form.set("image", new Blob([bytes], { type: "image/jpeg" }), "garment.jpg");

const response = await fetch(
  "https://api.getdraeva.com/bg/v1/background-removals",
  {
    method: "POST",
    headers: { Authorization: `Bearer ${key}` },
    body: form,
    signal: AbortSignal.timeout(45_000),
  },
);

if (!response.ok) {
  const requestId = response.headers.get("x-request-id");
  throw new Error(`Background removal failed: ${response.status}; requestId=${requestId}`);
}
if (!response.headers.get("content-type")?.startsWith("image/png")) {
  throw new Error("Unexpected response format");
}
await writeFile("result.png", Buffer.from(await response.arrayBuffer()));

Python

python
import os
import requests

key = os.environ["DRAEVA_API_KEY"]
with open("garment.jpg", "rb") as image:
    response = requests.post(
        "https://api.getdraeva.com/bg/v1/background-removals",
        headers={"Authorization": f"Bearer {key}"},
        files={"image": ("garment.jpg", image, "image/jpeg")},
        timeout=45,
    )

if not response.ok:
    raise RuntimeError(
        f"DRAEVA {response.status_code}; requestId={response.headers.get('X-Request-Id')}"
    )
if not response.headers.get("Content-Type", "").startswith("image/png"):
    raise RuntimeError("Unexpected response format")
with open("result.png", "wb") as output:
    output.write(response.content)

Base64

bash
curl -X POST "https://api.getdraeva.com/bg/v1/background-removals?return_base64=true" \
  -H "Authorization: Bearer YOUR_DRAEVA_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{"image_base64":"BASE64_IMAGE_DATA"}'

Shell history'ye gerçek anahtar yazmamak için header değerini environment variable veya güvenli secret injection ile sağlayın.

Bu sayfada

Bir sorunuz mu var?API erişimi ve destek →