Skip to content

Error Handling API

All Cryptid API errors follow a consistent format with standard HTTP status codes, machine-readable error codes, and optional retry guidance. This enables clients to implement robust error handling and recovery strategies.

{
"error": "ERROR_CODE",
"message": "Human readable error description",
"code": 4001,
"retry_after": 300
}

Fields:

  • error: Machine-readable error code (uppercase snake_case)

    • Used for programmatic error handling
  • message: Human-readable error description

    • Suitable for logging or development debugging
    • Should NOT be displayed directly to end users
  • code: Numeric error code (4 digits)

    • First digit matches HTTP status category (4xxx for client errors, 5xxx for server errors)
    • Unique identifier for specific error types
  • retry_after (optional): Seconds to wait before retrying

    • Only present for retryable errors (rate limits, temporary failures)
    • Clients SHOULD respect this value
StatusDescriptionRetryable?
200OK - Request successfulN/A
202Accepted - Message queuedN/A
400Bad Request - Invalid formatNo
401Unauthorized - Invalid tokenNo*
404Not Found - Resource missingNo
413Payload Too Large - Message too bigNo
429Too Many Requests - Rate limitedYes
500Internal Server ErrorYes
502Bad Gateway - Federation failedYes
503Service UnavailableYes
CodeErrorHTTP StatusDescription
4001INVALID_SIGNATURE400Ed25519 signature verification failed
4002DEVICE_NOT_ANNOUNCED401Device not registered for delivery
4003MESSAGE_TOO_LARGE413Message exceeds server size limit
4004RATE_LIMIT_EXCEEDED429Too many requests
4005INVALID_ADDRESS400Malformed device address
4006FEDERATION_FAILED502Cross-server delivery failed
4007SERVER_UNREACHABLE502/404Target server unavailable or not found
4008INVALID_REFRESH_TOKEN401Refresh token is invalid or expired
4009INVALID_ADMIN401Device is not configured as admin
4010CHALLENGE_EXPIRED410Admin auth challenge has expired
4011INSUFFICIENT_PERMISSIONS403Admin lacks required permission
4012INVALID_CONFIG400Configuration value invalid
4013DEVICE_NOT_FOUND404Device not found on server
5003FEDERATION_DISABLED503Recipient’s server doesn’t support federation

Client errors indicate problems with the request that cannot be resolved by retrying without modification.

Examples:

  • 4001 (INVALID_SIGNATURE): Re-sign the request with the correct device key
  • 4002 (DEVICE_NOT_ANNOUNCED): Re-announce device before retrying
  • 4003 (MESSAGE_TOO_LARGE): Reduce message size or split into chunks
  • 4005 (INVALID_ADDRESS): Fix address format
  • 4008 (INVALID_REFRESH_TOKEN): Obtain new token via /v1/announce

Server errors indicate temporary issues that may be resolved by retrying with exponential backoff.

Examples:

  • 4006 (FEDERATION_FAILED): Retry with backoff, store locally if persistent
  • 4007 (SERVER_UNREACHABLE): Retry with backoff, notify user of delay
  • 5003 (FEDERATION_DISABLED): Cannot be resolved by retry - inform user

All responses (success or failure) include rate limiting information:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1759000000
Retry-After: 60

Headers:

  • X-RateLimit-Limit: Maximum requests allowed in the current window

  • X-RateLimit-Remaining: Requests remaining in the current window

  • X-RateLimit-Reset: Unix timestamp when the rate limit resets

  • Retry-After: Time in seconds after which requests can be retried

  1. Exponential Backoff: For retryable errors (5xx, 429), use exponential backoff

  2. Respect Retry-After: Always respect the retry_after field

  3. User-Facing Error Messages: Don’t show API error messages directly to users. Show them useful information

  4. Logging and Monitoring: Log all errors with context for debugging

  5. Graceful Degradation: Handle errors gracefully without blocking user experience.

Error codes are stable across API versions. Clients can rely on specific codes for error handling logic.

Future versions may add new error codes. Clients should handle unknown codes gracefully.

Error responses never include stack traces or internal server details. This prevents information leakage while maintaining debuggability through logs on the server side.