Birefnet Background Removal V2

API kılavuzu ve entegrasyon referansı: uç nokta, girdi alanları, fiyatlar, webhook ve hatalar.

İstek ve yanıt

POST
https://kolayzeka.com/api/models/birefnet-background-removal-v2/generate

Gövde: { "input": {…alanlar}, "category_id"?: sayı, "webhook_url"?: "https://…" }. Alanlar aşağıda; tanımlı olmayan bir alan 422 döner.

cURL · JSON

curl -X POST https://kolayzeka.com/api/models/birefnet-background-removal-v2/generate \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "input": {
    "model": "General Use (Light)",
    "operating_resolution": "1024x1024",
    "output_mask": false,
    "refine_foreground": true,
    "image_url": "https://cdn.example.com/input.jpg",
    "output_format": "png",
    "mask_only": false
  },
  "webhook_url": "https://your-server.com/hooks/kolayzeka"
}'

cURL · multipart (dosya yükleyerek)

curl -X POST https://kolayzeka.com/api/models/birefnet-background-removal-v2/generate \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -F 'input[model]=General Use (Light)' \
  -F 'input[operating_resolution]=1024x1024' \
  -F 'input[output_mask]=false' \
  -F 'input[refine_foreground]=true' \
  -F 'input[output_format]=png' \
  -F 'input[mask_only]=false' \
  -F 'input[image_url]=@./image_url.jpg' \
  -F 'webhook_url=https://your-server.com/hooks/kolayzeka'
Üretim asenkrondur. POST, 202 ve status: "queued" döner; sonuç henüz yoktur. Sonucu GET https://kolayzeka.com/api/generations/{id} ile sorgulayın ya da webhook_url verin (aynı nesne gelir). Durumlar: queued → processing → completed | failed. estimated_seconds bu modun geçmiş ortalama süresidir (null olabilir).

1 · POST yanıtı (202)

{
  "data": {
    "id": "9d1c…-uuid",
    "model": "birefnet-background-removal-v2",
    "output_type": "image",
    "source": "api",
    "status": "queued",
    "input_data": {
      "model": "General Use (Light)",
      "operating_resolution": "1024x1024",
      "output_mask": false,
      "refine_foreground": true,
      "image_url": "https://cdn.example.com/input.jpg",
      "output_format": "png",
      "mask_only": false
    },
    "output_data": null,
    "thumbnail_url": null,
    "credit_cost": 5153,
    "duration": null,
    "estimated_seconds": 12,
    "error_message": null,
    "webhook_url": "https://your-server.com/hooks/kolayzeka",
    "created_at": "2026-06-29T12:00:00.000000Z",
    "updated_at": "2026-06-29T12:00:00.000000Z"
  },
  "success": true
}

2 · Tamamlandı (GET /generations/{id} veya webhook)

{
  "data": {
    "id": "9d1c…-uuid",
    "model": "birefnet-background-removal-v2",
    "output_type": "image",
    "source": "api",
    "status": "completed",
    "input_data": {
      "model": "General Use (Light)",
      "operating_resolution": "1024x1024",
      "output_mask": false,
      "refine_foreground": true,
      "image_url": "https://cdn.example.com/input.jpg",
      "output_format": "png",
      "mask_only": false
    },
    "output_data": {
      "result": "https://<signed-url>/output.jpg"
    },
    "thumbnail_url": "https://<signed-url>/thumb.jpg",
    "credit_cost": 5153,
    "duration": 4.52,
    "estimated_seconds": 12,
    "error_message": null,
    "webhook_url": "https://your-server.com/hooks/kolayzeka",
    "created_at": "2026-06-29T12:00:00.000000Z",
    "updated_at": "2026-06-29T12:00:05.000000Z"
  },
  "success": true
}

3 · Başarısız

