# Rate limits and best practices

## Rate limits

**Test keys** are limited to **60 requests per minute** and **200 test tracking items created per UTC day**.
Both limits answer `429` (`RATE_LIMITED` / `TEST_LIMIT_REACHED`) with a `Retry-After` header.

For **live keys** there is **no hard per-key rate limit today**. The API is shared by all partners, so fair use applies:
traffic far above what your tracking items need can be throttled or blocked without notice, and we will
contact you first when we can.

One exception counts per organization: [ELD and Hybrid](/eld-tracking#errors) creates that keep sending
truck numbers the carrier's ELD does not know answer `429 RATE_LIMITED` with a `Retry-After` header for
a while. Check the truck number with the carrier before you retry.

A per-key limit may be introduced later. When it is, an exceeded limit answers `429` with a
`Retry-After` header - build that handling in now (see below) and you will not need to change
anything.

## Prefer webhooks over polling

The driver app reports a position about every 20 seconds.
Webhooks deliver changes once a minute, and for most dashboards one read per minute per tracking is
enough.

- Use [webhooks](/webhooks) for live updates.
- If you must poll, call `GET /get-tracking` **at most once per minute per tracking**, and only for
  tracking items that are not finished.
- Use `GET /get-all-tracking-items?type=active` (one call) instead of reading every tracking to find
  the active ones.
- Ask for `requestStopsEta` and `requestDriverAddress` only when you show them - each one adds an
  external routing or geocoding lookup to the request.

## Retries

| Response | What to do |
| --- | --- |
| `429` | Wait for `Retry-After` (seconds) when present, otherwise back off, then retry |
| `500`, `502`, `503`, `504`, network error, timeout | Retry with exponential backoff and jitter, for example 1 s, 2 s, 4 s, 8 s, at most 5 attempts |
| Other `4xx` | Do not retry - fix the request (except `DRIVER_LOOKUP_FAILED` and `GEOCODING_FAILED`, which can be temporary: retry a few times with backoff) |

A `429` or `503` without a JSON body comes from the hosting platform. Back off and retry. A
`503 ELD_PROVIDER_UNAVAILABLE` carries `Retry-After` - wait that long before you retry.

`create-tracking` is **not idempotent**: two identical calls create two tracking items, and both
are billed. If a create times out, look for the tracking with
`GET /get-all-tracking-items?type=active` (match your `customId`) before retrying. Setting a unique
`customId` per load makes this easy.

Stop, delete and all reads are safe to retry (treat `TRACKING_NOT_FOUND` on a retried delete as
success). Edits are safe too, but every edit that sends `stopLocations` resets the stops' arrival
status.

## Request ids

Every response carries an `X-Request-Id` header, and every error body repeats it as `requestId`.

- Log it with every failed call.
- You may send your own `X-Request-Id` (8 to 128 characters of `A-Z a-z 0-9 . _ : -`), for example
  your trace id - it is echoed back and appears in our logs.
- Quote it when you contact [support](/support).

## Other good habits

- Send `Content-Type: application/json` on `POST` and `PATCH`.
- Reuse HTTP connections (keep-alive) and set a client timeout of about 60 seconds - `get-tracking`
  answers `504 UPSTREAM_TIMEOUT` when one internal step takes more than 25 seconds.
- Responses are never cached (`Cache-Control: no-store`). Do not put a caching proxy in front of
  them either.
- Ignore unknown fields and handle unknown `code` and `status.value` values - see
  [Base URL and versioning](/base-url-and-versioning).
- Keep keys server-side - see [Authentication](/authentication).
