Source: https://ailoot.ai/docs/ko/api/images/
Canonical: https://ailoot.ai/docs/ko/api/images/
Language: ko

[API](https://ailoot.ai/docs/ko/) 

# Images

[Markdown](https://ailoot.ai/docs/ko/api/images/index.md)

OpenAI Images 형식의 이미지 생성 및 편집입니다.

POST`https://api.ailoot.ai/v1/images/generations`

Images

```bash
curl https://api.ailoot.ai/v1/images/generations \
  -H "Authorization: Bearer $AILOOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5",
    "prompt": "수채화 그림: 바위 위의 등대, 새벽",
    "size": "1024x1024"
  }' 
```

```python
img = client.images.generate(
    model="gpt-image-2.5",
    prompt="수채화 그림: 바위 위의 등대, 새벽",
    size="1024x1024",
)
print(img.data[0].url or "base64:", (img.data[0].b64_json or "")[:40])
```

200 OK

```json
{
  "created": 1790812800,
  "data": [
    { "url": "https://…/content" }
  ],
  "usage": { "input_tokens": 18, "output_tokens": 1056 }
}
```

## 인증

| 매개변수 | 유형 | 필수 | 설명 |
| --- | --- | --- | --- |
| `Authorization` | header | 필수 | 키 형식: `Bearer sk-…`. 다음 헤더도 사용할 수 있습니다: `x-api-key` 또는 `x-goog-api-key`. |

## 요청 본문

| 매개변수 | 유형 | 필수 | 설명 |
| --- | --- | --- | --- |
| `model` | string | 필수 | 이미지 모델: `gpt-image-2.5-sunburst`, `gemini-3.1-flash-image`, `grok-imagine-image-2.0`, `qwen-image-3.0-pro`, `image-01`, `gpt-image-2`, `gemini-3.1-flash-lite-image`, `grok-imagine-image`, `wan2.7-image`, `gpt-image-2.5-sunburst-2026-09-08`, `gemini-3-pro-image`, `grok-imagine-image-quality` 및 추가 모델 수: [4](https://ailoot.ai/models/ko/?format=images). |
| `prompt` | string | 필수 | 이미지 설명입니다. |
| `n` | integer | 선택 사항 | 생성할 이미지 수입니다. 완성된 이미지마다 비용이 부과됩니다. |
| `size` | string | 선택 사항 | 크기입니다. 예: `1024x1024`. 허용 크기는 모델마다 다릅니다. |
| `quality` | string | 선택 사항 | 모델이 지원하는 경우 이미지 품질을 지정합니다(예: `low`, `medium`, `high`). |
| `response_format` | string | 선택 사항 | `url` 또는 `b64_json` — 모델이 선택을 지원하는 경우. |

## 편집

POST`https://api.ailoot.ai/v1/images/edits`

요청 `multipart/form-data`의 필드: `image` (이미지 하나 또는 여러 개), `prompt`, `model`, 필요한 경우 `mask`.

## 응답

| 매개변수 | 유형 | 필수 | 설명 |
| --- | --- | --- | --- |
| `data[]` | array |  | 완성된 이미지의 링크 `url` 또는 데이터 `b64_json`, 모델에 따라 다릅니다. |

Ailoot는 생성 전에 결과의 전체 비용을 예약합니다. 이미지는 텍스트보다 비싸므로 잔액에 여유를 두세요. 이미지당 요금 또는 이미지 토큰 요금 확인: [카탈로그](https://ailoot.ai/models/ko/?kind=image).

## 편집 · multipart/form-data

```bash
: "${AILOOT_IMAGE_EDIT_MODEL:?Select a model whose actual card or GET /v1/models method supports /v1/images/edits}"
curl --fail-with-body --max-time 300 \
  -D image-edit-headers.txt -o image-edit.json \
  https://api.ailoot.ai/v1/images/edits \
  -H "Authorization: Bearer $AILOOT_API_KEY" \
  -F "model=$AILOOT_IMAGE_EDIT_MODEL" \
  -F 'prompt=Keep the subject and replace the background with a sunset' \
  -F 'image=@input.png'
```

`input.png` → `image-edit.json` → `data[]` → `url | b64_json`

```python
import base64
import json
import mimetypes
import os
from pathlib import Path
import time
from urllib.parse import urljoin, urlsplit
from urllib.request import Request, urlopen

origin = "https://api.ailoot.ai"
out = Path("image-edit-results")
out.mkdir(exist_ok=True)

def save_all(data):
    rows = data.get("data", [])
    if not rows:
        raise RuntimeError("No completed image data; keep the original response")
    for index, row in enumerate(rows, 1):
        if row.get("b64_json"):
            content = base64.b64decode(row["b64_json"], validate=True)
            suffix = ".png" if content.startswith(b"\x89PNG") else ".bin"
        elif row.get("url"):
            url = row["url"]
            if urlsplit(url).scheme != "https":
                raise ValueError("Expected the exact returned HTTPS image URL")
            # Signed result URLs are downloaded without sending the API key to another host.
            with urlopen(url, timeout=300) as response:
                content = response.read()
                suffix = mimetypes.guess_extension(response.headers.get_content_type()) or ".bin"
        else:
            raise RuntimeError("Image has neither url nor b64_json")
        (out / ("image-%03d" % index + suffix)).write_bytes(content)


with open("image-edit.json", encoding="utf-8") as response:
    save_all(json.load(response))
```

## Images · async

OpenAI와 Anthropic SDK는 보통 네트워크 오류와 5xx를 자동 재시도합니다. 생성 요청에서는 다음으로 이를 끄고(`max_retries=0`) 다음을 확인하세요: `X-Should-Retry` — 새 시도 전에 확인해야 합니다. 응답을 잃었다고 요청이 실행되지 않았다는 뜻은 아닙니다.

```python
import base64
import json
import mimetypes
import os
from pathlib import Path
import time
from urllib.parse import urljoin, urlsplit
from urllib.request import Request, urlopen

origin = "https://api.ailoot.ai"
key = os.environ["AILOOT_API_KEY"]
out = Path("image-results")
out.mkdir(exist_ok=True)

def api(url, payload=None):
    url = urljoin(origin, url)
    if urlsplit(url).scheme != "https" or urlsplit(url).netloc != "api.ailoot.ai":
        raise ValueError("Unexpected API origin")
    request = Request(url, data=None if payload is None else json.dumps(payload).encode(),
                      headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"})
    with urlopen(request, timeout=300) as response:
        headers = dict(response.headers)
        data = json.load(response)
    (out / "response-headers.json").write_text(json.dumps(headers, indent=2))
    return data, headers

def save_all(data):
    rows = data.get("data", [])
    if not rows:
        raise RuntimeError("No completed image data; keep the original response")
    for index, row in enumerate(rows, 1):
        if row.get("b64_json"):
            content = base64.b64decode(row["b64_json"], validate=True)
            suffix = ".png" if content.startswith(b"\x89PNG") else ".bin"
        elif row.get("url"):
            url = row["url"]
            if urlsplit(url).scheme != "https":
                raise ValueError("Expected the exact returned HTTPS image URL")
            # Signed result URLs are downloaded without sending the API key to another host.
            with urlopen(url, timeout=300) as response:
                content = response.read()
                suffix = mimetypes.guess_extension(response.headers.get_content_type()) or ".bin"
        else:
            raise RuntimeError("Image has neither url nor b64_json")
        (out / ("image-%03d" % index + suffix)).write_bytes(content)

# One POST. If its result is unknown, preserve it and check history; do not rerun creation.
task, headers = api("/v1/images/generations/async", {
    "model": "gpt-image-2.5", "prompt": "Watercolor lighthouse at dawn", "size": "1024x1024"})
(out / "created-task.json").write_text(json.dumps(task, indent=2))
task_id = task.get("task_id") or task.get("id")
poll_url = task.get("poll_url") or headers.get("Location") or headers.get("location")
if not task_id or not poll_url:
    raise RuntimeError("Keep the create response and Request ID; do not submit again")

for poll in range(60):
    task, headers = api(poll_url)  # Read the original task with the same key.
    (out / "task-status.json").write_text(json.dumps(task, indent=2))
    if task.get("status") == "completed":
        result = task["result"]
        (out / "image-response.json").write_text(json.dumps(result, indent=2))
        save_all(result)
        break
    if task.get("status") == "failed":
        raise RuntimeError(json.dumps(task.get("error")))
    if task.get("status") != "processing" or task.get("result_pending_check"):
        raise RuntimeError("Keep the original task ID and check it later; no new POST")
    time.sleep(min(60, max(1, int(headers.get("Retry-After", headers.get("retry-after", "3"))))))
else:
    raise TimeoutError("Polling stopped; resume GET reads using created-task.json, never repeat POST")
```

궁금한 점이 남았나요? Request ID와 설명을 보내 주시면 해결을 도와드리겠습니다.[지원팀에 문의](mailto:support@ailoot.ai)

## Ailoot · 회사와 그 프로젝트 포트폴리오





Ailoot는 축적된 운영 경험, 폭넓은 고객 기반, 안정적인 서비스, 지속적인 KPI 관리를 바탕으로 합니다.





회사와 그 프로젝트 포트폴리오: 수백만 고객, 매월 수십억 규모의 매출.





Ailoot는 이러한 운영 경험을 고객의 제품, 에이전트, 애플리케이션, 자동화에서 AI 기능을 이용할 수 있는 API 접근에 활용합니다.
