# Midjourney API

{% hint style="danger" %}
此文档已停止维护，最新文档地址：<https://docs.ttapi.io>
{% endhint %}

## 速度模式 <a href="#mo-shi" id="mo-shi"></a>

TTAPI 的 Midjourney 服务提供 **relax**、**fast** 和 **turbo** 三种模式的图像生成，与 Midjourney 对应。

* **fast** 模式响应一般在 **60秒内**
* **relax** 模式响应一般在 **120秒内**
* **turbo** 模式响应一般在 **30秒内**

{% hint style="info" %}
最多可以 **同时执行 10 个生成队列**，如需更多作业队列请 [联系我们](https://ttapi.io/contact)
{% endhint %}

## 使用模式

TTAPI支持两种账户使用模式，满足不同用户、不同场景以及不同体量的使用需求。

* **PPU 模式**（Pay for per use）按量付费，即使用TTAPI账户池中账户执行 Midjourney 任务，无需关注于账户的相关问题。
* **账户托管模式**，将你的账户托管在TTAPI平台上执行Midjourney任务。具体区别详见 [托管模式和PPU模式](/faq/midjourney/jie-kou-wen-ti-jie-da.md#ppu-mo-shi-hold-account-zhang-hu-tuo-guan-mo-shi)

## 生成图像\[/imagine]

{% hint style="info" %}

* **托管模式的host与PPU模式不相同**
  {% endhint %}

<mark style="color:green;">`POST`</mark>  `https://api.ttapi.io/midjourney/v1/imagine`

> Imagine 接口将根据文案生成4张图像。

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

**Body**

<table><thead><tr><th width="182">参数</th><th width="122">类型</th><th width="101">是否必须</th><th>描述</th></tr></thead><tbody><tr><td><code>prompt</code></td><td>string</td><td>是</td><td><p>用以生成图像的提示词</p><p> 例：a cat --ar 1:1</p></td></tr><tr><td><code>hookUrl</code></td><td>string</td><td>否</td><td>回调地址，任务完成或失败将通过请地址进行通知。如果未设置，则需要请求<a href="/pages/HxIcHS2R2BZ8nrRgMQNL#fetch-cha-xun-zuo-ye">fetch</a> 接口进行查询。</td></tr><tr><td><code>mode</code></td><td>string</td><td>否</td><td>生成图像的任务模式，包括<a href="/pages/mRrb1oyXp1N3J2W7ppEu#mo-shi"> relax、fast和turbo</a>。如果未填写，则默认情况下将使用 fast 模式。</td></tr><tr><td><code>timeout</code></td><td>int</td><td>否</td><td>任务执行超时时间，单位：秒，范围 300 - 1200。<br>fast与turbo模式下默认与最小值为300<br>relax模式下默认与最小值为600。</td></tr><tr><td><code>getUImages</code></td><td>boolean</td><td>否</td><td>是否获取四张小图，可选值为 <strong>true, false</strong>  默认为 <strong>false，</strong>对应的返回结果为<a href="#yi-bu-hui-tiao-json-jie-gou">JSON结构</a>中images字段<strong>。</strong>注意：此操作并不是真正对生成的任务执行U操作，选择true之后依然可以进行U放大</td></tr><tr><td><code>translation</code></td><td>boolean</td><td>否</td><td>是否翻译<br><strong>true</strong>-翻译 <br><strong>false</strong>-不翻译 <br>默认<strong>true</strong></td></tr></tbody></table>

{% hint style="info" %}
如果 hookUrl 不为空，系统会向您设置的 hookUrl 发送一个 [json响应](#yi-bu-hui-tiao-json-jie-gou)。
{% endhint %}

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/imagine"

headers = {
    "TT-API-KEY": your_key
}

data = {
    "prompt": "a cute cat",
    "mode": "fast",
    "hookUrl": "",
    "timeout": 300
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

<pre><code><strong>&#x3C;?php
</strong>
$url = 'https://api.ttapi.io/midjourney/v1/imagine';

$data = array(
    'prompt' => 'a cat --ar 1:1',
    'model' => 'fast',
    'hookUrl' => '',
    'timeout' => 300
);

$ch = curl_init($url);

$dataString = json_encode($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
));

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
</code></pre>

{% endtab %}

{% tab title="Node" %}

```
const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/midjourney/v1/imagine',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
    "prompt": "a cute cat",
    "model": "fast",
    "hookUrl": "",
    "timeout": 300
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
```

{% endtab %}
{% endtabs %}

#### 响应示例

{% tabs %}
{% tab title="200" %}

```
{
  "status": "SUCCESS",
  "message": "",
  "data": {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4"
  }
}
```

{% endtab %}

{% tab title="400" %}

```
{
  "status": "FAILED",
  "message": "'action' parameter error!",
  "data": null
}
```

{% endtab %}
{% endtabs %}

## 图像变化\[U1\~U4、V1\~V4]

<mark style="color:green;">`POST`</mark> `https://api.ttapi.io/midjourney/v1/action`

> 此接口包含生成图像下方的按钮操作 例如：U1\~U4，V1\~V4等，具体可参考[ Action操作](#action-ju-ti-shi-yong-cao-zuo)

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

**Body**

<table><thead><tr><th width="155">参数</th><th width="122">类型</th><th width="101">是否必须</th><th>描述</th></tr></thead><tbody><tr><td><code>jobId</code></td><td>string</td><td>是</td><td>上一步请求返回的jobId</td></tr><tr><td><code>action</code></td><td>string</td><td>否</td><td><p>您的具体操作</p><p><strong>例如：</strong></p><p><strong>upsample1 = U1</strong> </p><p><strong>variation1  = V1</strong></p><p><a href="#action-ju-ti-shi-yong-cao-zuo"><strong>更多请参考</strong></a></p></td></tr><tr><td><code>timeout</code></td><td>int</td><td>否</td><td>请求超时时间，单位：秒。如果未填写，默认超时时间 300秒</td></tr><tr><td><code>hookUrl</code></td><td>string</td><td>否</td><td>任务完成或失败将通过请地址进行通知。如果未设置，则需要请求<a href="/pages/HxIcHS2R2BZ8nrRgMQNL#fetch-cha-xun-zuo-ye">fetch</a> 接口进行查询。</td></tr><tr><td><code>getUImages</code></td><td>boolean</td><td>否</td><td>是否获取四张小图，可选值为 <strong>true, false</strong>  默认为 <strong>false，</strong>对应的返回结果为<a href="#yi-bu-hui-tiao-json-jie-gou">JSON结构</a>中<strong><code>images</code></strong>字段<strong>。</strong>注意：此操作并不是真正对生成的任务执行U操作，选择true之后依然可以进行U放大</td></tr></tbody></table>

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/action"

headers = {
    "TT-API-KEY": your_key
}

data = {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4",
    "action": "upsample1",
    "hookUrl": ""
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

```
<?php

$url = 'https://api.ttapi.io/midjourney/v1/action';

$data = array(
    'jobId' => 'afa774a3-1aee-5aba-4510-14818d6875e4',
    'action' => 'upsample1',
    'hookUrl' => ''
);

$ch = curl_init($url);

$dataString = json_encode($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
);

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
```

{% endtab %}

{% tab title="Node" %}

```
const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/midjourney/v1/action',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4",
    "action": "upsample1",
    "hookUrl": ""
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
```

{% endtab %}
{% endtabs %}

#### 响应示例

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "SUCCESS",
  "message": "",
  "data": {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4"
  }
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "status": "FAILED",
  "message": "'action' parameter error!",
  "data": null
}
```

{% endtab %}
{% endtabs %}

## 获取图像种子\[--seed]

<mark style="color:green;">`POST`</mark>  `https://api.ttapi.io/midjourney/v1/seed`

> 从 Midjourney 图像中获取种子，了解具体用法请参阅 [Midjourney文档](https://docs.midjourney.com/docs/en/seeds)

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

**Body**

<table><thead><tr><th width="155">参数</th><th width="122">类型</th><th width="101">是否必须</th><th>描述</th></tr></thead><tbody><tr><td><code>jobId</code></td><td>string</td><td>是</td><td>上一步请求返回的jobId</td></tr><tr><td><code>timeout</code></td><td>int</td><td>否</td><td>请求超时时间，单位：秒。如果未填写，默认超时时间 300秒</td></tr><tr><td><code>hookUrl</code></td><td>string</td><td>否</td><td>任务完成或失败将通过请地址进行通知。如果未设置，则需要请求<a href="/pages/HxIcHS2R2BZ8nrRgMQNL#fetch-cha-xun-zuo-ye">fetch</a> 接口进行查询。</td></tr></tbody></table>

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/seed"

headers = {
    "TT-API-KEY": your_key
}

data = {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4",
    "hookUrl": ""
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

```
<?php

$url = 'https://api.ttapi.io/midjourney/v1/seed';

$data = array(
    'jobId' => 'afa774a3-1aee-5aba-4510-14818d6875e4',
    'hookUrl' => ''
);

$ch = curl_init($url);

$dataString = json_encode($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
);

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
```

{% endtab %}

{% tab title="Node" %}

```
const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/midjourney/v1/seed',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4",
    "hookUrl": ""
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
```

{% endtab %}
{% endtabs %}

#### 响应示例

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "SUCCESS",
  "message": "",
  "data": {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4"
  }
}
```

{% endtab %}
{% endtabs %}

## 图像合成\[/blend]

<mark style="color:green;">`POST`</mark> `https://api.ttapi.io/midjourney/v1/blend`

> 上传2-5个图像，然后根据每个图像的概念和美学，将它们合并为一个新图像。

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

**Body**

<table><thead><tr><th width="195">参数</th><th width="122">类型</th><th width="101">是否必须</th><th>描述</th></tr></thead><tbody><tr><td><code>imgBase64Array</code></td><td>Array</td><td>是</td><td><p>将要生成混图的图片Base64数组</p><p>数组长度为 2-5</p><p>例：[</p><p>"data:image/png;base64,xxx1",        "data:image/png;base64,xxx2"</p><p>]</p></td></tr><tr><td><code>dimensions</code></td><td>string</td><td>否</td><td><p>生成图像的比例，包括PORTRAIT</p><p>、SQUARE、LANDSCAPE。如果未填写，默认使用SQUARE。</p><p></p><p>PORTRAIT 对应比例 2：3</p><p>SQUARE 对应比例 1：1</p><p>LANDSCAPE 对应比例 3：2</p></td></tr><tr><td><code>mode</code></td><td>string</td><td>否</td><td>生成图像的任务模式，包括<a href="/pages/mRrb1oyXp1N3J2W7ppEu#mo-shi"> relax、fast和turbo</a>。如果未填写，则默认情况下将使用 fast 模式。</td></tr><tr><td><code>hookUrl</code></td><td>string</td><td>否</td><td>任务完成或失败将通过请地址进行通知。如果未设置，则需要请求fetch 接口进行查询。</td></tr><tr><td><code>timeout</code></td><td>int</td><td>否</td><td>请求超时时间，单位：秒。如果未填写，默认超时时间 300秒</td></tr><tr><td><code>getUImages</code></td><td>boolean</td><td>否</td><td>是否获取四张小图，可选值为 <strong>true, false</strong>  默认为 <strong>false，</strong>对应的返回结果为<a href="#yi-bu-hui-tiao-json-jie-gou">JSON结构</a>中images字段<strong>。</strong>注意：此操作并不是真正对生成的任务执行U操作，选择true之后依然可以进行U放大</td></tr></tbody></table>

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/blend"

headers = {
    "TT-API-KEY": your_key
}

data = {
    "imgBase64Array": ["data:image/png;base64,xxx1","data:image/png;base64,xxx2"],
    "dimensions": "SQUARE",
    "model": "fast",
    "hookUrl": ""
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

```
<?php

$url = 'https://api.ttapi.io/midjourney/v1/blend';

$data = array(
    "imgBase64Array" => ["data:image/png;base64,xxx1","data:image/png;base64,xxx2"],
    "dimensions" => "SQUARE",
    "model" => "fast",
    "hookUrl" => ""
);

$ch = curl_init($url);

$dataString = json_encode($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
);

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
```

{% endtab %}

{% tab title="Node" %}

```
const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/midjourney/v1/blend',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
    "imgBase64Array": ["data:image/png;base64,xxx1","data:image/png;base64,xxx2"],
    "dimensions": "SQUARE",
    "model": "fast",
    "hookUrl": ""
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
```

{% endtab %}
{% endtabs %}

#### 响应示例

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "SUCCESS",
  "message": "",
  "data": {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4"
  }
}
```

{% endtab %}
{% endtabs %}

## 图像描述词\[/describe]

<mark style="color:green;">`POST`</mark> `https://api.ttapi.io/midjourney/v1/describe`

> 上传图像，并根据该图像生成四个提示信息。

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

**Body**

<table><thead><tr><th width="195">参数</th><th width="122">类型</th><th width="101">是否必须</th><th>描述</th></tr></thead><tbody><tr><td><code>base64</code></td><td>string</td><td>否</td><td><p>图像的base64编码</p><p>字符串"data:image/png;base64,"+ 图片base64值</p><p>例："data:image/png;base64,xxx1"</p></td></tr><tr><td><code>url</code></td><td>string</td><td>否</td><td>图片url地址<br>url参数与base64参数至少存在一个值不为空，若两个字段同时传值，默认取base64字段</td></tr><tr><td><del><code>mode</code></del></td><td>string</td><td>否</td><td><del>生成图像的任务模式，包括</del><a href="/pages/mRrb1oyXp1N3J2W7ppEu#mo-shi"> <del>relax、fast和turbo</del></a><del>。如果未填写，则默认情况下将使用 fast 模式。</del></td></tr><tr><td><code>hookUrl</code></td><td>string</td><td>否</td><td>任务完成或失败将通过请地址进行通知。如果未设置，则需要请求fetch 接口进行查询。</td></tr><tr><td><code>timeout</code></td><td>int</td><td>否</td><td>请求超时时间，单位：秒。如果未填写，默认超时时间 300秒</td></tr></tbody></table>

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/describe"

headers = {
    "TT-API-KEY": your_key
}

data = {
    "base64": "data:image/png;base64,xxx1",
    "model": "fast",
    "hookUrl": ""
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

```
<?php

$url = 'https://api.ttapi.io/midjourney/v1/describe';

$data = array(
    "base64" => "data:image/png;base64,xxx1",
    "model" => "fast",
    "hookUrl" => ""
);

$ch = curl_init($url);

$dataString = json_encode($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
);

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
```

{% endtab %}

{% tab title="Node" %}

```
const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/midjourney/v1/describe',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
    "base64": "data:image/png;base64,xxx1",
    "model": "fast",
    "hookUrl": ""
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
```

{% endtab %}
{% endtabs %}

#### 响应示例

{% tabs %}
{% tab title="200" %}

```
{
  "status": "SUCCESS",
  "message": "",
  "data": {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4"
  }
}
```

{% endtab %}
{% endtabs %}

## 区域重绘\[Vary(region)]

<mark style="color:green;">`POST`</mark> `https://api.ttapi.io/midjourney/v1/inpaint`

> 区域重绘，等同midjourney的Vary(region)按钮

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

**Body**

<table><thead><tr><th width="155">参数</th><th width="122">类型</th><th width="101">是否必须</th><th>描述</th></tr></thead><tbody><tr><td><code>jobId</code></td><td>string</td><td>是</td><td>上一步请求返回的jobId</td></tr><tr><td><code>mask</code></td><td>string</td><td>是</td><td>所选择图片的Base64值<br>提交的base64内容 是一张跟<strong>原图尺寸一样</strong>的黑白通道的蒙版（<strong>就是图中只包括黑色与白色</strong>） 其中白色部分是重绘圈出来的部分 其余部分是黑色<br>该base64值<strong>无需 “data:image/png;base64,”前缀</strong></td></tr><tr><td><code>prompt</code></td><td>string</td><td>否</td><td>对所选择图片区域想要修改的描述</td></tr><tr><td><code>timeout</code></td><td>int</td><td>否</td><td>请求超时时间，单位：秒。如果未填写，默认超时时间 300秒</td></tr><tr><td><code>hookUrl</code></td><td>string</td><td>否</td><td>任务完成或失败将通过请地址进行通知。如果未设置，则需要请求<a href="/pages/HxIcHS2R2BZ8nrRgMQNL#fetch-cha-xun-zuo-ye">fetch</a> 接口进行查询。</td></tr></tbody></table>

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/inpaint"

headers = {
    "TT-API-KEY": your_key
}

data = {
   "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4",
    "prompt": "white background",
    "mask": "UklGRrw0AABXRUJQVlA4WAoAAAAgAAAA..."
    "hookUrl": ""
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

```
<?php

$url = 'https://api.ttapi.io/midjourney/v1/inpaint';

$data = array(
    "jobId" => "afa774a3-1aee-5aba-4510-14818d6875e4",
    "prompt" => "white background",
    "mask"   => "UklGRrw0AABXRUJQVlA4WAoAAAAgAAAA..."
    "hookUrl" => ""
);

$ch = curl_init($url);

$dataString = json_encode($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
);

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
```

{% endtab %}

{% tab title="Node" %}

<pre><code>const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/midjourney/v1/inpaint',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
<strong>    "jobId" => "afa774a3-1aee-5aba-4510-14818d6875e4",
</strong>    "prompt" => "white background",
    "mask"   => "UklGRrw0AABXRUJQVlA4WAoAAAAgAAAA..."
    "hookUrl" => ""
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
</code></pre>

{% endtab %}
{% endtabs %}

#### 响应示例

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "SUCCESS",
  "message": "",
  "data": {
    "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4"
  }
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "status": "FAILED",
  "message": "'action' parameter error!",
  "data": {}
}
```

{% endtab %}
{% endtabs %}

## 获取任务状态 - fetch

<mark style="color:green;">`POST`</mark> `https://api.ttapi.io/midjourney/v1/fetch`

> 查询任务结果，**该接口不消耗quota，免费使用**

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

**Body**

<table><thead><tr><th width="155">参数</th><th width="122">类型</th><th width="101">是否必须</th><th>描述</th></tr></thead><tbody><tr><td><code>jobId</code></td><td>string</td><td>是</td><td>上一步请求返回的jobId</td></tr></tbody></table>

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/fetch"

headers = {
    "TT-API-KEY": your_key
}

data = {
   "jobId": "afa774a3-1aee-5aba-4510-14818d6875e4"
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

```
<?php

$url = 'https://api.ttapi.io/midjourney/v1/fetch';

$data = array(
    "jobId" => "afa774a3-1aee-5aba-4510-14818d6875e4"
);

$ch = curl_init($url);

$dataString = json_encode($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
);

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
```

{% endtab %}

{% tab title="Node" %}

<pre><code>const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/midjourney/v1/fetch',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
<strong>    "jobId" => "afa774a3-1aee-5aba-4510-14818d6875e4"
</strong>  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
</code></pre>

{% endtab %}
{% endtabs %}

#### 响应示例

**`返回结果与`**[**`异步回调`**](#yi-bu-hui-tiao-json-jie-gou)**`数据结构一致`**

## Prompt效验 - Prompt Checker <a href="#prompt-checker" id="prompt-checker"></a>

<mark style="color:green;">`POST`</mark> `https://api.ttapi.io/midjourney/v1/promptCheck`

> 效验imagine接口中的prompt，**该接口不消耗quota，免费使用**

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

**Body**

<table><thead><tr><th width="155">参数</th><th width="122">类型</th><th width="101">是否必须</th><th>描述</th></tr></thead><tbody><tr><td><code>prompt</code></td><td>string</td><td>是</td><td>prompt文案，<strong>注意：该效验目前只对英文文案有效</strong></td></tr></tbody></table>

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/v1/promptCheck"

headers = {
    "TT-API-KEY": your_key
}

data = {
   "prompt": "a sexy girl"
}

response = requests.post(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

```
<?php

$url = 'https://api.ttapi.io/midjourney/v1/promptCheck';

$data = array(
     "prompt"=> "a sexy girl"
);

$ch = curl_init($url);

$dataString = json_encode($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
);

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
```

{% endtab %}

{% tab title="Node" %}

<pre><code>const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/midjourney/v1/promptCheck',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
<strong>    "prompt"=> "a sexy girl"
</strong>  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
</code></pre>

{% endtab %}
{% endtabs %}

#### 响应示例

{% tabs %}
{% tab title="200成功" %}

```json
{
    "status": "SUCCESS",
    "message": "success",
    "data": "Prompt verification successful."
}
```

{% endtab %}

{% tab title="200失败" %}

```
{
    "status": "FAILED",
    "message": "banned prompt words：sexy",
    "data": null
}
```

{% endtab %}

{% tab title="400" %}

```
{
    "status": "FAILED",
    "message": "\"prompt\" cannot be empty.",
    "data": null
}
```

{% endtab %}
{% endtabs %}

## Midjourney服务状态查询 <a href="#midjourney-status" id="midjourney-status"></a>

<mark style="color:red;">`GET`</mark> `https://api.ttapi.io/midjourney/status`

> 查询Midjourney API服务各个接口状&#x6001;**，该接口不消耗quota，免费使用**

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| TT-API-KEY   | 用于请求授权 TT-API 的API密钥 |
| Content-Type | application-json     |

#### 请求示例

{% tabs %}
{% tab title="Python" %}

```
import requests

endpoint = "https://api.ttapi.io/midjourney/status"

headers = {
    "TT-API-KEY": your_key
}


response = requests.get(endpoint, headers=headers, json=data)

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Php" %}

```
<?php

$url = 'https://api.ttapi.io/midjourney/status';


$ch = curl_init($url);


curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'TT-API-KEY: your_key'
);

$result = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpCode;
```

{% endtab %}

{% tab title="Node" %}

```
const axios = require('axios');

let config = {
  method: 'get',
  url: 'https://api.ttapi.io/midjourney/status',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {}
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});
```

{% endtab %}
{% endtabs %}

#### 响应示例

{% tabs %}
{% tab title="200成功" %}

```json
{
    "status": "SUCCESS",
    "message": "success",
    "data": {
        "fast": {
            "status": 200,
            "runningMessage": "Endpoints running",
            "averageExecute": 46.42
        },
        "relax": {
            "status": 200,
            "runningMessage": "Endpoints running",
            "averageExecute": 39.37
        },
        "turbo": {
            "status": 200,
            "runningMessage": "Endpoints running",
            "averageExecute": 23.87
        }
    }
}
```

{% endtab %}
{% endtabs %}

### Action 具体使用操作

{% hint style="info" %}
关于相关操作的具体用法，您可以详细阅读 [Midjourney官方文档](https://docs.midjourney.com/v1/docs)
{% endhint %}

<table><thead><tr><th>操作名称</th><th>描述</th><th data-type="files">midjourney 示例</th><th data-hidden>description</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>upsample1</strong></td><td><p><strong>U1-U4</strong> 按钮</p><p><strong>upsample2,  upsample3, upsample4</strong> 同理</p></td><td><a href="/files/uyupsCDTQULYJxcu13xI">/files/uyupsCDTQULYJxcu13xI</a></td><td>Zoom into the first of the four images generated</td><td></td></tr><tr><td><strong>variation1</strong></td><td><strong>V1-V4</strong> 按钮<br><strong>variation2, variation3, variation4</strong> 同理</td><td><a href="/files/PkMAQf0OoF6ZqaykZ6wM">/files/PkMAQf0OoF6ZqaykZ6wM</a></td><td></td><td></td></tr><tr><td><strong>high_variation</strong></td><td><strong>Vary (Strong)</strong>按钮<br>对图片进行大幅变化</td><td><a href="/files/wPVLoMaQzxEOSt298BLm">/files/wPVLoMaQzxEOSt298BLm</a></td><td></td><td></td></tr><tr><td><strong>low_variation</strong></td><td><strong>Vary (Subtle)</strong> 按钮<br>对图片进行小幅变化</td><td><a href="/files/U958taVJ0kzCq5a4SZTh">/files/U958taVJ0kzCq5a4SZTh</a></td><td></td><td></td></tr><tr><td><strong>upscale2</strong></td><td>U<strong>pscale(2x)</strong> 按钮<br>图像放大 2 倍，只存在于v5模式 </td><td><a href="/files/F7CYQllaGgXNAIKrSv0X">/files/F7CYQllaGgXNAIKrSv0X</a></td><td></td><td></td></tr><tr><td><strong>upscale4</strong></td><td>U<strong>pscale(4x)</strong> 按钮<br>图像放大 4 倍，只存在于v5模式 </td><td><a href="/files/Pd8HjUxffJyV5PUvbBb2">/files/Pd8HjUxffJyV5PUvbBb2</a></td><td></td><td></td></tr><tr><td><strong>zoom_out_2</strong></td><td><p><strong>Zoom Out 2x</strong> 按钮</p><p>“缩小”选项在不更改原始图片的情况下展开放大图像的画布，根据提示和初始图像填充新空间。</p></td><td><a href="/files/O3ND6EkAvlu42kek6opZ">/files/O3ND6EkAvlu42kek6opZ</a></td><td></td><td></td></tr><tr><td><strong>zoom_out_1_5</strong></td><td><strong>Zoom Out 1.5x</strong> 按钮<br>“缩小”选项在不更改原始图片的情况下展开放大图像的画布，根据提示和初始图像填充新空间。</td><td><a href="/files/0qZJSfGuiqOtVYKyUqqz">/files/0qZJSfGuiqOtVYKyUqqz</a></td><td></td><td></td></tr><tr><td><strong>pan_left</strong></td><td><strong>⬅️➡️⬆️⬇️</strong> 按钮<br>在选定方向上平移展开图像画布，而不会更改原始内容。根据初始图像和提供的提示填充扩展区域。<strong>pan_right, pan_up, pan_down</strong> 同理</td><td><a href="/files/Bs4yWQLZRQlWWvCPf2mx">/files/Bs4yWQLZRQlWWvCPf2mx</a></td><td></td><td></td></tr><tr><td><strong>upscale_creative</strong></td><td><strong>Upscale(Creative)</strong> 按钮<br>只存在于v6模式</td><td><a href="/files/b0FQp1wEE3oV986xZlpH">/files/b0FQp1wEE3oV986xZlpH</a></td><td></td><td></td></tr><tr><td><strong>upscale_subtle</strong></td><td><strong>Upscale(Subtle)</strong> 按钮<br>只存在于v6模式</td><td><a href="/files/QCKTIS4lWAyv0KSalMHY">/files/QCKTIS4lWAyv0KSalMHY</a></td><td></td><td></td></tr><tr><td><strong>reroll</strong></td><td>基于上一个prompt重新生成。<strong>🔄按钮</strong></td><td><a href="/files/KFjlvrXTEwFhTr5Z2xIx">/files/KFjlvrXTEwFhTr5Z2xIx</a></td><td></td><td></td></tr><tr><td><strong>redo_upscale2</strong></td><td><strong>Redo Upscale(2x)</strong> 按钮<br>重新对图像放大 2 倍，只存在于v5模式 </td><td><a href="/files/fVzgKgKHxo9TnOVSKNdp">/files/fVzgKgKHxo9TnOVSKNdp</a></td><td></td><td></td></tr><tr><td><strong>redo_upscale4</strong></td><td><strong>Redo Upscale(4x)</strong> 按钮<br>重新对图像放大 4 倍，只存在于v5模式 </td><td><a href="/files/OAL2NWvWNFBfba4UdiOR">/files/OAL2NWvWNFBfba4UdiOR</a></td><td></td><td></td></tr><tr><td><strong>make_square</strong></td><td><strong>Make Square 按钮</strong><br>将非方形图像变更为方形图像</td><td><a href="/files/WheHsz1NLuUd1EqlgaR3">/files/WheHsz1NLuUd1EqlgaR3</a></td><td></td><td></td></tr><tr><td><strong>redo_upscale_subtle</strong></td><td><p><strong>Redo Upscale(Subtle)</strong> 按钮<br>重新执行Upscale(Subtle) ，</p><p>只存在于v6模式</p></td><td><a href="/files/coFRgZtzjU26bRyFsWzY">/files/coFRgZtzjU26bRyFsWzY</a></td><td></td><td></td></tr><tr><td><strong>redo_upscale_creative</strong></td><td><strong>Redo Upscale(Creative)</strong> 按钮<br>重新执行Upscale(Creative) ，<br>只存在于v6模式</td><td><a href="/files/tvcRiWwr7hzBoDp5556X">/files/tvcRiWwr7hzBoDp5556X</a></td><td></td><td></td></tr></tbody></table>

### 异步回调 JSON 结构

{% tabs %}
{% tab title="SUCCESS" %}

```
{
    "status": "SUCCESS",
    "jobId": "f5850038-90a3-8a97-0476-107ea4b8dac4",
    "message": "success",
    "data": {
        "actions": "imagine",
        "jobId": "f5850038-90a3-8a97-0476-107ea4b8dac4",
        "progress": "100",
        "prompt": "Soccer star Max Kruse and Jan-Peter Jachtmann victims of €528,695 poker scam, German soccer star Max Kruse and WSOP Main Event finalist Jan-Peter Jachtmann are among the players who have been swindled out of €528,695., poker, realistic --ar 1280:720",
        "discordImage": "https://cdn.discordapp.com/attachments/1107938555931656214/1176340921227423844/voyagel_Soccer_star_Max_Kruse_and_Jan-Peter_Jachtmann_victims_o_c513a87b-eed3-4a3b-ab97-6be4dbc3ea99.png?ex=656e83da&is=655c0eda&hm=6e06a1dec3c6c1be209799884681969878eabb81ce81f8db22d54480379fcd9b&",
        "cdnImage": "http://127.0.0.1/8080/pics/452020f2-6793-4525-a1b5-472cac439610.png",
        "width": 1632,
        "height": 2912,
        "hookUrl": "",
        "components": [
            "upsample1",
            "upsample2",
            "upsample3",
            "upsample4",
            "variation1",
            "variation2",
            "variation3",
            "variation4"
        ],
        "seed":"",
        "images": [
            "https://cdnb.ttapi.io/2024-04-02/5ac3b82974cfbc394ff70fdb3f8ad243a78cce8c3cd88defee12739db0b499f9.png",
            "https://cdnb.ttapi.io/2024-04-02/41c7a7dfc8ec9871d7aa6f45bbcb3ca7dcb967cadef285ae3b05b2fce63e9fa5.png",
            "https://cdnb.ttapi.io/2024-04-02/1d62e5110d24de42e8ac4894108874885b8460e5cbd212fe19ad756b1bf15087.png",
            "https://cdnb.ttapi.io/2024-04-02/a1887b8f816286df67cc83d0b1cc07450b2558bc28a60fbea4991f4ae390652c.png"
        ],
        "quota": 3
    }
}
```

{% endtab %}

{% tab title="PENDING\_QUEUE" %}

```
{
    "status": "PENDING_QUEUE",
    "jobId": "f5850038-90a3-8a97-0476-107ea4b8dac4",
    "message": "",
    "data": []
}
```

{% endtab %}

{% tab title="ON\_QUEUE" %}

```
{
    "status": "ON_QUEUE",
    "jobId": "f5850038-90a3-8a97-0476-107ea4b8dac4",
    "message": "",
    "data": {
        "actions": "imagine",
        "jobId": "f5850038-90a3-8a97-0476-107ea4b8dac4",
        "progress": "100",
        "prompt": "Soccer star Max Kruse and Jan-Peter Jachtmann victims of €528,695 poker scam, German soccer star Max Kruse and WSOP Main Event finalist Jan-Peter Jachtmann are among the players who have been swindled out of €528,695., poker, realistic --ar 1280:720",
        "discordImage": "https://cdn.discordapp.com/attachments/1107938555931656214/1176340921227423844/voyagel_Soccer_star_Max_Kruse_and_Jan-Peter_Jachtmann_victims_o_c513a87b-eed3-4a3b-ab97-6be4dbc3ea99.png?ex=656e83da&is=655c0eda&hm=6e06a1dec3c6c1be209799884681969878eabb81ce81f8db22d54480379fcd9b&",
        "cdnImage": "http://127.0.0.1/8080/pics/452020f2-6793-4525-a1b5-472cac439610.png",
        "width": null,
        "height": null,
        "hookUrl": "",
        "components": [],
        "seed": null,
        "images": null
    }
}
```

{% endtab %}

{% tab title="FAILED" %}

```
{
    "status": "FAILED",
    "jobId": "f5850038-90a3-8a97-0476-107ea4b8dac4",
    "message": "failed",
    "data": []
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
自2023年12月1日开始，discord返回的cdn图片链接将在24-72小时之内过期。
{% endhint %}

{% hint style="info" %}
自2024年09月13日开始，TTAPI的Midjourney服务的`cdnImage`字段的域名由原来的 `https://mjcdn.ttapi.io` 变更至 `https://cdnb.ttapi.io`
{% endhint %}

### 返回JSON结构详解

| name         | value                                                                                   |
| ------------ | --------------------------------------------------------------------------------------- |
| status       | <p>PENDING\_QUEUE //排队中</p><p>ON\_QUEUE  //执行中</p><p>SUCCESS   //成功<br>FAILED  //失败</p> |
| progess      | 进度 : 0-100，100为完成                                                                       |
| components   | [支持的下一步操作](#action-ju-ti-shi-yong-cao-zuo)                                              |
| discordImage | discord的cdn图片地址，**24小时**后过期                                                             |
| cdnImage     | 国内可访问的cdn代理地址，**24小时**后过期                                                               |
| images       | ttapi的cdn地址，imagine命令生成的四张小图，至少保证留存**一个月**                                              |
| quota        | 实际消耗额度                                                                                  |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-zh.mjapiapp.com/api/midjourney-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
