API Documentation
Everything you need to integrate Midjourney into your applications
Overview
The Mj API provides a simple REST interface for generating AI images using Midjourney. All requests must include an API key for authentication.
Base URL
https://mj.apify.pl/api
Authentication
All API requests require authentication using an API key. Include your API key in the request headers:
Authorization: Bearer YOUR_API_KEY
You can obtain an API key from the Dashboard.
Endpoints
/api/imagine
Generate a new image from a text prompt.
Request Body
{
"prompt": "a beautiful sunset over mountains --ar 16:9",
"webhook_url": "https://your-site.com/webhook" // optional
}
Response
{
"success": true,
"data": {
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "pending",
"prompt": "a beautiful sunset over mountains --ar 16:9"
}
}
/api/job/{jobId}
Get the status and results of a generation job.
Path Parameters
| jobId | string | The job UUID |
Response
{
"success": true,
"data": {
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "completed",
"progress": 100,
"images": [
"https://cdn.midjourney.com/image1.png",
"https://cdn.midjourney.com/image2.png"
]
}
}
/api/jobs
List all jobs for the authenticated user.
Query Parameters
| page | integer | Page number (default: 1) |
| limit | integer | Results per page (default: 20, max: 100) |
| status | string | Filter by status: pending, processing, completed, failed |
/api/upscale
Upscale a generated image to higher resolution.
Request Body
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"index": 1 // Image index (1-4)
}
/api/variation
Create a variation of a generated image.
Request Body
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"index": 1 // Image index (1-4)
}
Code Examples
cURL
curl -X POST https://mj.apify.pl/api/imagine \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "a beautiful sunset"}'
PHP
$ch = curl_init('https://mj.apify.pl/api/imagine');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'a beautiful sunset'
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
JavaScript (fetch)
const response = await fetch('https://mj.apify.pl/api/imagine', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
prompt: 'a beautiful sunset'
}),
});
const data = await response.json();
Error Handling
The API uses standard HTTP status codes. Errors return a JSON response with details:
{
"success": false,
"error": "Invalid API key",
"code": "AUTH_INVALID_KEY"
}
Common Error Codes
| Code | Status | Description |
|---|---|---|
| AUTH_MISSING | 401 | No API key provided |
| AUTH_INVALID_KEY | 401 | Invalid API key |
| RATE_LIMIT | 429 | Too many requests |
| INVALID_PROMPT | 400 | Prompt is empty or too long |
| JOB_NOT_FOUND | 404 | Job ID does not exist |
| SERVER_ERROR | 500 | Internal server error |