qidao123.com技术社区-IT企服评测·应用市场

标题: Midjourney Tasks API 的对接和使用 [打印本页]

作者: tsx81429    时间: 2024-10-31 02:43
标题: Midjourney Tasks API 的对接和使用
Midjourney Tasks API 的主要功能是通过输入Midjourney Imagine API 或 Midjourney Describe API 生成的任务ID来查询该任务的执行情况。
本文档将详细先容 Midjourney Tasks API 的对接阐明,帮助您轻松集成并充分利用该 API 的强大功能。通过 Midjourney Tasks API ,您可以轻松实现查询 Midjourney Imagine API 或 Midjourney Describe API 的任务执行情况。
申请流程

要使用 Midjourney Tasks API,必要先到 申请页面 Midjourney Imagine API 申请相应的服务,然后复制Imagine API的任务ID,如图所示:


最后进入Tasks API页面 Midjourney Tasks API 申请相应的服务,进入页面之后,点击「Acquire」按钮,如图所示:


如果您尚未登录或注册,会自动跳转到登录页面约请您来注册和登录,登录注册之后会自动返回当前页面。
首次申请时会有免费额度赠送,可以免费使用该 API。
请求示例

MIdjourney Tasks API 可以用于查询 MIdjourney Imagine API 和 MIdjourney Describe API 两个 API 的结果。关于怎样使用 MIdjourney Imagine API,请参考文档 Midjourney Imagine API 。关于怎样使用 Midjourney Describe,请参考 Midjourney Describe API 。
我们以 Midjourney Imagine API 服务返回的任务ID一个为例,演示怎样使用该 API。假设我们有一个任务ID:7489df4c-ef03-4de0-b598-e9a590793434,接下来演示怎样通过传入一个任务ID来。
任务示例图



设置请求头和请求体

Request Headers 包括:

Request Body 包括:

设置如下图所示:


代码示例

可以发现,在页面右侧已经自动生成了各种语言的代码,如图所示:


部门代码示例如下:
CURL

bash curl -X POST 'https://api.acedata.cloud/midjourney/tasks' \ -H 'accept: application/json' \ -H 'authorization: Bearer {token}' \ -H 'content-type: application/json' \ -d '{ "id": "7489df4c-ef03-4de0-b598-e9a590793434", "action": "retrieve" }'
Python

```python import requests
url = "https://api.acedata.cloud/midjourney/tasks"
headers = { "accept": "application/json", "authorization": "Bearer {token}", "content-type": "application/json" }
payload = { "id": "7489df4c-ef03-4de0-b598-e9a590793434", "action": "retrieve" }
response = requests.post(url, json=payload, headers=headers) print(response.text) ```
响应示例

请求乐成后,API 将返回此处图片任务的详情信息。例如:
json { "_id": "668aae3f550a4144a540803b", "id": "7489df4c-ef03-4de0-b598-e9a590793434", "application_id": "9dec7b2a-1cad-41ff-8536-d4ddaf2525d4", "created_at": 1720364607.967, "credential_id": "68253cc8-505d-47f4-97ad-0050a62e4975", "request": { "mode": "fast", "prompt": "A cat sitting on a table", "action": "generate" }, "type": "imagine", "hold": false, "image_id": "1259525319472185344", "job_id": "da317da6-f500-48e6-bf32-dd48b3e6f84f", "response": { "image_url": "https://platform.cdn.acedata.cloud/midjourney/7489df4c-ef03-4de0-b598-e9a590793434.png?imageMogr2/thumbnail/!50p", "image_width": 1024, "image_height": 1024, "actions": [ "upscale1", "upscale2", "upscale3", "upscale4", "reroll", "variation1", "variation2", "variation3", "variation4" ], "raw_image_url": "https://platform.cdn.acedata.cloud/midjourney/7489df4c-ef03-4de0-b598-e9a590793434.png", "raw_image_width": 2048, "raw_image_height": 2048, "progress": 100, "image_id": "1259525319472185344", "task_id": "7489df4c-ef03-4de0-b598-e9a590793434", "success": true, "job_id": "da317da6-f500-48e6-bf32-dd48b3e6f84f", "hold": false }, "duration": 29.437000036239624, "finished_at": 1720364637.404 }
返回结果一共有多个字段,request 字段就是发起任务时的 request body,同时response 字段是任务完成后返回的response body,如果 type = imagine,其结果和 Midjourney Imagine API 的请求和返回同等,如果 type = describe,其结果和 Midjourney Describe API 的请求和返回同等。字段先容如下。

批量查询操作

这是是针对多个任务ID来举行查询图片任务详情,与上面不同的是必要将action选中为retrieve_batch
Request Body 包括:

设置如下图所示:


代码示例

可以发现,在页面右侧已经自动生成了各种语言的代码,如图所示:


