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

# 画像生成を作成

> gpt-image-2 で画像を生成します。非同期タスクと JSON 形式の参照画像に対応しています。

`gpt-image-2` は DimiLinks の画像生成モデルで、テキストからの画像生成と画像からの画像生成に対応しています。`image_urls` フィールドで最大 9 枚の参照画像を指定できます。

<Note>
  `?async=true` の追加を推奨します。同期モードでは画像の完成までレスポンスが返らないため、ゲートウェイやクライアントのタイムアウトによって中断されやすくなります。
</Note>

## リクエスト URL

```http theme={null}
POST https://dimilinks.com/v1/images/generations?async=true
Content-Type: application/json
Authorization: Bearer <DIMILINKS_API_KEY>
```

## テキストから画像を生成する例

```bash theme={null}
curl "https://dimilinks.com/v1/images/generations?async=true" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "サイバーパンク風の猫のポスター、ネオンライト、映画のような雰囲気",
    "n": 1,
    "size": "16:9",
    "resolution": "2k",
    "output_format": "png"
  }'
```

## 画像から画像を生成する例

```bash theme={null}
curl "https://dimilinks.com/v1/images/generations?async=true" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "人物の主体を維持したまま、海辺の夕暮れを背景にした映画風ポートレートに変更する",
    "n": 1,
    "size": "16:9",
    "resolution": "4k",
    "image_urls": [
      "https://example.com/reference.png"
    ]
  }'
```

## 非同期レスポンス

```json theme={null}
{
  "created": 1777080000,
  "task_id": "img_xxx",
  "data": []
}
```

`task_id` を取得したら、[画像タスクを取得](/jp/api-reference/images/gpt-image-2/tasks)を呼び出して結果を確認してください。

## 同期レスポンス

同期モードでは、画像の完成後に次のレスポンスが返ります。

```json theme={null}
{
  "created": 1777080000,
  "task_id": "img_xxx",
  "data": [
    {
      "url": "/p/img/img_xxx/0?exp=1777166400000&sig=...",
      "file_id": "file_xxx"
    }
  ]
}
```

## 結果フィールドの説明

`data[].url` は必ずしも公開画像 URL とは限りません。次の 3 形式すべてに対応してください。

* `/p/img/...`：相対パスです。表示またはダウンロードする前に `https://dimilinks.com/p/img/...` の形式に補完してください。このパスには Bearer は不要で、URL 自体に署名と有効期限が含まれています。
* `https://...`：完全な画像 URL です。そのままリクエストまたは表示できます。
* `data:image/...;base64,...`：Data URL で、文字列自体が画像データです。Web ページではそのまま `<img src>` に指定できます。サーバー側のスクリプトでファイルとして保存する場合は、先に base64 をデコードしてください。

## パラメータ

| パラメータ                | 型                         | デフォルト値        | 説明                                                            |
| -------------------- | ------------------------- | ------------- | ------------------------------------------------------------- |
| `model`              | string                    | `gpt-image-2` | モデル名。                                                         |
| `prompt`             | string                    | 必須            | 画像生成または編集用のプロンプト。                                             |
| `n`                  | integer                   | `1`           | 1 回に生成する画像数。`1k` プランでは `1` 固定、`2k` / `4k` プランでは最大 `4`。        |
| `size`               | string                    | `1024x1024`   | `1:1`、`16:9` などのアスペクト比、または `WxH` 形式の具体的なピクセル数（例：`3840x2160`）。 |
| `resolution`         | string                    | 空             | 解像度プラン：`1k` / `2k` / `4k`。                                    |
| `output_format`      | string                    | 空             | 出力形式：`png` / `jpeg` / `webp`。                                 |
| `output_compression` | integer                   | 空             | 出力の圧縮品質。`jpeg` または `webp` と組み合わせて使用します。                       |
| `background`         | string                    | 空             | 背景の設定：`auto` / `transparent` / `opaque`。                      |
| `moderation`         | string                    | 空             | コンテンツモデレーションの強度：`auto` / `low`。                               |
| `user`               | string                    | 空             | 監査に使用する呼び出し元のユーザー識別子。                                         |
| `wait_for_result`    | boolean                   | `true`        | `false` を指定すると非同期で送信します。                                      |
| `image_urls`         | string \| array \| object | 空             | JSON 形式の参照画像フィールド。最大 9 枚。                                     |
| `mask_url`           | string                    | 空             | 部分的な再描画に使用するマスク。少なくとも 1 枚の参照画像と組み合わせる必要があります。                 |
| `response_format`    | string                    | 空             | `b64_json` を指定すると結果が base64 で直接返ります。デフォルトでの有効化は推奨しません。        |

## 非同期モードを有効にする方法

次のいずれかを指定すると、非同期モードになります。

