GET/v1/fetch/{task_id}

Fetch Task

Check the status of a task and retrieve the result when complete. Poll this endpoint every 5-10 seconds until the status is completed or failed.

Path Parameters

task_idrequired
string
The task ID returned by /v1/imagine or /v1/action.

Example Request

cURL
curl https://linkrapi.com/api/v1/fetch/a1b2c3d4-e5f6-7890-abcd-ef1234567890 \
  -H "Authorization: Bearer lkr_your_api_key"

Response — Completed

200 OK — Task completed
{
  "task_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "action": "imagine",
  "status": "completed",
  "progress": 100,
  "prompt": "a futuristic city at sunset, cinematic lighting --ar 16:9",
  "image_url": "https://cdn.discordapp.com/attachments/.../image.png",
  "message_id": "1234567890123456789",
  "components": [
    { "custom_id": "MJ::JOB::upsample::1::...", "label": "U1", "style": 2 },
    { "custom_id": "MJ::JOB::upsample::2::...", "label": "U2", "style": 2 },
    { "custom_id": "MJ::JOB::variation::1::...", "label": "V1", "style": 2 },
    { "custom_id": "MJ::JOB::reroll::0::...", "label": "🔄", "style": 2 }
  ],
  "error": null,
  "created_at": "2025-02-26T10:30:00"
}

Response — Processing

200 OK — Task still processing
{
  "task_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "action": "imagine",
  "status": "processing",
  "progress": 45,
  "prompt": "a futuristic city at sunset, cinematic lighting --ar 16:9",
  "image_url": null,
  "message_id": null,
  "components": null,
  "error": null,
  "created_at": "2025-02-26T10:30:00"
}

Response Fields

task_id
string
Unique task identifier.
action
string
imagine, upsample1, variation2, etc.
status
string
pending, processing, completed, failed, or timeout.
progress
number
Progress percentage (0-100).
prompt
string
The original prompt used.
image_url
string
CDN URL of the generated image. Null if not yet complete.
message_id
string
Discord message ID. Used internally for actions.
components
array
Available action buttons (upscale, variation, reroll). Null if not yet complete.
error
string
Error message if status is failed. Null otherwise.
created_at
string
ISO timestamp of when the task was created.

Task Statuses

StatusDescription
pendingTask received, waiting to be sent to Discord.
processingMidjourney is generating the image. Check progress field.
completedImage is ready. image_url and components are populated.
failedSomething went wrong. Check the error field.
timeoutGeneration took too long (>5 minutes). Try again.

Polling Helper

Here is a helper function that polls until the task is complete:

JavaScript — Polling helper
async function waitForResult(taskId, apiKey, maxWait = 300) {
  const start = Date.now();
  
  while ((Date.now() - start) / 1000 < maxWait) {
    const res = await fetch(`https://linkrapi.com/api/v1/fetch/${taskId}`, {
      headers: { "Authorization": `Bearer ${apiKey}` },
    });
    const data = await res.json();
    
    if (data.status === "completed") return data;
    if (data.status === "failed") throw new Error(data.error);
    
    console.log(`Progress: ${data.progress}%`);
    await new Promise(r => setTimeout(r, 5000));
  }
  
  throw new Error("Timeout waiting for result");
}

const result = await waitForResult("your-task-id", "lkr_your_api_key");
console.log(result.image_url);

Status Codes

200Task found. Check the status field for current state.
401Invalid or missing API key.
404Task not found or does not belong to your hold.