curl --request POST \
--url https://api.midjourney-api.com/gpt/v1/generations \
--header 'API-KEY: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "draw a boy play with a girl",
"model": "gpt-image-2",
"referImages": [
"https://example.com/image.png",
"https://example.com/image.png"
],
"aspect_ratio": "1:1",
"size": "1K",
"output_size": "1920x1080",
"hookUrl": "https://api.example.com/webhook"
}
'import requests
url = "https://api.midjourney-api.com/gpt/v1/generations"
payload = {
"prompt": "draw a boy play with a girl",
"model": "gpt-image-2",
"referImages": ["https://example.com/image.png", "https://example.com/image.png"],
"aspect_ratio": "1:1",
"size": "1K",
"output_size": "1920x1080",
"hookUrl": "https://api.example.com/webhook"
}
headers = {
"API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'draw a boy play with a girl',
model: 'gpt-image-2',
referImages: ['https://example.com/image.png', 'https://example.com/image.png'],
aspect_ratio: '1:1',
size: '1K',
output_size: '1920x1080',
hookUrl: 'https://api.example.com/webhook'
})
};
fetch('https://api.midjourney-api.com/gpt/v1/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.midjourney-api.com/gpt/v1/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'draw a boy play with a girl',
'model' => 'gpt-image-2',
'referImages' => [
'https://example.com/image.png',
'https://example.com/image.png'
],
'aspect_ratio' => '1:1',
'size' => '1K',
'output_size' => '1920x1080',
'hookUrl' => 'https://api.example.com/webhook'
]),
CURLOPT_HTTPHEADER => [
"API-KEY: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.midjourney-api.com/gpt/v1/generations"
payload := strings.NewReader("{\n \"prompt\": \"draw a boy play with a girl\",\n \"model\": \"gpt-image-2\",\n \"referImages\": [\n \"https://example.com/image.png\",\n \"https://example.com/image.png\"\n ],\n \"aspect_ratio\": \"1:1\",\n \"size\": \"1K\",\n \"output_size\": \"1920x1080\",\n \"hookUrl\": \"https://api.example.com/webhook\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.midjourney-api.com/gpt/v1/generations")
.header("API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"draw a boy play with a girl\",\n \"model\": \"gpt-image-2\",\n \"referImages\": [\n \"https://example.com/image.png\",\n \"https://example.com/image.png\"\n ],\n \"aspect_ratio\": \"1:1\",\n \"size\": \"1K\",\n \"output_size\": \"1920x1080\",\n \"hookUrl\": \"https://api.example.com/webhook\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.midjourney-api.com/gpt/v1/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"draw a boy play with a girl\",\n \"model\": \"gpt-image-2\",\n \"referImages\": [\n \"https://example.com/image.png\",\n \"https://example.com/image.png\"\n ],\n \"aspect_ratio\": \"1:1\",\n \"size\": \"1K\",\n \"output_size\": \"1920x1080\",\n \"hookUrl\": \"https://api.example.com/webhook\"\n}"
response = http.request(request)
puts response.read_body{
"status": 0,
"data": {
"taskId": "MtAd7mCuc4YqK_a1iAQSW"
},
"message": "success"
}{
"error": 1001,
"message": "quota not enough"
}generations
Generate images based on text prompts and image resources
curl --request POST \
--url https://api.midjourney-api.com/gpt/v1/generations \
--header 'API-KEY: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "draw a boy play with a girl",
"model": "gpt-image-2",
"referImages": [
"https://example.com/image.png",
"https://example.com/image.png"
],
"aspect_ratio": "1:1",
"size": "1K",
"output_size": "1920x1080",
"hookUrl": "https://api.example.com/webhook"
}
'import requests
url = "https://api.midjourney-api.com/gpt/v1/generations"
payload = {
"prompt": "draw a boy play with a girl",
"model": "gpt-image-2",
"referImages": ["https://example.com/image.png", "https://example.com/image.png"],
"aspect_ratio": "1:1",
"size": "1K",
"output_size": "1920x1080",
"hookUrl": "https://api.example.com/webhook"
}
headers = {
"API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'draw a boy play with a girl',
model: 'gpt-image-2',
referImages: ['https://example.com/image.png', 'https://example.com/image.png'],
aspect_ratio: '1:1',
size: '1K',
output_size: '1920x1080',
hookUrl: 'https://api.example.com/webhook'
})
};
fetch('https://api.midjourney-api.com/gpt/v1/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.midjourney-api.com/gpt/v1/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'draw a boy play with a girl',
'model' => 'gpt-image-2',
'referImages' => [
'https://example.com/image.png',
'https://example.com/image.png'
],
'aspect_ratio' => '1:1',
'size' => '1K',
'output_size' => '1920x1080',
'hookUrl' => 'https://api.example.com/webhook'
]),
CURLOPT_HTTPHEADER => [
"API-KEY: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.midjourney-api.com/gpt/v1/generations"
payload := strings.NewReader("{\n \"prompt\": \"draw a boy play with a girl\",\n \"model\": \"gpt-image-2\",\n \"referImages\": [\n \"https://example.com/image.png\",\n \"https://example.com/image.png\"\n ],\n \"aspect_ratio\": \"1:1\",\n \"size\": \"1K\",\n \"output_size\": \"1920x1080\",\n \"hookUrl\": \"https://api.example.com/webhook\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.midjourney-api.com/gpt/v1/generations")
.header("API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"draw a boy play with a girl\",\n \"model\": \"gpt-image-2\",\n \"referImages\": [\n \"https://example.com/image.png\",\n \"https://example.com/image.png\"\n ],\n \"aspect_ratio\": \"1:1\",\n \"size\": \"1K\",\n \"output_size\": \"1920x1080\",\n \"hookUrl\": \"https://api.example.com/webhook\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.midjourney-api.com/gpt/v1/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"draw a boy play with a girl\",\n \"model\": \"gpt-image-2\",\n \"referImages\": [\n \"https://example.com/image.png\",\n \"https://example.com/image.png\"\n ],\n \"aspect_ratio\": \"1:1\",\n \"size\": \"1K\",\n \"output_size\": \"1920x1080\",\n \"hookUrl\": \"https://api.example.com/webhook\"\n}"
response = http.request(request)
puts response.read_body{
"status": 0,
"data": {
"taskId": "MtAd7mCuc4YqK_a1iAQSW"
},
"message": "success"
}{
"error": 1001,
"message": "quota not enough"
}Authorizations
You can obtain your API key from the Midjourney-api Dashboard.
Body
Text prompt for image generation.
Since this is a reverse-engineered model, it's recommended to include keywords in your prompt such as:
- "draw a xxx"
- "generate a xxx"
Language is not restricted; OpenAI itself supports multilingual models with excellent Chinese support.
"draw a boy play with a girl"
Supported models: gpt-image-2
gpt-image-2 "gpt-image-2"
Reference image array
[
"https://example.com/image.png",
"https://example.com/image.png"
]
Support model: gpt-image-2
Available options:
- 1:1
- 1:2
- 2:1
- 3:4
- 4:3
- 16:9
- 9:16
1:1, 1:2, 2:1, 3:4, 4:3, 16:9, 9:16 "1:1"
Support model: gpt-image-2
Available options: 1K, 4K
Default: 1K
4K is better at keeping other areas unchanged in image editing scenarios
1K, 4K "1K"
Support model: gpt-image-2. Custom output width and height in WIDTHxHEIGHT format, e.g. "1920x1080". Only takes effect when size is "4K"; ignored for 1K.
A parsed value overrides aspect_ratio. Unparseable values are ignored and the request keeps aspect_ratio sizing.
The server auto-corrects a parsed value:
- both sides snapped to multiples of 16
- longest edge ≤ 3840
- aspect ratio clamped to 1:3–3:1
- total pixels clamped to 655360–8294400
Examples:
- "100x100" → 816x816
- "1920x1080" → 1920x1088
- "5000x100" → 3840x1280
- "10000x10000" → 2880x2880
"1920x1080"
Callback notification URL
"https://api.example.com/webhook"