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

# 即梦官方格式生图

> 使用 `POST /jm` 调用即梦官方格式接口生成图像。

# 即梦官方格式生图

即梦官方格式的图像生成接口，使用 JSON 提交并需要携带查询参数。

* 路由入口是 `POST /jm`。
* 需要在 URL 中携带 `Action` 和 `Version` 查询参数。
* 当前使用 `application/json` 提交。
* 支持文生图、图生图等多种场景。
* 提交成功后返回任务 `task_id`，后续用 [查询任务](./official-query) 获取结果。

## 支持模型

* `jimeng-4.0`：即梦 4.0 模型

## 方法与路径

```http theme={null}
POST /jm?Action=CVSync2AsyncSubmitTask&Version=2022-08-31
```

## 请求示例

<CodeGroup>
  ```bash theme={null}
  curl -X POST "https://octopusx.ai/jm?Action=CVSync2AsyncSubmitTask&Version=2022-08-31" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -d '{
      "req_key": "jimeng_t2i_v40",
      "model": "jimeng-4.0",
      "prompt": "落日余晖映照湖面，细腻的油画质感",
      "force_single": true,
      "image_urls": [],
      "width": 1024,
      "height": 1024
    }'
  ```

  ```python theme={null}
  import requests

  resp = requests.post(
      "https://octopusx.ai/jm",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json",
          "Accept": "application/json",
      },
      params={
          "Action": "CVSync2AsyncSubmitTask",
          "Version": "2022-08-31",
      },
      json={
          "req_key": "jimeng_t2i_v40",
          "model": "jimeng-4.0",
          "prompt": "落日余晖映照湖面，细腻的油画质感",
          "force_single": True,
          "image_urls": [],
          "width": 1024,
          "height": 1024,
      },
      timeout=60,
  )
  print(resp.json())
  ```
</CodeGroup>

### 带参考图示例

<CodeGroup>
  ```bash theme={null}
  curl -X POST "https://octopusx.ai/jm?Action=CVSync2AsyncSubmitTask&Version=2022-08-31" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -d '{
      "req_key": "jimeng_t2i_v40",
      "model": "jimeng-4.0",
      "prompt": "参考图片生成艺术风格",
      "force_single": true,
      "image_urls": [
        "https://example.com/reference1.png",
        "https://example.com/reference2.png"
      ],
      "resolution": "2k"
    }'
  ```

  ```python theme={null}
  import requests

  resp = requests.post(
      "https://octopusx.ai/jm",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json",
          "Accept": "application/json",
      },
      params={
          "Action": "CVSync2AsyncSubmitTask",
          "Version": "2022-08-31",
      },
      json={
          "req_key": "jimeng_t2i_v40",
          "model": "jimeng-4.0",
          "prompt": "参考图片生成艺术风格",
          "force_single": True,
          "image_urls": [
              "https://example.com/reference1.png",
              "https://example.com/reference2.png",
          ],
          "resolution": "2k",
      },
      timeout=60,
  )
  print(resp.json())
  ```
</CodeGroup>

## 响应示例

<ResponseExample>
  ```json 200 theme={null}
  {
    "code": 10000,
    "data": {
      "task_id": "67fb9e82-126e-4c71-bb16-a3bb3789e3b7",
      "status": "submitted"
    },
    "message": "Success",
    "request_id": "67fb9e82-126e-4c71-bb16-a3bb3789e3b7",
    "status": 10000,
    "time_elapsed": "35.381µs"
  }
  ```
</ResponseExample>

## 认证

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

## 查询参数

<ParamField query="Action" type="string">
  操作类型。固定值：`CVSync2AsyncSubmitTask`（提交任务）。
</ParamField>

<ParamField query="Version" type="string">
  API 版本。固定值：`2022-08-31`。
</ParamField>

## Body

<ParamField body="req_key" type="string" required>
  服务标识。取固定值：`jimeng_t2i_v40`。
</ParamField>

<ParamField body="model" type="string" required>
  模型名。例如 `jimeng-4.0`。
</ParamField>

<ParamField body="prompt" type="string" required>
  用于生成图像的提示词。中英文输入均可。建议最长不超过 800 字符，prompt 过长有概率出图异常或不生效。支持在 prompt 中直接指定生图比例。
</ParamField>

<ParamField body="resolution" type="string">
  分辨率。可选值：`1k`、`2k`、`4k`。
</ParamField>

<ParamField body="size" type="integer">
  生成图片的面积（已弃用）。默认值：4194304，即 2048*2048，生成 2K 分辨率图像。取值范围：\[1024*1024, 4096\*4096]，可生成 1K 到 4K 分辨率图像。
</ParamField>

<ParamField body="force_single" type="boolean">
  是否强制生成单图。默认值：`false`。
</ParamField>

<ParamField body="image_urls" type="array">
  图片文件 URL。支持输入 0 至 10 张图，用于图生图场景。
</ParamField>

<ParamField body="width" type="integer">
  图片宽度。推荐可选值：1024（1K）、2048（2K）、4096（4K）等。
</ParamField>

<ParamField body="height" type="integer">
  图片高度。推荐可选值：1024（1K）、2048（2K）、4096（4K）等。
</ParamField>

## Response

<ResponseField name="code" type="integer">
  状态码。`10000` 表示成功。
</ResponseField>

<ResponseField name="data" type="object">
  响应数据容器。
</ResponseField>

<ResponseField name="data.task_id" type="string">
  任务 ID。用于后续查询任务状态和结果。
</ResponseField>

<ResponseField name="data.status" type="string">
  任务状态。
</ResponseField>

<ResponseField name="message" type="string">
  状态消息。
</ResponseField>

<ResponseField name="request_id" type="string">
  请求 ID。
</ResponseField>

<ResponseField name="status" type="integer">
  状态码。
</ResponseField>

<ResponseField name="time_elapsed" type="string">
  请求耗时。
</ResponseField>

## 推荐尺寸

### 1K 分辨率

| 宽高        | 比例  |
| --------- | --- |
| 1024x1024 | 1:1 |

### 2K 分辨率

| 宽高        | 比例   |
| --------- | ---- |
| 2048x2048 | 1:1  |
| 2304x1728 | 4:3  |
| 2496x1664 | 3:2  |
| 2560x1440 | 16:9 |
| 3024x1296 | 21:9 |

### 4K 分辨率

| 宽高        | 比例   |
| --------- | ---- |
| 4096x4096 | 1:1  |
| 4694x3520 | 4:3  |
| 4992x3328 | 3:2  |
| 5404x3040 | 16:9 |
| 6198x2656 | 21:9 |

## 相关接口

* [即梦图像概览](./overview)
* [图像生成](./generation)
* [图像编辑](./edit)
* [官方格式查询](./official-query)
