Poomi

Error Handling

API error codes and how to handle them

When an API request fails, Poomi returns a JSON error response with an appropriate HTTP status code.

Error Response Format

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error description."
  }
}

Error Codes

Client Errors

HTTP StatusCodeDescription
400VALIDATION_ERRORRequest body is malformed or missing required fields
400MISSING_IMAGEEndpoint requires an image input but none was provided
400MISSING_TEXTEndpoint requires a text input but none was provided
400MISSING_INPUTEndpoint requires image and/or text input but none was provided
400INVALID_IMAGEImage format is unsupported or file size exceeds the limit
401UNAUTHORIZEDMissing or invalid Authorization header
401INVALID_KEYThe API key does not exist
402INSUFFICIENT_CREDITSAccount does not have enough credits for this request
403KEY_DISABLEDThe API key has been disabled
403KEY_REVOKEDThe API key has been revoked
403KEY_EXPIREDThe API key has expired
404NOT_FOUNDThe endpoint slug does not exist or is not published

Server Errors

HTTP StatusCodeDescription
502AI_CALL_FAILEDThe upstream AI model call failed

Handling Errors

Check the HTTP Status Code

  • 4xx errors are client errors — fix the request before retrying
  • 5xx errors are server errors — safe to retry with exponential backoff

Example: Error Handling in Code

const response = await fetch('https://www.poomi.pet/api/v1/{endpoint-slug}', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer pk_your_api_key_here',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ image: base64Data }),
});

if (!response.ok) {
  const { error } = await response.json();

  switch (error.code) {
    case 'INSUFFICIENT_CREDITS':
      // Prompt user to add credits
      break;
    case 'INVALID_KEY':
      // Check API key configuration
      break;
    case 'AI_CALL_FAILED':
      // Retry the request
      break;
    default:
      console.error(`API error: ${error.code} - ${error.message}`);
  }
}

Retry Strategy

For 5xx errors, use exponential backoff:

  1. Wait 1 second, retry
  2. Wait 2 seconds, retry
  3. Wait 4 seconds, retry
  4. Give up after 3 attempts

On this page