{
  "data": {
    "id": "9d1c…-uuid",
    "model": "birefnet-background-removal-v2",
    "output_type": "image",
    "source": "api",
    "status": "failed",
    "input_data": {
      "model": "General Use (Light)",
      "operating_resolution": "1024x1024",
      "output_mask": false,
      "refine_foreground": true,
      "image_url": "https://cdn.example.com/input.jpg",
      "output_format": "png",
      "mask_only": false
    },
    "output_data": null,
    "thumbnail_url": null,
    "credit_cost": 0,
    "duration": null,
    "estimated_seconds": 12,
    "error_message": "Sağlayıcı yoğun, lütfen tekrar deneyin.",
    "webhook_url": "https://your-server.com/hooks/kolayzeka",
    "created_at": "2026-06-29T12:00:00.000000Z",
    "updated_at": "2026-06-29T12:00:00.000000Z"
  },
  "success": true
}
  • Sonuç output_data.result alanındadır (imzalı URL, süreli: kalıcı tutmak için kendi depolamanıza indirin).
  • Medya URL'leri imzalıdır ve süresi dolar; eski bir URL için işi tekrar GET edin, taze URL gelir.
  • Geçmiş: GET https://kolayzeka.com/api/generations (en yeni önce, sayfa başına 20, ?page=).

Fiyat ve teklif

Fiyat kredi cinsindendir ve seçtiğiniz seçeneklere (kalite, boyut, süre, adet…) göre değişir. Varsayılan ayarlarla bu mod ≈ 5153 kredi.

POST
https://kolayzeka.com/api/models/birefnet-background-removal-v2/quote

Çalıştırmadan, tam bu girdinin fiyatı. Token gerekmez; girdiyi üretimdeki gibi doğrular.

cURL

curl -X POST https://kolayzeka.com/api/models/birefnet-background-removal-v2/quote \
  -H "Content-Type: application/json" \
  -d '{"input":{"model":"General Use (Light)","operating_resolution":"1024x1024","output_mask":false,"refine_foreground":true,"image_url":"https://cdn.example.com/input.jpg","output_format":"png","mask_only":false}}'

Yanıt

{
  "success": true,
  "data": {
    "credits": 5153,
    "basis": "per_generation",
    "exact": true,
    "mode": {
      "category_id": null,
      "label": "Mod"
    }
  }
}
  • exact: false: fiyat çıktıya bağlı (ör. token, gerçek süre); teklif tipik değerle hesaplanır.
  • Kredi, istek kabul edilince teklif tutarı kadar ayrılır. İş bitince gerçek tutara göre fark düşülür ya da iade edilir; iş başarısız olursa tamamı iade edilir. Kesin tutar: sonuçtaki credit_cost.
  • Bakiye: GET https://kolayzeka.com/api/me → credit_balance. Yetmezse 402 insufficient_credits.

Girdi alanları

input içine gönderilir. Tip etiketi gönderilecek JSON değeridir (string, integer, number, boolean, url, array<url>). Aynı liste makine-okunur olarak GET https://kolayzeka.com/api/ai-models/birefnet-background-removal-v2 yanıtında.

model
isteğe bağlı
string

Model · Model to use for background removal. The 'General Use (Light)' model is the original model used in the BiRefNet repository. The 'General Use (Light 2K)' model is the original model used in the BiRefNet repository but trained with 2K images. The 'General Use (Heavy)' model is a slower but more accurate model. The 'Matting' model is a model trained specifically for matting images. The 'Portrait' model is a model trained specifically for portrait images. The 'General Use (Dynamic)' model supports dynamic resolutions from 256x256 to 2304x2304. The 'General Use (Light)' model is recommended for most use cases. The corresponding models are as follows: - 'General Use (Light)': BiRefNet - 'General Use (Light 2K)': BiRefNet_lite-2K - 'General Use (Heavy)': BiRefNet_lite - 'Matting': BiRefNet-matting - 'Portrait': BiRefNet-portrait - 'General Use (Dynamic)': BiRefNet_dynamic

Kabul edilen değerler:"General Use (Light)""General Use (Light 2K)""General Use (Heavy)""Matting""Portrait""General Use (Dynamic)"

Varsayılan: "General Use (Light)" (gönderilmezse bu kullanılır)

operating_resolution
isteğe bağlı
string

Operating Resolution · The resolution to operate on. The higher the resolution, the more accurate the output will be for high res input images. The '2304x2304' option is only available for the 'General Use (Dynamic)' model.

Kabul edilen değerler:"1024x1024""2048x2048""2304x2304"

Varsayılan: "1024x1024" (gönderilmezse bu kullanılır)

output_mask
isteğe bağlı
boolean

Output Mask · Whether to output the mask used to remove the background

Varsayılan: false (gönderilmezse bu kullanılır)

refine_foreground
isteğe bağlı
boolean

Refine Foreground · Whether to refine the foreground using the estimated mask

Varsayılan: true (gönderilmezse bu kullanılır)

image_url
zorunlu
url
dosya

Image Url · URL of the image to remove background from

