Errors

The Phosra API uses standard HTTP status codes and returns structured error responses.

Error Response Format

All errors follow this structure:

json
{
  "error": "error_code",
  "message": "A human-readable description of what went wrong"
}

HTTP Status Codes

Success Codes

CodeMeaningUsed For
200OKSuccessful read or update
201CreatedResource created successfully
202AcceptedAsync job started (enforcement, sync)
204No ContentSuccessful delete

Client Error Codes

CodeMeaningCommon Causes
400Bad RequestMissing required fields, invalid JSON, malformed parameters
401UnauthorizedMissing, expired, or invalid token/API key
403ForbiddenValid auth but insufficient permissions or scope
404Not FoundResource does not exist or is not accessible to your account
409ConflictDuplicate resource (e.g., email already registered)
422Unprocessable EntityValid JSON but semantically invalid (e.g., birth date in the future)
429Too Many RequestsRate limit exceeded

Server Error Codes

CodeMeaningAction
500Internal Server ErrorRetry with exponential backoff. If persistent, contact support
502Bad GatewayUpstream platform unreachable (OAuth exchange, verification)

Common Error Examples

Missing Required Field

json
{
  "error": "validation_error",
  "message": "child_name is required"
}

Authentication Failure

json
{
  "error": "unauthorized",
  "message": "Invalid or expired access token"
}

Resource Not Found

json
{
  "error": "not_found",
  "message": "Child 550e8400-e29b-41d4-a716-446655440000 not found"
}

Rate Limit Exceeded

json
{
  "error": "rate_limit_exceeded",
  "message": "Rate limit exceeded. Retry after 30 seconds"
}

Rate Limiting

API requests are rate limited per API key or access token. Rate limit information is included in every response via headers:

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per window
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetUnix timestamp when the window resets

Default Limits

PlanRate Limit
Free100 requests/minute
Pro1,000 requests/minute
EnterpriseCustom

Handling Rate Limits

When you receive a 429 response, read the X-RateLimit-Reset header and wait until that time before retrying:

bash
# Check rate limit headers
curl -i https://phosra-api.fly.dev/api/v1/families \
  -H "Authorization: Bearer $PHOSRA_API_KEY"
 
# Response headers include:
# X-RateLimit-Limit: 1000
# X-RateLimit-Remaining: 998
# X-RateLimit-Reset: 1708700000

Retry Guidance

ScenarioStrategy
429 Rate LimitedWait until X-RateLimit-Reset, then retry
500 Server ErrorExponential backoff: 1s, 2s, 4s, 8s (max 3 retries)
502 Bad GatewayRetry once after 5 seconds; if persistent, check status page
401 UnauthorizedRefresh your access token, then retry once

Enforcement jobs (202 responses) are asynchronous. Poll GET /enforcement/jobs/{jobID} to check completion status rather than retrying the trigger.