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

# 이미지 생성 및 편집 API

> OpenAI 호환 생성 및 편집, Gemini 및 Nano Banana, Midjourney, Flux, Bria, Replicate, Seedream 또는 SeedEdit 워크플로에 맞는 CometAPI 이미지 라우트를 선택하세요.

워크플로에 맞는 요청 형식을 선택해 CometAPI 이미지 모델 문서를 활용하세요. OpenAI 호환 이미지 엔드포인트는 일반적인 생성 및 편집 흐름을 지원하며, 공급자별 페이지는 작업 기반 이미지 시스템을 다룹니다.

## 이미지 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">
    CometAPI를 통해 Flux 이미지를 생성합니다.
  </Card>

  <Card title="Bria 이미지 생성" icon="image" href="/api/image/bria/generate-image">
    Bria 이미지 생성 도구를 사용합니다.
  </Card>

  <Card title="Replicate prediction 생성" icon="sparkles" href="/api/image/replicate/create-predictions-general">
    Replicate 형식의 이미지 prediction 요청을 실행합니다.
  </Card>

  <Card title="Seedream 이미지 생성" icon="image" href="/api/image/seededit-seedream/bytedance-image-generation">
    Seedream 이미지 생성 요청을 만듭니다.
  </Card>
</CardGroup>

## 이미지 생성하기

[Models 페이지](/ko/overview/models) 또는 [model directory](https://www.cometapi.com/models/)에서 이미지 지원 model ID를 사용하세요. 아래 예시는 OpenAI 호환 이미지 생성(Create an image) 엔드포인트를 호출합니다.

<Note>
  이 예시에서는 플레이스홀더 `your-image-model-id`를 사용합니다. 요청을 실행하기 전에 [Models 페이지](/ko/overview/models) 또는 [model directory](https://www.cometapi.com/models/)에서 사용 가능한 이미지 model ID로 바꾸세요.
</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>

## 응답 예시

성공적인 응답은 다음과 같을 수 있습니다. 선택한 모델에 따라 각 항목에는 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
  }
}
```

## 예시 모델 레코드

<Info>
  이 예시 모델 카탈로그 응답은 `/api/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">
    [Models page](/ko/overview/models)에서 이미지 지원 모델을 선택하세요.
  </Accordion>

  <Accordion title="Unsupported size">
    선택한 이미지 엔드포인트가 허용하는 크기를 사용하세요.
  </Accordion>

  <Accordion title="Expired result URL">
    provider 링크가 만료되기 전에 생성된 자산을 다운로드하세요.
  </Accordion>

  <Accordion title="Upload too large">
    큰 base64 페이로드 대신 이미지 URL 또는 더 작은 파일을 사용하세요.
  </Accordion>

  <Accordion title="Missing image data">
    모델에 따라 출력 형태가 다를 수 있으므로 `b64_json`와 `url` 필드를 모두 확인하세요.
  </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">
    지수 백오프와 함께 재시도하고 동시성을 줄이세요.
  </Accordion>

  <Accordion title="500 or 503">
    일시적인 provider 또는 서비스 오류에는 백오프와 함께 재시도하세요.
  </Accordion>
</AccordionGroup>

<Tip>
  구현 패턴은 [Error codes and retry strategy](/ko/guides/error-codes-and-retry-strategy) 및 [Rate limits and concurrency](/ko/guides/rate-limits-and-concurrency)를 참조하세요.
</Tip>

## 가격 및 모델 디렉터리

<CardGroup cols={3}>
  <Card title="Models page" icon="list" href="/overview/models">
    문서에서 CometAPI가 model ID를 노출하는 방식을 확인하세요.
  </Card>

  <Card title="Model directory" icon="puzzle-piece" href="https://www.cometapi.com/models/">
    사용 가능한 모델과 기능을 살펴보세요.
  </Card>

  <Card title="Pricing" icon="tag" href="https://www.cometapi.com/pricing/">
    모델을 호출하기 전에 가격을 확인하세요.
  </Card>
</CardGroup>
