🔥Midjourney API

Midjourney相关API,包含目前v5-v6所有操作。TTAPI 的 Midjourney API 是目前最稳定、最具成本效益的 Midjourney 产品。

模式

TT API 的 Midjourney 服务提供 relaxfastturbo 三种模式的图像生成,与 Midjourney 对应。

  • fast 模式响应时间在 90秒内,整体成功率 超过98%

  • relax 模式响应一般在 10分钟内根据官方响应,总体成功率超过90%

  • turbo 模式响应时间在 60秒内

最多可以 同时执行 10 个生成队列,如需更多作业队列请 联系我们

生成图像[/imagine]

Midjourney 6.0 版本的 “Imagine 接口配额消耗将是其他模型的1.5倍。

--cref 操作必须配合 --v 6.0 模型使用

POST https://api.ttapi.io/midjourney/v1/imagine

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

Headers

Body

如果 hookUrl 不为空,系统会向您设置的 hookUrl 发送一个 json响应

请求示例

import requests

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

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

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

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

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

响应示例

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

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

POST https://api.ttapi.io/midjourney/v1/action

此接口包含生成图像下方的按钮操作 例如:U1~U4,V1~V4等,具体可参考 Action操作

Headers

Body

请求示例

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())

响应示例

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

获取图像种子[--seed]

POST https://api.ttapi.io/midjourney/v1/seed

从 Midjourney 图像中获取种子,了解具体用法请参阅 Midjourney文档

Headers

Body

请求示例

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())

响应示例

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

图像合成[/blend]

POST https://api.ttapi.io/midjourney/v1/blend

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

Headers

Body

请求示例

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())

响应示例

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

图像描述词[/describe]

POST https://api.ttapi.io/midjourney/v1/describe

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

Headers

Body

请求示例

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())

响应示例

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

区域重绘[Vary(region)]

POST https://api.ttapi.io/midjourney/v1/inpaint

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

Headers

Body

请求示例

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())

响应示例

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

获取任务状态 - fetch

POST https://api.ttapi.io/midjourney/v1/fetch

查询任务结果

Headers

Body

Response

返回结果与异步回调数据结构一致

Action 具体使用操作

关于相关操作的具体用法,您可以详细阅读 Midjourney官方文档

异步回调 JSON 结构

{
    "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",
        "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"
        ]
    }
}

从2023年12月1日开始,discord返回的cdn图片链接将在24-72小时之内过期。

返回JSON结构详解

Last updated