部门代码示例如下:
CURL

bash curl -X POST 'https://api.acedata.cloud/midjourney/tasks' \ -H 'accept: application/json' \ -H 'authorization: Bearer {token}' \ -H 'content-type: application/json' \ -d '{ "action": "retrieve_batch", "id": "", "ids": ["7489df4c-ef03-4de0-b598-e9a590793434","807f62de-c63e-4add-8345-7f0ae6dd18e7"] }'
Python

```python import requests
url = "https://api.acedata.cloud/midjourney/tasks"
headers = { "accept": "application/json", "authorization": "Bearer {token}", "content-type": "application/json" }
payload = { "action": "retrieve_batch", "id": "", "ids": ["7489df4c-ef03-4de0-b598-e9a590793434","807f62de-c63e-4add-8345-7f0ae6dd18e7"] }
response = requests.post(url, json=payload, headers=headers) print(response.text) ```
响应示例

请求乐成后,API 将返回此次全部批量图片任务的详细详情信息。例如:
json { "items": [ { "_id": "668aae3f550a4144a540803b", "id": "7489df4c-ef03-4de0-b598-e9a590793434", "application_id": "9dec7b2a-1cad-41ff-8536-d4ddaf2525d4", "created_at": 1720364607.967, "credential_id": "68253cc8-505d-47f4-97ad-0050a62e4975", "request": { "mode": "fast", "prompt": "A cat sitting on a table", "action": "generate" }, "type": "imagine", "hold": false, "image_id": "1259525319472185344", "job_id": "da317da6-f500-48e6-bf32-dd48b3e6f84f", "response": { "image_url": "https://platform.cdn.acedata.cloud/midjourney/7489df4c-ef03-4de0-b598-e9a590793434.png?imageMogr2/thumbnail/!50p", "image_width": 1024, "image_height": 1024, "actions": [ "upscale1", "upscale2", "upscale3", "upscale4", "reroll", "variation1", "variation2", "variation3", "variation4" ], "raw_image_url": "https://platform.cdn.acedata.cloud/midjourney/7489df4c-ef03-4de0-b598-e9a590793434.png", "raw_image_width": 2048, "raw_image_height": 2048, "progress": 100, "image_id": "1259525319472185344", "task_id": "7489df4c-ef03-4de0-b598-e9a590793434", "success": true, "job_id": "da317da6-f500-48e6-bf32-dd48b3e6f84f", "hold": false }, "duration": 29.437000036239624, "finished_at": 1720364637.404 }, { "_id": "668b41d6550a4144a551d996", "id": "807f62de-c63e-4add-8345-7f0ae6dd18e7", "application_id": "9dec7b2a-1cad-41ff-8536-d4ddaf2525d4", "created_at": 1720402390.341, "credential_id": "6fd3e1d5-4bd6-47e8-8872-fab89a183b53", "request": { "mode": "fast", "prompt": "A beautiful girl", "action": "generate" }, "type": "imagine", "hold": false, "image_id": "1259683790612070400", "job_id": "ede5c805-e231-498c-8f74-3aa76d5d6d12", "response": { "image_url": "https://platform.cdn.acedata.cloud/midjourney/807f62de-c63e-4add-8345-7f0ae6dd18e7.png?imageMogr2/thumbnail/!50p", "image_width": 1024, "image_height": 1024, "actions": [ "upscale1", "upscale2", "upscale3", "upscale4", "reroll", "variation1", "variation2", "variation3", "variation4" ], "raw_image_url": "https://platform.cdn.acedata.cloud/midjourney/807f62de-c63e-4add-8345-7f0ae6dd18e7.png", "raw_image_width": 2048, "raw_image_height": 2048, "progress": 100, "image_id": "1259683790612070400", "task_id": "807f62de-c63e-4add-8345-7f0ae6dd18e7", "success": true, "job_id": "ede5c805-e231-498c-8f74-3aa76d5d6d12", "hold": false }, "duration": 29.471999883651733, "finished_at": 1720402419.813 } ], "count": 2 }
返回结果一共有多个字段,其中items是包含了批量图片任务的详细详情信息,每个图片任务的详细信息与上文的字段一样,字段信息如下。

错误处理

在调用 API 时,如果碰到错误,API 会返回相应的错误代码和信息。例如:

错误响应示例

{ "success": false, "error": { "code": "api_error", "message": "fetch failed" }, "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89" }
结论

通过本文档,您已经了解了怎样使用 Midjourney Tasks API 举行查询单个或批量图片任务的全部详细详情信息。盼望本文档能帮助您更好地对接和使用该 API。如有任何题目,请随时接洽我们的技能支持团队。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 qidao123.com技术社区-IT企服评测·应用市场 (https://dis.qidao123.com/) Powered by Discuz! X3.4