Skip to main content

Error Handling

Every error response includes a machine-readable error_code you can switch on, and an error_type category for generic handling. See the full error code catalog for all codes and their meanings.

Error Response Shape

{
"success": false,
"error": "Human-readable message",
"error_code": "specific_error_code",
"error_type": "invalid_request_error",
"request_id": "req_abc123"
}

Handling Errors

Switch on error_code for specific cases. Fall back to error_type for generic behavior.

resp = requests.post(f"{BASE_URL}/api/reports", headers=headers, json=body)

if resp.status_code >= 400:
err = resp.json()
code = err.get("error_code", "")

if code == "occupants_missing":
print("Add occupants before generating a report.")
elif code == "unsupported_file_type":
print("Please upload a JPEG, PNG, or PDF.")
elif err.get("error_type") == "api_error":
# Server error — retry with backoff
time.sleep(5)
else:
print(f"Error: {err['error']}")

Retry Strategy

  • Retry api_error types (5xx) and 429 responses with exponential backoff
  • Don't retry invalid_request_error types (4xx) — fix the request first
  • Log the request_id — include it when contacting support

Further Reading