MidJourney API Notes
The MidJourney API is divided into two categories: Direct Generation and Secondary Editing. Direct Generation only requires providing necessary parameters such as prompts to generate images directly. Secondary Editing requires providing the previous task ID and image number to execute image generation. edit is a Secondary Editing category
Authentication
authorization string required
All APIs require authentication via Bearer Token.
Get API Key:
Visit API Key Management Page to get your API Key
Usage:
Add to request header:
Authorization: Bearer YOUR_API_KEY
Parameters
model string required
Model ID to use for the request
Options: midjourney_edit
jobId string required
Task ID
imageNo integer required
Image number, must be 0, 1, 2 or 3
Options: 0, 1, 2, 3
canvas object required
Canvas object
width
integerrequiredCanvas width in pixels
height
integerrequiredCanvas height in pixels
imgPos object required
Image position and size relative to canvas
width
integerrequiredImage width in pixels
height
integerrequiredImage height in pixels
x
integerrequiredHorizontal offset from canvas top-left corner
y
integerrequiredVertical offset from canvas top-left corner
remixPrompt string required
Prompt text, length must be between 1-8192 characters
mask object
Original image repaint area
callback string
Callback URL for task result notification, must be valid HTTP/HTTPS URL
Polling
Since result generation takes time, you need to poll the task status after creating the task.
The initial response only returns information such as the task ID and initial status. The final result must be obtained by polling the task status endpoint using the task ID.
See the examples on the right for polling requests and responses.
Response Format
error object
Error information. Only present when status is failed.
code
integerError code.
error_message
stringDetailed error message.
output array
Generation results. Only present when status is completed.
content
arrayList of generated content.
type
stringResource type, e.g.,
video,image.url
stringGenerated content URL.
usage object
Usage statistics. Only present when status is completed.
cost
stringTotal cost in USD.
discount
numberDiscount amount.
metadata object
Metadata information
Error Codes
| Error Code | Description |
|---|---|
| 004007001 | Task ID missing |
| 004007002 | Image number missing |
| 004007003 | Invalid image number |
| 004007004 | Prompt missing |
| 004007005 | Invalid prompt length |
| 004007006 | Canvas parameters missing |
| 004007007 | Image position parameters missing |
| 004007008 | Invalid callback URL |
| 004007098 | Generation failed |
| 004007099 | Service unavailable |