JSON'da herkese açık bir https URL gönderin, ya da dosyayı multipart ile yükleyin: -F 'input[image_url]=@./dosya.jpg'

output_format
isteğe bağlı
string

Output Format · The format of the output image

Kabul edilen değerler:"webp""png""gif"

Varsayılan: "png" (gönderilmezse bu kullanılır)

mask_only
isteğe bağlı
boolean

Mask Only · Whether to return only the segmentation mask without applying it to the image. When set to `True`, only the mask will be returned and foreground refinement will be skipped. Useful for reducing computation and data transfer when only the mask is needed.

Varsayılan: false (gönderilmezse bu kullanılır)

Kimlik doğrulama

Her istekte Authorization: Bearer YOUR_API_TOKEN. Token'ı Profil sayfasında oluşturun. Katalog ve teklif (/ai-models, /quote) token istemez. Ayrıntılar: geliştirici rehberi.

Webhook

İsteğe bir webhook_url (https) ekleyin; iş bitince oraya imzalı bir POST gelir. Gövde { event, success, data }: data, durum endpoint'inin döndüğü nesnenin aynısıdır. Sorgulamaya gerek kalmaz; uzun işler (video, çok adımlı uygulamalar) için önerilir.

Gelen başlıklar

X-KolayZeka-Event: generation.completed // veya generation.failed

X-KolayZeka-Signature: sha256=<hex>

User-Agent: KolayZeka-Webhook/1.0

İmza = ham gövdenin, hesabınızın webhook imzalama anahtarı ile HMAC-SHA256'sı. Anahtarı Profil sayfasında oluşturun (bir kez gösterilir). Anahtar yoksa webhook gönderilmez.

Doğrulama · Node.js

import crypto from 'node:crypto';

// rawBody: the request body exactly as received (before JSON.parse).
const expected = 'sha256=' + crypto
  .createHmac('sha256', process.env.KOLAYZEKA_WEBHOOK_SECRET)
  .update(rawBody)
  .digest('hex');
const given = req.headers['x-kolayzeka-signature'] ?? '';

if (given.length !== expected.length ||
    !crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(given))) {
  return res.status(401).end();
}

Doğrulama · PHP / Laravel

$expected = 'sha256='.hash_hmac('sha256', $request->getContent(), config('services.kolayzeka.webhook_secret'));

abort_unless(hash_equals($expected, (string) $request->header('X-KolayZeka-Signature')), 401);
  • 2xx dönün. Diğer yanıtlar ve ağ hataları 30 sn arayla en çok 5 kez yeniden denenir.
  • Aynı iş için birden fazla gelebilir: data.id ile tekilleştirin.
  • Özel / iç ağ / bulut-metadata adresleri reddedilir (422 invalid_webhook_url).

Hatalar

Her hata aynı şekildedir: { success: false, code, error, … }. Kodunuzu code'a göre yazın; error insan için mesajdır.

HTTPcodeNe zaman
400
invalid_modeModelin şu an çalıştırılabilir bir modu yok (geçici; başka model deneyin).
401
unauthenticatedBearer token yok, geçersiz ya da iptal edilmiş.
402
insufficient_creditsBakiye yetmiyor. Yanıtta balance (bakiye) ve required (gereken) var.
403
forbiddenBu kaynağa erişim yetkiniz yok.
404
not_foundModel / uygulama / iş yok, aktif değil ya da size ait değil.
405
method_not_allowedEndpoint bu HTTP metodunu kabul etmiyor.
422
validation_failedGirdi şemaya uymuyor. errors alanı: alan → mesajlar.
422
invalid_webhook_urlwebhook_url https değil, çözümlenmiyor ya da özel / iç ağ adresi.
429
rate_limitedHız sınırı aşıldı. retry_after saniye sonra tekrar deneyin.
500
server_errorBeklenmeyen hata. Tekrar denemeden önce listeden (GET /api/generations) işin oluşup oluşmadığına bakın.

402 örneği

{
  "success": false,
  "code": "insufficient_credits",
  "error": "Yetersiz kredi. Bakiye: 40, Gerekli: 55",
  "balance": 40,
  "required": 55
}

422 örneği

{
  "success": false,
  "code": "validation_failed",
  "error": "Doğrulama başarısız oldu.",
  "errors": {
    "quality": [
      "`quality` alanı şunlardan biri olmalıdır: low, medium, high."
    ]
  }
}