> ## 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.

# Image generation and editing APIs

> Choose CometAPI image routes for OpenAI-compatible generation and edits, Gemini and Nano Banana, Midjourney, Flux, Bria, Replicate, and Seedream or SeedEdit workflows.

Use CometAPI image model docs by choosing the request format that matches your workflow. OpenAI-compatible image endpoints cover common generation and editing flows; provider-specific pages cover task-based image systems.

## Choose an image API

<CardGroup cols={2}>
  <Card title="Create an image" icon="image" href="/api/image/openai/images">
    Generate images with an OpenAI-compatible request.
  </Card>

  <Card title="Create image edit" icon="sparkles" href="/api/image/openai/image-editing">
    Edit images with an OpenAI-compatible request.
  </Card>

  <Card title="Generate images with Gemini" icon="image" href="/api/image/gemini/gemini-generates-image">
    Generate or edit images with Gemini format.
  </Card>

  <Card title="Start with Midjourney API" icon="sparkles" href="/api/image/midjourney/midjourney-api-quick-start">
    Submit and poll Midjourney image tasks.
  </Card>

  <Card title="Generate a Flux image" icon="image" href="/api/image/flux/flux-generate-image">
    Generate Flux images through CometAPI.
  </Card>

  <Card title="Generate a Bria image" icon="image" href="/api/image/bria/generate-image">
    Use Bria image generation tools.
  </Card>

  <Card title="Create a Replicate prediction" icon="sparkles" href="/api/image/replicate/create-predictions-general">
    Run Replicate-format image prediction requests.
  </Card>

  <Card title="Create Seedream images" icon="image" href="/api/image/seededit-seedream/bytedance-image-generation">
    Create Seedream image generation requests.
  </Card>
</CardGroup>

## Generate an image

Use an image-capable model ID from the [Models page](/overview/models) or the [model directory](https://www.cometapi.com/models/). The examples below call the OpenAI-compatible Create an image endpoint.

<Note>
  These examples use the placeholder `your-image-model-id`. Replace it with an available image model ID from the [Models page](/overview/models) or [model directory](https://www.cometapi.com/models/) before you run the request.
</Note>

<Tip>
  Open [Create an image](/api/image/openai/images) to use the playground and endpoint schema.
</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>

## Response example

A successful response can look like this. Depending on the selected model, each item can contain a base64 image or a result 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
  }
}
```

## Example model records

<Info>
  This example model catalog response shows the `/api/models` envelope and one image model record shape. It is not a complete model list.
</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
      }
    }
  ]
}
```

## Common errors

<AccordionGroup>
  <Accordion title="Invalid model ID">
    Choose an image-capable model from the [Models page](/overview/models).
  </Accordion>

  <Accordion title="Unsupported size">
    Use a size that the selected image endpoint accepts.
  </Accordion>

  <Accordion title="Expired result URL">
    Download generated assets before provider links expire.
  </Accordion>

  <Accordion title="Upload too large">
    Use image URLs or smaller files instead of large base64 payloads.
  </Accordion>

  <Accordion title="Missing image data">
    Check both `b64_json` and `url` fields because output shape can differ by model.
  </Accordion>
</AccordionGroup>

## Error codes and retry strategy

<AccordionGroup>
  <Accordion title="400">
    Do not retry until the prompt, size, or image input is fixed.
  </Accordion>

  <Accordion title="401">
    Do not retry until the API key is present and valid.
  </Accordion>

  <Accordion title="404">
    Check the base URL, path, and model ID before retrying.
  </Accordion>

  <Accordion title="413">
    Reduce upload size before retrying.
  </Accordion>

  <Accordion title="429">
    Retry with exponential backoff and reduce concurrency.
  </Accordion>

  <Accordion title="500 or 503">
    Retry with backoff for transient provider or service errors.
  </Accordion>
</AccordionGroup>

<Tip>
  For implementation patterns, see [Error codes and retry strategy](/guides/error-codes-and-retry-strategy) and [Rate limits and concurrency](/guides/rate-limits-and-concurrency).
</Tip>

## Pricing and model directory

<CardGroup cols={3}>
  <Card title="Models page" icon="list" href="/overview/models">
    Read how CometAPI exposes model IDs in the docs.
  </Card>

  <Card title="Model directory" icon="puzzle-piece" href="https://www.cometapi.com/models/">
    Browse model availability and capabilities.
  </Card>

  <Card title="Pricing" icon="tag" href="https://www.cometapi.com/pricing/">
    Check pricing before you call a model.
  </Card>
</CardGroup>
