Skip to content

Guide

Exchange Rate API Rate Limits: 429 and Retry-After

Handle exchange rate API rate limits: read the RateLimit headers, tell rate_limited from quota_exceeded, honor Retry-After and back off on 5xx errors.

Updated

Every exchange rate API limits how fast and how much you can call it, and a well-behaved client treats those limits as part of the protocol, not as a failure. This guide explains the two limits on an FXbase key, the standard headers that announce them, and retry code in JavaScript and Python that respects them. The reference for all of it is the rate limits section of the API docs.

Two limits: per minute and per month

A per-minute limit smooths out bursts, and a monthly quota caps total use. Both are set by your plan:

PlanPriceRequests a monthPer minuteRatesHistory
DeveloperFree5005Daily rates, previous dayNone
Startup$12 a month30,00060Hourly rate snapshots1 year of history
Growth$49 a month250,000300Live rates, updated every 60 s5 years of history
EnterpriseContact salesunlimitedunlimitedLive rates, updated every 60 s5 years of history

Only successful answers count toward the monthly quota: anything under 400, which includes a 304 Not Modified. Errors, including a 429, do not use up your quota. The quota resets at the start of each UTC month.

Read the RateLimit headers

Each successful answer tells you where you stand, with the IETF RateLimit-Policy and RateLimit headers. The policy names the limit, its size q and its window w in seconds. The state gives the requests remaining, r, and the seconds until the window resets, t:

See the limit headers
curl -si "https://api.fxbase.dev/v1/latest?symbols=EUR" \
  -H "Authorization: Bearer $FXBASE_API_KEY" | grep -i '^ratelimit'

# On the Startup plan, after the first request of a minute:
# ratelimit-policy: "rates";q=60;w=60
# ratelimit: "rates";r=59;t=60

A client that reads r can pace itself and never see a 429 at all. The header can carry more than one comma-separated item, so parse it by name:

Read RateLimit
// '"rates";r=59;t=60' -> { rates: { remaining: 59, resetSeconds: 60 } }
export function parseRateLimit(header) {
  const out = {};
  for (const item of (header ?? "").split(",")) {
    const name = /"([^"]+)"/.exec(item)?.[1];
    const r = /;r=(\d+)/.exec(item)?.[1];
    const t = /;t=(\d+)/.exec(item)?.[1];
    if (name && r && t) out[name] = { remaining: Number(r), resetSeconds: Number(t) };
  }
  return out;
}

If you run several workers with one key, they share the limit. Either give each a fair share of q, or send all calls through one queue that reads the headers.

What a 429 looks like

Over a limit, the API answers 429 Too Many Requests with an RFC 9457 problem body and a Retry-After header in seconds. The code field says which limit you hit:

A 429, per-minute limit
HTTP/2 429
ratelimit-policy: "rates";q=60;w=60
ratelimit: "rates";r=0;t=12
retry-after: 12
content-type: application/problem+json

{
  "type": "about:blank",
  "title": "Too Many Requests",
  "status": 429,
  "code": "rate_limited",
  "detail": "Rate limit \"rates\" exceeded; retry after 12s.",
  "requestId": "3f2b8c1e-6d4a-4f0b-9a7e-2c5d1e8f9a01"
}
  • rate_limited: the per-minute window is full. Retry-After is the wait until it frees up, usually seconds.
  • quota_exceeded: this month's quota is spent. Retry-After is the time until the next UTC month starts, which can be days. The headers then describe the "quota" policy instead, with r=0.

Always branch on code, not on the status alone. Sleeping for days inside a request handler is never what you want: treat quota_exceeded as an alert for a person, and serve cached rates until it clears.

Retry with Retry-After and backoff

A small wrapper covers every case:

  • rate_limited: wait exactly Retry-After seconds, then retry.
  • quota_exceeded: do not retry; report it.
  • 500 or 503: retry with exponential backoff and random jitter, capped, so many clients do not retry in lockstep.
  • Any other 4xx: fix the request. Retrying a 400, 401 or 403 unchanged gives the same answer.
fetchWithRetry (Node 18 or later)
const API = "https://api.fxbase.dev";
const KEY = process.env.FXBASE_API_KEY;
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

export async function fetchWithRetry(path, params, { attempts = 4 } = {}) {
  const url = `${API}${path}?${new URLSearchParams(params)}`;
  for (let attempt = 1; ; attempt++) {
    const res = await fetch(url, { headers: { Authorization: `Bearer ${KEY}` } });
    if (res.ok) return res.json();

    const problem = await res.json().catch(() => ({}));
    const retryAfter = Number(res.headers.get("Retry-After"));
    if (attempt >= attempts) throw new Error(`${res.status} ${problem.code ?? ""}`);

    if (res.status === 429 && problem.code === "rate_limited") {
      await sleep(retryAfter * 1000); // the window frees up then
    } else if (res.status === 429 && problem.code === "quota_exceeded") {
      throw new Error(`Monthly quota spent; it resets in ${retryAfter}s`); // do not retry
    } else if (res.status >= 500) {
      await sleep(Math.min(30_000, 2 ** attempt * 500 * (0.5 + Math.random()))); // backoff with jitter
    } else {
      throw new Error(`${problem.code}: ${problem.detail}`); // 4xx: fix the request
    }
  }
}

const latest = await fetchWithRetry("/v1/latest", { base: "EUR", symbols: "USD,GBP" });

The same logic in Python, with requests:

The same in Python
import os
import random
import time

import requests

API = "https://api.fxbase.dev"
HEADERS = {"Authorization": f"Bearer {os.environ['FXBASE_API_KEY']}"}


def get_with_retry(path, params, attempts=4):
    for attempt in range(1, attempts + 1):
        res = requests.get(f"{API}{path}", params=params, headers=HEADERS, timeout=10)
        if res.ok:
            return res.json()
        try:
            code = res.json().get("code")  # application/problem+json
        except ValueError:
            code = None
        retryable = res.status_code == 429 or res.status_code >= 500
        if attempt == attempts or not retryable or code == "quota_exceeded":
            res.raise_for_status()
        if code == "rate_limited":
            time.sleep(int(res.headers["Retry-After"]))
        else:
            time.sleep(min(30, 2**attempt * 0.5 * (0.5 + random.random())))


latest = get_with_retry("/v1/latest", {"base": "EUR", "symbols": "USD,GBP"})

Cap the attempts. Four tries with backoff cover a brief blip; beyond that, failing fast and serving cached data is kinder to your users than a request that hangs for a minute.

Spend fewer requests

The cheapest request is the one you do not make. Three habits go a long way:

  • Batch currencies. One /v1/latest call with symbols=EUR,GBP,JPY replaces three conversions. The JavaScript guide shows how to convert locally from it.
  • Cache for at least five minutes. Answers say Cache-Control: private, max-age=300. On the Developer plan the rates are daily, so you can cache for hours. The converter guide builds that cache with ETag and If-None-Match; see also caching.
  • Use ranges for history. One /v1/timeseries call returns up to 366 days. A backfill day by day would use hundreds of requests; see the historical rates guide.

Other answers that look like limits

A 403 is not a rate limit. plan_required means the plan does not include what you asked for, such as history on the Developer plan or a date older than your plan reaches; forbidden means the key's own scope, IP or referrer rules refused the call. Neither gets better by waiting.

Repeated requests with invalid keys from one address are also throttled, with a 429 before the key is checked. If you see 429 on a fresh deployment, check the key first. Need more than Startup gives you? Compare plans on the home page, or read the checklist for choosing an API.

Try it with a free key

The Developer plan is free and includes latest rates and conversion. Every request in this guide is in the API reference. Get a free API key.