> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# واجهات برمجة تطبيقات إنشاء الصور وتحريرها

> اختر مسارات صور CometAPI لإنشاء الصور وتحريرها بصيغة متوافقة مع OpenAI، وGemini وNano Banana، وMidjourney، وFlux، وBria، وReplicate، وسير عمل Seedream أو SeedEdit.

استخدم وثائق نماذج الصور في CometAPI من خلال اختيار تنسيق الطلب الذي يطابق سير عملك. تغطي نقاط نهاية الصور المتوافقة مع OpenAI تدفقات الإنشاء والتحرير الشائعة؛ بينما تغطي الصفحات الخاصة بكل مزود أنظمة الصور المعتمدة على المهام.

## اختر Image API

<CardGroup cols={2}>
  <Card title="إنشاء صورة" icon="image" href="/api/image/openai/images">
    أنشئ صورًا باستخدام طلب متوافق مع OpenAI.
  </Card>

  <Card title="إنشاء تعديل للصورة" icon="sparkles" href="/api/image/openai/image-editing">
    عدّل الصور باستخدام طلب متوافق مع OpenAI.
  </Card>

  <Card title="إنشاء صور باستخدام Gemini" icon="image" href="/api/image/gemini/gemini-generates-image">
    أنشئ الصور أو عدّلها باستخدام تنسيق Gemini.
  </Card>

  <Card title="ابدأ باستخدام Midjourney API" icon="sparkles" href="/api/image/midjourney/midjourney-api-quick-start">
    أرسل مهام صور Midjourney وتابع حالتها.
  </Card>

  <Card title="إنشاء صورة Flux" icon="image" href="/api/image/flux/flux-generate-image">
    أنشئ صور Flux من خلال CometAPI.
  </Card>

  <Card title="إنشاء صورة Bria" icon="image" href="/api/image/bria/generate-image">
    استخدم أدوات إنشاء الصور من Bria.
  </Card>

  <Card title="إنشاء تنبؤ Replicate" icon="sparkles" href="/api/image/replicate/create-predictions-general">
    شغّل طلبات التنبؤ بالصور بتنسيق Replicate.
  </Card>

  <Card title="إنشاء صور Seedream" icon="image" href="/api/image/seededit-seedream/bytedance-image-generation">
    أنشئ طلبات إنشاء الصور في Seedream.
  </Card>
</CardGroup>

## إنشاء صورة

