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

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

# Images

[Markdown](https://ailoot.ai/docs/ja/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/ja/?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/ja/?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アクセスに活かしています。
