Rate limits
Each product a plan includes comes with a sustained rate, in requests per second, and aburst. Nothing is used up, and nothing resets at the turn of a month. The rates each plan sells are in the table on products and plans; the one your key has is in theRateLimit-Limit header of every answer.
A token bucket, per key and per product
- Every key has one bucket for each product its plan includes. They are independent: saturating routing does not slow geocoding.
- A bucket holds at most burst tokens, and starts full.
- It refills continuously at the sustained rate — not in a lump once a second, and not once a month.
- Each request takes one token, whatever it is. A 500-point travel-time matrix costs the same token as a geocode.
- A request that finds less than one token is refused with
429, and nothing is taken.
Worked through for a key at 10 requests a second with a burst of 12: twelve requests sent at once all pass. The thirteenth is refused with Retry-After: 1. A tenth of a second later one token is back and one more request passes; after a full second, ten more do. Sent evenly at ten a second, it is never refused at all.
This changes what a 429 means
It means you are going faster than you bought, right now. It does not mean you have exhausted an allowance, because there is no allowance to exhaust. The right response is to wait the seconds in Retry-Afterand ask again — not to stop until next month.
HTTP/1.1 429 Too Many Requests
content-type: application/json
ratelimit-limit: 2
ratelimit-remaining: 0
ratelimit-reset: 1
retry-after: 1
{
"error": "address is limited to 2 requests a second, burst 2; try again in 1 s. There is no monthly quota."
}A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.
Retry-After is whole seconds until one token is back, never less than one. The body says the same thing in words, and says which product's bucket is empty.
Watching headroom
Every admitted request to a keyed route carries three headers, and their X- aliases for clients that read the older spelling:
| Header | Is |
|---|---|
RateLimit-Limit | The sustained rate this product is sold at, rounded to a whole number. |
RateLimit-Remaining | Whole tokens left in the bucket after this request. |
RateLimit-Reset | Seconds until the bucket is full again at the sustained rate. There is no window to reset; this is how long until the burst is fully available. |
The names follow the IETF draft for RateLimit header fields. They are sent on every answer a keyed route gives — including a 400 for a bad parameter, since that request was admitted and took its token — and on a429, where remaining is 0. They are not sent by the keyless routes (/v1/health, /v1/migrate), nor on a 401, a 403 for a plan without the product, or a 503, which are refused before any bucket is looked at. A 403for a matrix larger than the plan allows does carry them: that request was admitted, and refused by the route.
Behind a fleet of pods, a key's rate is shared across them, and the headers always quote the rate you bought — never one pod's share of it.
Refusals that are not about rate
401: no key, or one the service does not know. Not retryable until the key is fixed.403: the plan does not include the route's product, or a matrix is larger than the plan allows. The body names the plan that would answer.503: the serving pod has not yet loaded the current list of keys, or its copy is more than fifteen minutes old. It refuses rather than answer with a revoked key still valid. Retry after a few seconds.
Every refusal body is JSON with one field, error, in plain words. Every status: errors.
Retrying well
Both clients raise one class for a 429 — RateLimited — carrying the parsed headers, and each has an opt-in helper that waits out Retry-After and tries again, a bounded number of times. It is opt-in because only the caller knows what can afford to wait: an interactive request should usually fail fast and say so; a backfill should wait.
from oslew import Client, RateLimited, retry_on_rate_limit
client = Client(base_url="https://api.oslew.com")
# Waits Retry-After (1 s if absent), at most 60 s at a time, three attempts.
answer = retry_on_rate_limit(client.geocode, "Museo Soumaya", attempts=5)
# Or handle it yourself.
try:
answer = client.geocode("Museo Soumaya")
except RateLimited as e:
print(e.rate_limit.retry_after, e.message)import { Client, RateLimited, retryOnRateLimit } from "@oslew/client";
const client = new Client({ baseUrl: "https://api.oslew.com" });
// Waits Retry-After (1 s if absent), at most 60 s at a time, three attempts.
const answer = await retryOnRateLimit(() => client.geocode("Museo Soumaya"), { attempts: 5 });
// Or handle it yourself.
try {
await client.geocode("Museo Soumaya");
} catch (e) {
if (e instanceof RateLimited) console.log(e.rateLimit.retryAfter, e.message);
else throw e;
}After any answer, client.rate_limit (client.rateLimit in TypeScript) holds the lastRateLimit-* values, so a loop can slow down before it is refused rather than after.
Pacing a backfill yourself
If you have a file of addresses, send it as a batch job and let the service pace it. If you are looping in your own code, pace to the sustained rate rather than sending as fast as you can and catching 429s — the burst is for spikes, and a loop that lives in the burst spends it on itself:
import time
from oslew import Client
client = Client(base_url="https://api.oslew.com")
rate = 20 # the RateLimit-Limit your key reports
for q in addresses:
started = time.monotonic()
answer = client.geocode(q, limit=1)
...
time.sleep(max(0.0, 1 / rate - (time.monotonic() - started)))Batch shares the same budget
A batch job takes one token per row from the submitting key's own address bucket. There is no separate batch price and no separate batch rate: bulk and interactive requests draw on one honest budget, and a job tells you how long it will take at that rate in remaining_s. Two million rows at twenty a second is a day and a night, and the job says so rather than pretending otherwise.