استخدم model ID يدعم الصور من [صفحة النماذج](/ar/overview/models) أو [دليل النماذج](https://www.cometapi.com/models/). تستدعي الأمثلة أدناه نقطة نهاية Create an image المتوافقة مع OpenAI.

<Note>
  تستخدم هذه الأمثلة العنصر النائب `your-image-model-id`. استبدله بـ model ID متاح للصور من [صفحة النماذج](/ar/overview/models) أو [دليل النماذج](https://www.cometapi.com/models/) قبل تشغيل الطلب.
</Note>

<Tip>
  افتح [Create an image](/api/image/openai/images) لاستخدام ساحة التجربة ومخطط نقطة النهاية.
</Tip>

<CodeGroup>
  ```python Python theme={null}
  import os
  import requests

  response = requests.post(
      "https://api.cometapi.com/v1/images/generations",
      headers={
          "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
          "Content-Type": "application/json",
      },
      json={
          "model": "your-image-model-id",
          "prompt": "A clean product photo of a glass teapot on a white table",
          "size": "1024x1024",
      },
      timeout=120,
  )

  response.raise_for_status()
  result = response.json()
  print(result["data"][0].keys())
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.cometapi.com/v1/images/generations", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "your-image-model-id",
      prompt: "A clean product photo of a glass teapot on a white table",
      size: "1024x1024",
    }),
  });

  if (!response.ok) {
    throw new Error(await response.text());
  }

  const result = await response.json();
  console.log(Object.keys(result.data[0]));
  ```

  ```bash cURL theme={null}
  curl https://api.cometapi.com/v1/images/generations \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "your-image-model-id",
      "prompt": "A clean product photo of a glass teapot on a white table",
      "size": "1024x1024"
    }'
  ```
</CodeGroup>

## مثال على الاستجابة

يمكن أن تبدو الاستجابة الناجحة بهذا الشكل. اعتمادًا على model المحدد، يمكن أن يحتوي كل عنصر على صورة base64 أو URL للنتيجة:

```json theme={null}
{
  "created": 1779872000,
  "background": "opaque",
  "data": [
    {
      "b64_json": "iVBORw0KGgo..."
    }
  ],
  "output_format": "png",
  "quality": "low",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 19,
    "input_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 19
    },
    "output_tokens": 196,
    "output_tokens_details": {
      "image_tokens": 196,
      "text_tokens": 0
    },
    "total_tokens": 215
  }
}
```

## سجلات model كمثال

<Info>
  يوضّح هذا المثال لاستجابة فهرس models غلاف `/api/models` وشكل سجل model واحد خاص بالصور. وهو لا يمثل قائمة models كاملة.
</Info>

```bash cURL theme={null}
curl https://api.cometapi.com/api/models
```

```json theme={null}
{
  "success": true,
  "page": 1,
  "page_size": 20,
  "total": 302,
  "data": [
    {
      "created": 1776391310,
      "id": "your-image-model-id",
      "code": "your-image-model-id",
      "provider": "ExampleProvider",
      "provider_code": "example",
      "name": "Example image model",
      "model_type": "image",
      "features": [
        "text-to-image"
      ],
      "endpoints": "{\n  \"openai-image\": {\n    \"path\": \"/v1/images/generations\",\n    \"method\": \"POST\"\n  }\n}",
      "pricing": {
        "currency": "USD / M Tokens",
        "input": 4,
        "output": 24,
        "per_request": null,
        "per_second": null
      }
    }
  ]
}
```

## الأخطاء الشائعة

<AccordionGroup>
  <Accordion title="Invalid model ID">
    اختر model يدعم الصور من [صفحة Models](/ar/overview/models).
  </Accordion>

  <Accordion title="Unsupported size">
    استخدم حجمًا تقبله نقطة نهاية الصور المحددة.
  </Accordion>

  <Accordion title="Expired result URL">
    نزّل الأصول المُولَّدة قبل انتهاء صلاحية روابط المزوّد.
  </Accordion>

  <Accordion title="Upload too large">
    استخدم URLs للصور أو ملفات أصغر بدلًا من حمولات base64 الكبيرة.
  </Accordion>

  <Accordion title="Missing image data">
    تحقّق من حقلي `b64_json` و`url` لأن شكل المخرجات قد يختلف حسب model.
  </Accordion>
</AccordionGroup>

## رموز الأخطاء واستراتيجية إعادة المحاولة

<AccordionGroup>
  <Accordion title="400">
    لا تُعد المحاولة حتى يتم إصلاح prompt أو الحجم أو إدخال الصورة.
  </Accordion>

  <Accordion title="401">
    لا تُعد المحاولة حتى يكون مفتاح API موجودًا وصالحًا.
  </Accordion>

  <Accordion title="404">
    تحقّق من base URL والمسار وmodel ID قبل إعادة المحاولة.
  </Accordion>

  <Accordion title="413">
    قلّل حجم الرفع قبل إعادة المحاولة.
  </Accordion>

  <Accordion title="429">
    أعد المحاولة باستخدام exponential backoff وقلّل التزامن.
  </Accordion>

  <Accordion title="500 or 503">
    أعد المحاولة مع backoff في حال أخطاء المزوّد أو الخدمة المؤقتة.
  </Accordion>
</AccordionGroup>

<Tip>
  للاطلاع على أنماط التنفيذ، راجع [رموز الأخطاء واستراتيجية إعادة المحاولة](/ar/guides/error-codes-and-retry-strategy) و[حدود المعدل والتزامن](/ar/guides/rate-limits-and-concurrency).
</Tip>

## التسعير ودليل models

<CardGroup cols={3}>
  <Card title="Models page" icon="list" href="/overview/models">
    اقرأ كيف يعرِض CometAPI model IDs في الوثائق.
  </Card>

  <Card title="Model directory" icon="puzzle-piece" href="https://www.cometapi.com/models/">
    تصفّح توفر models وإمكاناتها.
  </Card>

  <Card title="Pricing" icon="tag" href="https://www.cometapi.com/pricing/">
    تحقّق من التسعير قبل استدعاء أي model.
  </Card>
</CardGroup>
