Skip to main content

Get Task Detail

Query the status and results of any task created in the Market models

Overview

Use this endpoint to query the status and results of any task created through Market model APIs. This is a unified query interface that works with all models under the Market category.
This endpoint works with all Market models including Seedream, Grok Imagine, Kling, Claude, and any future models added to the Market.

API Endpoint

GET https://api.apikley.ru/api/v1/jobs/recordInfo

Query Parameters

taskId
string
required
The unique task identifier returned when you created the task.Example: task_12345678

Request Example

curl -X GET "https://api.apikley.ru/api/v1/jobs/recordInfo?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response Format

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "model": "grok-imagine/text-to-image",
    "state": "success",
    "param": "{\"model\":\"grok-imagine/text-to-image\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"input\":{\"prompt\":\"Cinematic portrait...\",\"aspect_ratio\":\"3:2\"}}",
    "resultJson": "{\"resultUrls\":[\"https://example.com/generated-content.jpg\"]}",
    "failCode": "",
    "failMsg": "",
    "completeTime": 1698765432000,
    "createTime": 1698765400000,
    "updateTime": 1698765432000
  }
}

Response Fields

code
integer
Response status code. 200 indicates success.
message
string
Response message. Typically "success" for successful queries.
data
object
The task data object containing all task information.

Task States

StateDescriptionAction
waitingTask is queued and waiting to be processedContinue polling
queuingTask is in the processing queueContinue polling
generatingTask is currently being processedContinue polling
successTask completed successfullyParse resultJson to get results
failTask failedCheck failCode and failMsg for details

Polling Best Practices

For production applications, we strongly recommend using the callBackUrl parameter when creating tasks:
  • No polling needed: Your server receives notifications automatically
  • Lower API costs: Eliminates continuous polling requests
  • Better performance: Immediate notifications when tasks complete
  • Reduced latency: No delay between completion and notification
See individual model documentation for callback implementation details.
When state is success:
  1. Parse the resultJson string to JSON
  2. Extract the resultUrls array
  3. Download generated content immediately
  4. Store content in your own storage
Important: Generated content URLs typically expire after 24 hours.

Error Handling

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "model": "grok-imagine/text-to-image",
    "state": "fail",
    "param": "{\"model\":\"grok-imagine/text-to-image\",\"input\":{\"prompt\":\"...\"}}",
    "resultJson": "",
    "failCode": "422",
    "failMsg": "Invalid prompt: prompt contains prohibited content",
    "completeTime": 1698765432000,
    "createTime": 1698765400000,
    "updateTime": 1698765432000
  }
}

Common Error Codes

CodeDescriptionSolution
401Unauthorized - Invalid or missing API keyCheck your API key
404Task not foundVerify the taskId is correct
422Validation error in original requestCheck the failMsg for details
500Internal server errorRetry after a few minutes
501Generation failedCheck failMsg for specific error details

Example: Complete Polling Flow

Node.js
async function pollTaskStatus(taskId, maxAttempts = 60, interval = 5000) {
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
    const response = await fetch(
      `https://api.apikley.ru/api/v1/jobs/recordInfo?taskId=${taskId}`,
      {
        headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
      }
    );

    const result = await response.json();
    const { state, resultJson, failMsg } = result.data;

    console.log(`Attempt ${attempt + 1}: State = ${state}`);

    if (state === 'success') {
      const results = JSON.parse(resultJson);
      console.log('Task completed!');
      console.log('Results:', results.resultUrls);
      return results;
    }

    if (state === 'fail') {
      console.error('Task failed:', failMsg);
      throw new Error(failMsg);
    }

    await new Promise(resolve => setTimeout(resolve, interval));
  }

  throw new Error('Task timed out after maximum attempts');
}

Rate limits and quotas are enforced by Apikley and may differ from upstream providers.