Error Handling

Error response format and common error codes.

Error Format

Every error includes an error message and a code:

Error response
{
  "error": "Short human-readable message",
  "code": "ERROR_CODE"
}

Validation errors include additional details:

Validation error
{
  "error": "Validation failed",
  "code": "VALIDATION_ERROR",
  "errors": [
    { "path": "/body/name", "message": "must be string" }
  ]
}

Common Error Codes

StatusCodeDescription
400VALIDATION_ERRORRequest body or parameters are invalid.
401UNAUTHORIZEDMissing or invalid API key.
402INSUFFICIENT_BALANCENot enough credits for the operation.
402PAYMENT_FAILEDCompany activation payment failed.
403FORBIDDENCompany is not active.
404NOT_FOUNDResource does not exist.
409ALREADY_PROCESSEDActivation already processed.
409CONVERSATION_CLOSEDConversation is no longer active.
500INTERNAL_ERRORUnexpected server error.

Handling 402 Errors

If you receive INSUFFICIENT_BALANCE, the company's plan does not cover the action and there are not enough prepaid credits. Purchase credits via POST /api/companies/credits/purchase and retry.

Best Practices

  • Always check the code field, not the HTTP status, for programmatic error handling.
  • Log the full error response for debugging.
  • Present the error message to users when appropriate.
  • Implement retry logic with exponential backoff for 500 errors.