Error Handling

The Dokai API uses conventional HTTP status codes and returns structured JSON error responses with machine-readable codes and human-readable messages.

Error response format

All errors follow a consistent structure. The suggestions array provides actionable steps to resolve the issue.

Error response
{
  "error": {
    "code": "invalid_file_type",
    "message": "The uploaded file is not a supported image format.",
    "type": "validation_error",
    "suggestions": [
      "Upload a JPEG, PNG, or WebP image",
      "Ensure the file is not corrupted",
      "Check that the Content-Type header matches the file"
    ]
  }
}

Error codes

CodeHTTPDescription
invalid_api_key401API key is missing, malformed, or revoked
key_expired401API key has been rotated or expired
unauthorized401Authentication failed
forbidden403Key does not have permission for this action
not_found404Requested resource does not exist
result_expired410Parse result has been purged after retention period
validation_error422Request parameters failed validation
invalid_file_type422File is not a supported image format (JPEG, PNG, WebP)
file_too_large422File exceeds the 10 MB size limit
invalid_document_type422Unrecognized document_type value
invalid_document_brand422Unrecognized document_brand value
webhook_invalid_url422webhook_url must use HTTPS or is malformed
webhook_domain_not_allowed422webhook_url domain is not in your allowed webhook domains
quota_exceeded429Monthly parse quota has been reached
rate_limited429Too many requests — slow down
processing_failed500Document could not be processed
ocr_failed500OCR engine failed to extract text
internal_error500Unexpected server error

Rate limiting

API responses include rate limit headers so you can track your current usage window.

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per window
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetUnix timestamp when the window resets
Rate limit headers
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 42
X-RateLimit-Reset: 1741276800

Quota headers

Parse responses also include quota headers so you can monitor monthly usage without calling the usage endpoint.

HeaderDescription
X-Quota-LimitMonthly parse quota
X-Quota-RemainingParses remaining this billing period
X-Quota-ResetUnix timestamp when the billing period resets

Handling errors in code

# cURL outputs the response body directly.
# Check the HTTP status code with -w:
curl -s -w "\n%{http_code}" -X POST https://api.dokai.dev/v1/parse \
  -H "Authorization: Bearer dk_live_your_api_key" \
  -F "file=@document.jpg"

# A non-200 status indicates an error.
# The response body contains the error JSON.

Validation endpoint

POST/v1/validate

Validate extracted data without submitting a document. Supports format validation for specific field types.

Supported types

TypeDescription
ic_numberMalaysian IC number format and checksum validation
mrzPassport MRZ (Machine Readable Zone) checksum validation
cURL
curl -X POST https://api.dokai.dev/v1/validate \
  -H "Authorization: Bearer dk_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "ic_number",
    "value": "880503-14-5234"
  }'