استبدال الخلفية
غيّر خلفية الصورة باستخدام موجّه نصي.
/v2/open/image/replace_background13 اعتماد / استدعاءالمدخلات
https://static.codia.ai/image_generate/2026-10-04/8c7b6ac0-2c6f-440b-867b-a1f6b77a2192.jpeg
1024 × 1024 px · JPG · 684 KBPremium skincare campaign scene: the bottle on a sculpted sand-colored plinth with soft desert shadows and dried palm leaves, warm golden-hour light
سيتوفر التشغيل المباشر من هذه الصفحة قريبًا. هذا طلب ومخرجات حقيقية من API — أنشئ مفتاحًا لتشغيله بنفسك.
المخرجات
مثال13 اعتماد / استدعاء


يحتفظ بالعنصر الرئيسي ويُنشئ خلفية جديدة انطلاقًا من prompt نصي.
- حالات الاستخدام
- لقطات المنتجات في مشاهد جديدة
- نسخ موسمية وإقليمية من الحملات
- إعادة استخدام صورة واحدة عبر قنوات متعددة
- المدخلات
- رابط URL عام لصورة أو ملف صورة مرفوع، وprompt يصف الخلفية الجديدة، وmodel اختياري.
- المخرجات
- data.image_urls مع صورة واحدة مُنشأة.
- طريقة التشغيل
- متزامن، ويستغرق عادةً أقل من عشر ثوانٍ.
المرجع التقني الكامل(بالإنجليزية)
Cost: 13 credits per successful call.
Image Replace Background supports two input modes:
- JSON URL mode: send
application/jsonwith the existing URL field. - Direct upload mode: send
multipart/form-datawith a local image file in theimagefield. The compatible field namefileis also accepted for the primary image. Codia checks credits before reading and uploading the file, so insufficient-credit requests return402without uploading anything.
Direct upload example:
curl 'https://openapi.codia.ai/v2/open/image/replace_background' \
-H 'Authorization: Bearer {codia_api_key}' \
-F 'image=@./product.png' \
-F 'prompt=clean white studio background'Keep the foreground subject of an image and synthesize a new background described by a text prompt. Synchronous, single-call. Combines background removal + inpainting + generative rendering in one step.
What this API is for
Reshooting product photography against new scenes ("on a marble counter", "in front of a sunset window"), reusing portraits across campaigns, or any time you want to keep the subject and change its environment. The subject is preserved; the prompt only steers the new background.
Request
| Field | Required | Notes |
|---|---|---|
image_url | yes | Public URL of the source image. |
prompt | yes | Natural-language description of the desired new background. Be specific about lighting, surface, and context for best results. |
model | no | Model ID. Defaults to nano_banana_2_1. Also: nano_banana_2, nano_banana_pro (higher fidelity), ideogram_v3 (alternative aesthetic). |
Prompt tips: describe the surface or scene ("clean white marble table"), the lighting ("soft studio lighting from the left"), and the mood. Avoid contradicting the subject's lighting unless you want the subject re-lit (the model may match it).
Response
Shared ImageUrlListSuccess shape — data.image_urls is an array of CDN URLs (length 1).
Billing & limits
- 13 credits per request from the unified Codia Open API balance.
- Synchronous, single-digit-second latency for typical inputs.
Errors
Standard set — 400 bad input (missing image_url or prompt), 401/403 auth, 402 credits, 429 rate limit, 500 internal.
Sync vs. async This synchronous endpoint returns the result inline — the simplest path. For production pipelines that need webhook delivery, automatic retry with idempotency, or explicit task cancellation, call
POST /v2/open/taskswithoperation=image_replace_backgroundinstead. Inputs and credit cost are identical.
التثبيت والإعداد
خزّن مفتاح API كمتغير بيئة في بيئة التشغيل لديك.
export CODIA_API_KEY="your-api-key"المصادقة
أرسل مفتاحك كرمز Bearer. تُنشأ المفاتيح وتُلغى من لوحة التحكم.
Authorization: Bearer <your-api-key>إرسال طلب
تقبل طلبات JSON عناوين URL عامة. كما تقبل نقاط النهاية التي تدعم multipart/form-data رفع الملفات مباشرة.
https://openapi.codia.ai·13 اعتماد / استدعاءترسل هذه الأمثلة نفس طلب مثال Sandbox، لذا تعمل كما هي بعد ضبط CODIA_API_KEY. استبدل الروابط بملفاتك العامة.
curl -X POST 'https://openapi.codia.ai/v2/open/image/replace_background' \
-H "Authorization: Bearer $CODIA_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"image_url": "https://static.codia.ai/image_generate/2026-10-04/8c7b6ac0-2c6f-440b-867b-a1f6b77a2192.jpeg",
"prompt": "Premium skincare campaign scene: the bottle on a sculpted sand-colored plinth with soft desert shadows and dried palm leaves, warm golden-hour light"
}'curl -X POST 'https://openapi.codia.ai/v2/open/image/replace_background' \
-H "Authorization: Bearer $CODIA_API_KEY" \
-F 'image=@./product.jpg' \
-F 'prompt=Premium skincare campaign scene: the bottle on a sculpted sand-colored plinth with soft desert shadows and dried palm leaves, warm golden-hour light'معلمات الطلب
Idempotency-Keystring · headerاختياريمفتاح اختياري يحدده المستخدم (حتى 255 حرفًا). عند تعيينه، تُخزَّن الاستجابة الناجحة (2xx) مؤقتًا لمدة 7 أيام. إعادة المحاولة بالمفتاح نفسه + جسم طلب مطابق تُعيد الاستجابة المخزّنة (دون خصم رصيد إضافي)؛ أما إعادة المحاولة بالمفتاح نفسه مع جسم مختلف فتُعيد 409. استخدمه لجعل إعادة إرسال POST آمنة عند حدوث أعطال في الشبكة. في عمليات الرفع بصيغة multipart/form-data، تُقارن الطلبات بحسب حقول النموذج ومحتوى الملفات، لذا يُعاد تشغيل الرفع المُكرَّر حتى لو اختار العميل multipart boundary جديدًا.
image_urlstringمطلوبرابط URL العام للصورة المصدر
promptstringمطلوبوصف نصي للخلفية الجديدة المطلوبة
modelstringاختياريالنموذج الذي يُنشئ الخلفية الجديدة. القيمة الافتراضية nano_banana_2_1. تكلفة جميع النماذج المدعومة حاليًا 13 رصيدًا لكل طلب.
| النموذج | الأنسب لـ | الأرصدة |
|---|---|---|
nano_banana_2_1 | استبدال فعّال للخلفية مع اتساق بصري أفضل (Gemini Flash Image). خيار افتراضي جيد لمعظم الصور. | 13 |
nano_banana_2 | استبدال سريع للخلفية (Gemini 3.1 Flash). | 13 |
nano_banana_pro | خلفيات 4K بجودة الاستوديو مع إضاءة وانعكاسات واقعية. | 13 |
ideogram_v3 | خلفيات مُنمَّقة أو توضيحية أو غنية بالنصوص. | 13 |
"nano_banana_2_1"imagefileمطلوبملف الصورة المصدر
filefileاختياريمتوقفحقل ملف الصورة المصدر للتوافق (مهمل: استخدم image بدلًا منه).
image_urlstringاختياريرابط URL للصورة المصدر عند عدم رفع صورة
promptstringمطلوبprompt الخلفية البديلة
modelstringاختيارينموذج اختياري
مخطط الاستجابة
200روابط URL للصور المعالَجة
codeintegermessagestringdataobjectdata.image_urlsstring[]روابط URL للصور المُولَّدة أو المعالَجة
{
"code": 0,
"message": "ok",
"data": {
"image_urls": [
"https://static.codia.ai/image_generate/2026-10-04/e96ad334-0b97-4eb4-8953-57936bcfc99c.png"
]
}
}رموز الأخطاء
تستخدم الأخطاء البنية نفسها: code يطابق حالة HTTP، وmessage يشرح المشكلة، وdata قيمته null. بعض الأخطاء تضيف كائن details. اعتمد على رمز الحالة وليس على نص message.
{
"code": 401,
"message": "Unauthorized",
"data": null
}| الحالة | الوصف |
|---|---|
| 400 | جسم الطلب غير صالح أو تنقصه معاملات مطلوبة |
| 401 | مفتاح API مفقود أو غير صالح أو تم إبطاله |
| 402 | رصيد الحساب غير كافٍ أو انتهت صلاحية الاشتراك |
| 403 | لا يملك الحساب صلاحية الوصول إلى نقطة النهاية هذه |
| 409 | أُعيد استخدام Idempotency-Key مع جسم طلب مختلف. |
| 429 | تم تجاوز حد المعدل. انتظر عدد الثواني المحدد في الترويسة `Retry-After` قبل إعادة المحاولة. |
| 500 | حدث خطأ غير متوقع في الخادم |


