cURL
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",
"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",
"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',
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',
'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 \"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 \"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 \"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"
}ChatGPT
GPT-Image
Generate images based on text prompts and image resources
POST
/
gpt
/
v1
/
generations
cURL
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",
"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",
"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',
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',
'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 \"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 \"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 \"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
application/json
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", 'draw a xxx', Language is not restricted; OpenAI itself supports multilingual models with excellent Chinese support.
Example:
"draw a boy play with a girl"
Supported models: gpt-image-2
Available options:
gpt-image-2 Example:
"gpt-image-2"
Reference image array
Example:
[
"https://example.com/image.png",
"https://example.com/image.png"
]
Support model: gpt-image-2; Available options: 1:1, 3:4, 4:3, 16:9, 9:16
Available options:
1:1, 3:4, 4:3, 16:9, 9:16 Example:
"1:1"
Callback notification URL
Example:
"https://api.example.com/webhook"
⌘I