# 生成图像（Midjourney）
> 文生图走 `/mj/submit/imagine`
> 混图走 `/mj/submit/blend`，反推走 `/mj/submit/describe`
> 三者的传参结构不同，不能混用
`POST /mj/submit/imagine`
## 认证
- `Authorization` (string / 必填) — 所有接口均使用 Bearer Token 进行认证。 获取 API Key：[访问控制台](https://api.oairoute.com/keys) 创建。 请求时在请求头中添加： ```http Authorization: Bearer YOUR_OAIRoute_KEY ```
## 三种生成方式
| 方式 | 端点 | 说明 |
|---|---|---|
| 文生图 | `POST /mj/submit/imagine` | 只给提示词，出一个四宫格 |
| 图片融合 | `POST /mj/submit/blend` | 2 到 5 张图融合，不接受 `prompt` |
| 反推提示词 | `POST /mj/submit/describe` | 传 1 张图，返回 4 条提示词候选 |
> **Note:** 
> 原生 MJ 参数直接写在 `prompt` 里，例如 `a cute cat --ar 16:9 --v 7`。请求体里没有单独的 `size`、`version` 字段。
## 请求参数
- `prompt` (string / 条件必填) — 提示词，`/imagine` 必填。原生 MJ 参数可内联。
- `botType` (string / 可选) — bot 类型，`MID_JOURNEY`（默认）或 `NIJI_JOURNEY`。
- `base64Array` (array / 条件必填) — 垫图，`data:image/png;base64,...` 形式。`/blend` 必填，2 到 5 张。
- `dimensions` (string / 可选) — 仅 `/blend` 使用，比例 `PORTRAIT`（2:3）、`SQUARE`（1:1）、`LANDSCAPE`（3:2）。
- `base64` (string / 可选) — 仅 `/describe` 使用，图片 Base64，与 `link` 二选一。
- `link` (string / 可选) — 仅 `/describe` 使用，图片链接，与 `base64` 二选一。
- `language` (string / 可选) — 仅 `/describe` 使用，返回语言 `en`（默认）或 `zh_cn`。
- `notifyHook` (string / 可选) — 回调地址，任务完成时平台向该地址 POST 结果。
- `noStorage` (boolean / 可选) — 为 `true` 时返回官方链接而非平台转存链接，默认 `false`。
- `state` (string / 可选) — 自定义透传字段，原样带回。
- `accountFilter` (object / 可选) — 账号筛选，`modes` 可指定 `["RELAX"]` 这类速度模式。
## 常用 MJ 参数
直接写在 `prompt` 末尾：
| 参数 | 含义 | 取值 |
|---|---|---|
| `--ar` | 画幅比例 | 如 `16:9`、`3:4` |
| `--v` | 模型版本 | 如 `7`、`6.1` |
| `--niji` | 动漫风格 | 无值或版本号 |
| `--s` | 艺术化强度 | 0 到 1000 |
| `--c` | 变化程度 | 0 到 100 |
| `--no` | 反向描述 | 如 `--no text` |
| `--tile` | 平铺模式 | 无值 |
| `--q` | 画质 | `0.25`、`0.5`、`1`、`2` |
| `--seed` | 随机种子 | 整数 |
## 融合的画幅
`/blend` 用 `dimensions` 指定画幅，都没传时默认方形。提示词里没有 `--ar` 的概念，这个端点不接受 `prompt`。
## 反推提示词
`/describe` 返回的字段是 `prompt` 与 `description`，不含图片地址。它通常 1 到 3 秒完成，但仍走标准异步流程，要 fetch 任务取结果。
## 错误码
| HTTP | 含义 |
|---|---|
| 200 | 请求已受理。要看 `code` 判断是否成功，`1` 才是成功 |
| 401 | Token 缺失或无效 |
| 429 | 触发限流 |
常见失败：`prompt` 缺失；`/blend` 传的图少于 2 张或多于 5 张；`/describe` 同时传了 `base64` 与 `link`。
更多状态码与重试建议见[错误码与限流](../../../support/errors.html)，常见报错的排查步骤见[常见问题](../../../support/faq.html)。
## 使用示例
### 文生图
提交后拿任务 ID，再 fetch 取四宫格。画幅、版本这些参数都写在提示词里。
### 图片融合
`base64Array` 传 2 到 5 张图，`dimensions` 决定画幅。融合完成后同样要 fetch 取结果。
### 反推提示词
把一张参考图丢进去，得到 4 条候选提示词，挑一条再送去 `/imagine`。
**文生图{Text to image}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/mj/submit/imagine' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "botType": "MID_JOURNEY",
  "prompt": "a cute cat --ar 16:9 --v 7",
  "notifyHook": "",
  "noStorage": false
}'
```
**文生图{Text to image}::Python**
```
import requests

res = requests.post(
    "https://api.oairoute.com/mj/submit/imagine",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "botType": "MID_JOURNEY",
        "prompt": "a cute cat --ar 16:9 --v 7",
        "noStorage": False,
    },
)
print(res.json())
```
**文生图{Text to image}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/mj/submit/imagine", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    botType: "MID_JOURNEY",
    prompt: "a cute cat --ar 16:9 --v 7",
    noStorage: false,
  }),
});
console.log(await res.json());
```
**图片融合{Blend}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/mj/submit/blend' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "botType": "MID_JOURNEY",
  "base64Array": [
    "data:image/png;base64,iVBORw0KGgo...",
    "data:image/png;base64,iVBORw0KGgo..."
  ],
  "dimensions": "SQUARE"
}'
```
**图片融合{Blend}::Python**
```
import base64, pathlib, requests

def data_uri(path):
    return "data:image/png;base64," + base64.b64encode(pathlib.Path(path).read_bytes()).decode()

res = requests.post(
    "https://api.oairoute.com/mj/submit/blend",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "botType": "MID_JOURNEY",
        "base64Array": [data_uri("a.png"), data_uri("b.png")],
        "dimensions": "SQUARE",
    },
)
print(res.json())
```
**图片融合{Blend}::JavaScript**
```
import { readFileSync } from "node:fs";

const toUri = (p) => "data:image/png;base64," + readFileSync(p).toString("base64");
const res = await fetch("https://api.oairoute.com/mj/submit/blend", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    botType: "MID_JOURNEY",
    base64Array: [toUri("a.png"), toUri("b.png")],
    dimensions: "SQUARE",
  }),
});
console.log(await res.json());
```
**反推提示词{Describe}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/mj/submit/describe' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "botType": "MID_JOURNEY",
  "link": "https://example.com/image.jpg",
  "language": "en"
}'
```
**反推提示词{Describe}::Python**
```
import requests

res = requests.post(
    "https://api.oairoute.com/mj/submit/describe",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "botType": "MID_JOURNEY",
        "link": "https://example.com/image.jpg",
        "language": "en",
    },
)
print(res.json())
```
**反推提示词{Describe}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/mj/submit/describe", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    botType: "MID_JOURNEY",
    link: "https://example.com/image.jpg",
    language: "en",
  }),
});
console.log(await res.json());
```
**200 文生图{Text to image}**
```
{
  "code": 1,
  "description": "提交成功",
  "result": "1320098173412546"
}
```
**200 图片融合{Blend}**
```
{
  "code": 1,
  "description": "提交成功",
  "result": "1320098173412547"
}
```
**200 反推提示词{Describe}**
```
{
  "code": 1,
  "description": "提交成功",
  "result": "1320098173412548"
}
```
