/APIXO Docs

Response Format

Understanding API responses and task states

Response Format

All APIXO API responses follow a consistent JSON structure.

Response Structure

{
  "code": 200,
  "message": "success",
  "data": {
    // Response payload
  }
}
FieldTypeDescription
codeintegerHTTP status code
messagestringHuman-readable status message
dataobjectResponse payload (varies by endpoint)

Task Submission Response

When you submit a generation task:

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_abc123xyz789"
  }
}
FieldTypeDescription
taskIdstringUnique identifier for tracking the task

Save the taskId to query status or debug issues later.

Task Status Response

Task States

StateDescription
pendingTask received, waiting to be processed
processingTask is being processed by the AI model
successGeneration completed successfully
failedGeneration failed (see error details)

Pending / Processing

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_abc123xyz789",
    "state": "processing",
    "createTime": 1704067200000
  }
}

Success

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_abc123xyz789",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://cdn.apixo.ai/output/abc123.jpg\"]}",
    "costTime": 12500,
    "createTime": 1704067200000,
    "completeTime": 1704067212500
  }
}
FieldTypeDescription
taskIdstringTask identifier
statestringsuccess
resultJsonstringJSON string containing result URLs
costTimeintegerProcessing time in milliseconds
createTimeintegerTask creation timestamp (Unix ms)
completeTimeintegerTask completion timestamp (Unix ms)

Parsing resultJson:

const result = JSON.parse(data.resultJson);
const urls = result.resultUrls; // Array of generated content URLs

Failed

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_abc123xyz789",
    "state": "failed",
    "failCode": "CONTENT_VIOLATION",
    "failMsg": "Content violates usage policy",
    "createTime": 1704067200000,
    "completeTime": 1704067205000
  }
}
FieldTypeDescription
failCodestringError code for programmatic handling
failMsgstringHuman-readable error message

Result URLs

The resultUrls array contains direct links to generated content:

{
  "resultUrls": [
    "https://cdn.apixo.ai/output/abc123.jpg",
    "https://cdn.apixo.ai/output/abc124.jpg"
  ]
}

Important: Result URLs expire after 24 hours. Download and store important outputs.

Polling Example

async function waitForResult(model, taskId, apiKey) {
  const maxAttempts = 60;
  const pollInterval = 3000; // 3 seconds
  
  for (let i = 0; i < maxAttempts; i++) {
    const response = await fetch(
      `https://api.apixo.ai/api/v1/statusTask/${model}?taskId=${taskId}`,
      { headers: { 'Authorization': `Bearer ${apiKey}` } }
    );
    
    const { data } = await response.json();
    
    switch (data.state) {
      case 'success':
        return JSON.parse(data.resultJson).resultUrls;
      case 'failed':
        throw new Error(`${data.failCode}: ${data.failMsg}`);
      default:
        await new Promise(r => setTimeout(r, pollInterval));
    }
  }
  
  throw new Error('Timeout waiting for result');
}

HTTP Status Codes

CodeMeaning
200Success
400Bad Request - Invalid parameters
401Unauthorized - Invalid API key
403Forbidden - Insufficient permissions
404Not Found - Task or model not found
429Too Many Requests - Rate limit exceeded
500Server Error - Try again later

See Error Codes for detailed error handling.

On this page