* クエリパラメータ：`?async=true`
* クエリパラメータ：`?wait_for_result=false`
* リクエストヘッダー：`Prefer: respond-async`
* リクエストボディ：`"wait_for_result": false`

## 参照画像の形式

`image_urls` の使用を推奨します。

```json theme={null}
{
  "image_urls": [
    "https://example.com/ref.png",
    "data:image/png;base64,iVBORw0KGgo..."
  ]
}
```

`reference_images`、`images`、`image`、`image_url`、`input_image`、`input_images` にも対応しています。

## 参照画像の制限

* 1 回のリクエストで指定できる参照画像は最大 9 枚です。
* 参照画像 1 枚あたりの最大サイズは 20 MB です。
* HTTP(S) URL、Data URL、純粋な base64 に対応しています。
* ブラウザの `blob:` URL は直接指定できません。先に自分のサーバーへアップロードするか、Data URL に変換してください。

## 解像度プラン別の機能差

| プラン  | 1 回あたりの最大 `n` | 標準的な所要時間 | 説明                                      |
| ---- | ------------: | -------: | --------------------------------------- |
| `1k` |             1 |   約 60 秒 | エントリープラン。プレビューや低コストの一括生成に適しています。        |
| `2k` |             4 |  約 120 秒 | 推奨プラン。ほとんどの業務用途の画像生成に適しています。            |
| `4k` |             4 |  約 180 秒 | 高忠実度プラン。`21:9` など一部の極端なアスペクト比にも対応しています。 |

具体的な単価はコンソールの「価格」ページを確認してください。料金はプランごとに個別に計算されます。


## OpenAPI

````yaml POST /images/generations
openapi: 3.1.0
info:
  title: DimiLinks API
  description: >-
    DimiLinks unified API for chat (OpenAI-compatible and Anthropic native),
    image generation/editing, and video generation.
  version: 1.1.0
servers:
  - url: https://dimilinks.com/v1
    description: OpenAI 兼容入口：chat completions / images / videos / models / tasks
security:
  - bearerAuth: []
tags:
  - name: Models
  - name: Chat
  - name: Images
  - name: Videos
  - name: Tasks
paths:
  /images/generations:
    post:
      tags:
        - Images
      summary: Create image generation
      operationId: createImageGeneration
      parameters:
        - name: async
          in: query
          description: Set to true to submit an async image task.
          schema:
            type: boolean
        - name: wait_for_result
          in: query
          description: Set to false to submit an async image task.
          schema:
            type: boolean
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerationRequest'
      responses:
        '200':
          description: Image generation result or async submission
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ImageSubmitResponse'
                  - $ref: '#/components/schemas/ImageResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  schemas:
    ImageGenerationRequest:
      type: object
      properties:
        model:
          type: string
          default: gpt-image-2
        prompt:
          type: string
        'n':
          type: integer
          default: 1
          minimum: 1
          maximum: 4
          description: 1k resolution allows n=1 only; 2k and 4k allow up to 4.
        size:
          type: string
          examples:
            - '1:1'
            - '16:9'
            - 3840x2160
        resolution:
          type: string
          enum:
            - 1k
            - 2k
            - 4k
        output_format:
          type: string
          examples:
            - png
            - jpeg
            - webp
        output_compression:
          type: integer
        background:
          type: string
          examples:
            - auto
            - transparent
            - opaque
        moderation:
          type: string
          examples:
            - auto
            - low
        wait_for_result:
          type: boolean
        image_urls:
          $ref: '#/components/schemas/ReferenceImages'
        mask_url:
          type: string
        response_format:
          type: string
          examples:
            - b64_json
        user:
          type: string
      required:
        - prompt
    ImageSubmitResponse:
      type: object
      properties:
        created:
          type: integer
          example: 1777080000
        task_id:
          type: string
          example: img_xxx
        data:
          type: array
          items:
            $ref: '#/components/schemas/ImageData'
          example: []
      required:
        - task_id
        - data
    ImageResponse:
      type: object
      properties:
        created:
          type: integer
          example: 1777080000
        task_id:
          type: string
          example: img_xxx
        data:
          type: array
          items:
            $ref: '#/components/schemas/ImageData'
    ReferenceImages:
      oneOf:
        - type: string
        - type: array
          items:
            oneOf:
              - type: string
              - type: object
                additionalProperties: true
          maxItems: 9
        - type: object
          additionalProperties: true
    ImageData:
      type: object
      properties:
        url:
          type: string
          example: /p/img/img_xxx/0?exp=1777166400000&sig=...
        file_id:
          type: string
          example: file_xxx
    ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ErrorObject'
    ErrorObject:
      type: object
      properties:
        message:
          type: string
        type:
          type: string
          example: invalid_request_error
        code:
          oneOf:
            - type: string
            - type: integer
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: Model is not allowed for this API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````