> ## Documentation Index
> Fetch the complete documentation index at: https://galejames.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Monitor rate limits

> Track your API usage to avoid exceeding rate limits.

Monitor rate limit headers in API responses to avoid exceeding the BookHub Publisher API limit of 150 requests per minute. Exceeding the limit returns a `429 Too Many Requests` response.

## Prerequisites

Before you begin, ensure you meet the following prerequisites:

* Familiarity with BookHub Publisher API v2.
* A valid JWT for authentication.
* Access to your codebase that integrates with the BookHub Publisher API.

## Step 1: Track rate limit headers

Every API response includes three rate limit headers: `X-RateLimit-Limit` (the ceiling), `X-RateLimit-Remaining` (requests left in the window), and `X-RateLimit-Reset` (the Unix timestamp when the window resets). For details on each header, see [Rate limit headers](https://galejames.mintlify.site/reference/reference-rate-limit-headers.md).

Add a rate limit check to your API calls:

```python theme={null}
import requests
import time

BASE_URL = "https://api.bookhub.com/api"
TOKEN = "YOUR_JWT_TOKEN"
HEADERS = {"Authorization": f"Bearer {TOKEN}"}

def check_rate_limits(response):
    limit = int(response.headers.get('X-RateLimit-Limit', 150))
    remaining = int(response.headers.get('X-RateLimit-Remaining', 0))
    reset = int(response.headers.get('X-RateLimit-Reset', 0))
    
    print(f"Rate limit: {remaining}/{limit} remaining")
    
    if remaining < 10:
        # Calculate seconds until reset from Unix timestamp
        wait_seconds = min(60, max(1, reset - int(time.time())))
        print(f"Low on rate limit — resets in {wait_seconds} seconds")
    
    return remaining
```

## Step 2: Handle 429 responses

When you exceed the rate limit, the API returns `429 Too Many Requests`. Implement retry after the reset window to retry automatically:

```python theme={null}
import requests

def make_request_with_retry(url, max_retries=3):
    for attempt in range(max_retries):
        response = requests.get(url, headers=HEADERS)
        
        if response.status_code == 429:
            reset = int(response.headers.get('X-RateLimit-Reset', 0))
            wait_seconds = min(60, max(1, reset - int(time.time())))
            print(f"Rate limit exceeded. Waiting {wait_seconds} seconds...")
            time.sleep(wait_seconds)
            continue
        
        response.raise_for_status()
        check_rate_limits(response)
        return response
    
    raise Exception(f"Failed after {max_retries} retries")
```

## Step 3: Test your implementation

Make a request and verify the rate limit headers are present in the response:

```bash theme={null}
curl -X GET "https://api.bookhub.com/api/v2/books" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -v
```

Confirm the response includes `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `X-RateLimit-Reset` headers. The `X-RateLimit-Reset` value is a Unix timestamp — convert it to a human‐readable time if needed:

```python theme={null}
import datetime
  reset = int(response.headers.get('X-RateLimit-Reset', 0))
  reset_time = datetime.datetime.fromtimestamp(reset)
  print(f"Rate limit resets at: {reset_time}")
```

## Response

A `429 Too Many Requests` response indicates the rate limit has been exceeded:

```json theme={null}
{
  "status": "error",
  "message": "Rate limit exceeded. Retry after the window resets (see X-RateLimit-Reset header)."
}
```

The response also includes the rate limit headers so you can calculate when to retry.

## Next steps

Explore related topics:

### Reference

* [API endpoints](https://galejames.mintlify.site/reference/reference-api-endpoints.md) — Explore all available API endpoints and their parameters for BookHub Publisher API v2.
* [Rate limit headers](https://galejames.mintlify.site/reference/reference-rate-limit-headers.md) — Details on the rate limit headers included in API responses.
* [Error codes](https://galejames.mintlify.site/reference/reference-api-endpoints.md#error-codes) — Complete list of error codes including `429`.

### How to guides

* [Handle pagination](https://galejames.mintlify.site/how-to-guides/how-to-guides-handle-pagination.md) — Manage large result sets efficiently to minimize API calls.
* [Cache book details for faster performance](https://galejames.mintlify.site/how-to-guides/how-to-guides-cache-book-details.md) — Reduce API calls by caching responses.

***


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.