Skip to content

Midjourney Integration Guide - Code Examples

  • This chapter uses Submit Imagine Task as an example to show how to use OpenAI-HK's api key to integrate with Midjourney;
  • Click here to view more API endpoints

Prerequisites

Mode Endpoints

  • Mixed mode (to be removed) https://api.openai-hk.com
  • fast mode https://api.openai-hk.com/fast
  • relax mode https://api.openai-hk.com/relax
  • Pricing differs across the 3 modes

curl Examples

Step 1: Submit an Imagine Task

API Reference — get any ID result:1320098173412546

shell
curl --request POST \
  --url https://api.openai-hk.com/fast/mj/submit/imagine \
  --header 'Authorization: Bearer hk-replace-with-your-key' \
  -H "Content-Type: application/json" \
  --data '{
  "base64Array": [],
  "instanceId": "",
  "modes": [],
  "notifyHook": "https://ww.baidu.com/notifyHook/back",
  "prompt": "black cat",
  "remix": true,
  "state": ""
}'
curl --request POST \
  --url https://api.openai-hk.com/fast/mj/submit/imagine \
  --header 'Authorization: Bearer hk-replace-with-your-key' \
  -H "Content-Type: application/json" \
  --data '{
  "base64Array": [],
  "instanceId": "",
  "modes": [],
  "notifyHook": "https://ww.baidu.com/notifyHook/back",
  "prompt": "black cat",
  "remix": true,
  "state": ""
}'

Step 2: Retrieve Task Result by Task ID

Using the task ID obtained in Step 1: 1320098173412546, get the returned result.

For a description of the return result, please refer to Return Result Description

shell
curl --request GET \
  --url https://api.openai-hk.com/fast/mj/task/1320098173412546/fetch \
  --header 'Authorization: Bearer hk-replace-with-your-key' \
  -H "Content-Type: application/json"
curl --request GET \
  --url https://api.openai-hk.com/fast/mj/task/1320098173412546/fetch \
  --header 'Authorization: Bearer hk-replace-with-your-key' \
  -H "Content-Type: application/json"