# On Rate-Limiting (/api/using-the-api/on-rate-limiting)

All the endpoints in the Spoke Public API are rate-limited, which means we
will reject requests that come in too fast.

To know if your request was rate-limited, check if the response has the HTTP
status code 429.

Each endpoint has a different rate limit, and Spoke can change this rate
limit at any moment.

The rate limits are as follows:

- **Rate Limits for Write Endpoints**: All write endpoints have a limit of 5
  requests per second, which includes Creation (POST), Update (PATCH), and
  Deletion (DELETE) operations for all models.
  - An exception to this rule is the Driver Creation endpoint, which is limited to
    1 request per second. Thus, we recommend using the Batch Import Drivers
    when adding multiple drivers.
- **Rate Limits for Read Endpoints**: All read endpoints, including list
  endpoints, are limited to 10 requests per second.
- **Rate Limits for Batch Import**:
  - The _Batch Import_ endpoints for Stops and Unassigned Stops models are
    limited to 100 requests per _10 minutes_ (with a maximum rate of 30 per _minute_).
    However, these endpoints can handle the import of up to 1,000 stops per minute.
    The Creation, Update, and Deletion endpoints for these models still maintain
    a rate limit of 5 requests per second.
  - The _Batch Import_ endpoint for Drivers is limited to 2 requests per
    _minute_. This allows for the import of up to 100 drivers per minute.
- **Rate Limits for Optimization Endpoints**: The Plan _optimization_ and
  _re-optimization_ endpoints are limited to 100 requests per _10 minutes_
  (with a maximum rate of 30 per _minute_), due to the long running nature of these operations.

Spoke API will occasionally support bursts of requests, but they cannot be
sustained and will be rejected if they last too long.

If Spoke rejects your request because it exceeds the rate limit, you must
wait before retrying it. We suggest you use an [exponential
backoff](https://en.wikipedia.org/wiki/Exponential_backoff) approach for this.

We also recommend, besides the exponential backoff algorithm, that you add a
random delay to each attempt to prevent a [thundering herd
problem](https://en.wikipedia.org/wiki/Thundering_herd_problem).

If the client keeps retrying rate-limited requests while being rejected with a
429 at a high rate, Spoke will keep rejecting the requests until you turn
down the request rate.

Spoke will also limit requests if it keeps receiving them at a high frequency
at or close to the requests limit for an extended period, so while we support
an occasional burst of requests, if this is sustained for a long period, we
will rate-limit the client making them.

While we feel these rate-limits will work for the vast majority of use cases we
understand every team is different. So please reach out to us and describe your
use case if these limits are not enough for you, and we will evaluate
increasing them for your team.