Skip to content

Errors and Rate Limits

All API errors return a JSON response with a consistent structure:

{
"error": "unauthorized",
"message": "Invalid or expired API token.",
"timestamp": "2025-01-15T14:30:00.000Z",
"path": "/api/PurchaseDocuments/my",
"requestId": "req_abc123def456"
}
FieldDescription
errorMachine-readable error code
messageHuman-readable description of the problem
timestampWhen the error occurred (ISO 8601)
pathThe requested API path
requestIdUnique request identifier — include this in support requests
CodeMeaningWhen it happens
200OKRequest succeeded
204No ContentResource exists but is still processing (e.g., a document being parsed)
401UnauthorizedMissing, invalid, or expired API token
403ForbiddenToken does not have the required scope for this endpoint
404Not FoundThe requested resource does not exist
429Too Many RequestsRate limit exceeded — slow down and retry

Each token scope has a per-hour request limit:

ScopeHourly limit
read1,000 requests
write2,000 requests
admin5,000 requests

The rate limit window resets on a rolling hourly basis.

Every API response includes headers that tell you your current rate limit status:

HeaderDescription
X-RateLimit-LimitMaximum number of requests allowed per hour
X-RateLimit-RemainingNumber of requests remaining in the current window
X-RateLimit-ResetUnix timestamp when the rate limit window resets
X-RateLimit-Reset-AfterSeconds until the rate limit window resets

When you receive a 429 response, an additional header is included:

HeaderDescription
Retry-AfterSeconds to wait before making another request

Here is a recommended approach for handling rate limits:

  1. Monitor the X-RateLimit-Remaining header on every response. If it drops below a threshold (e.g., 50), slow down your request rate.

  2. On a 429 response, read the Retry-After header and wait that many seconds before retrying.

  3. Implement exponential backoff for retries. If the first retry also fails, wait progressively longer.

Example in bash:

Okno terminala
response=$(curl -s -w "\n%{http_code}" \
"https://api.ogarni.ai/api/weekly-summaries/latest" \
-H "X-API-Key: $OGARNIAI_API_TOKEN")
http_code=$(echo "$response" | tail -1)
if [ "$http_code" = "429" ]; then
echo "Rate limited. Waiting before retry..."
sleep 60
fi

See Code examples for more complete implementations with rate limit handling in Python and JavaScript.