Exchange Rate API Rate Limits: How to Handle 429 Errors and Retries

6 min read

Exchange Rate API Rate Limits: How to Handle 429 Errors and Retries

If your app calls an exchange rate API often enough, sooner or later you will see an HTTP 429. The right response depends on why you got it. A per-second rate limit clears in a moment and is safe to retry. An exhausted monthly quota will not clear by retrying, and hammering the API only makes your logs noisy.

This guide covers how to handle exchange rate API rate limits properly: which errors deserve a retry, how to back off, how to cut your request count before you ever hit a limit, and what your app should show when the rate truly cannot be fetched. The principles apply to any REST API. The examples use GetRatesAPI.

Two kinds of 429: rate limit versus quota

Most APIs limit you in two ways, and both can return the same HTTP status.

  • Rate limit: a cap on requests per second. Bursts above it are rejected briefly. It resets almost immediately.
  • Quota: a cap on total request units per billing period, usually a month. Once it is used up, it stays used up until the period rolls over or you upgrade.

GetRatesAPI separates them in the error body, so you never have to guess from the status code alone. A burst returns rate_limit_exceeded with a retry_after_seconds value. An exhausted allowance returns quota_exceeded. Always branch on the code field and not on the message text, which can change.

{
  "code": "rate_limit_exceeded",
  "message": "Too many requests.",
  "request_id": "req_example123",
  "retry_after_seconds": 1
}

Rate-limited requests are not billed, so retrying after a short wait costs nothing extra. Malformed requests are not billed either.

Which errors to retry and which to fail fast

A retry policy is mostly a decision table. Retrying something that can never succeed wastes time. Not retrying something transient causes needless failures.

CodeHTTPRetry?What to do
rate_limit_exceeded429YesWait retry_after_seconds, add jitter, try again
temporarily_unavailable503YesExponential backoff with jitter, limited attempts
quota_exceeded429NoAlert someone, serve the last known rate, upgrade or wait for reset
unauthorized401NoCheck the key; it may be revoked or rotated
invalid_asset_symbol400NoFix the currency code in your code or data
invalid_amount400NoFix the amount string
unsupported_pair404NoShow a clear message; do not retry

Network errors such as timeouts and dropped connections belong in the retry group too, since the request may never have reached the server. Reading exchange rates is idempotent, so retrying is always safe. The full list of codes is in the error reference.

A retry wrapper with backoff and jitter

Two details matter more than anything else here: respect the server's retry_after_seconds when it gives one, and add random jitter so that many workers do not all retry at the same instant.

const BASE = "https://api.getratesapi.com";
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

// Exponential backoff: 0.5s, 1s, 2s, ... plus up to 250 ms of jitter.
const backoff = (attempt) =>
  500 * 2 ** (attempt - 1) + Math.random() * 250;

class ApiError extends Error {
  constructor(body, status) {
    super(body.message || `HTTP ${status}`);
    this.code = body.code;
    this.status = status;
    this.requestId = body.request_id;
  }
}

async function getJson(path, maxAttempts = 4) {
  for (let attempt = 1; ; attempt++) {
    let res;
    try {
      res = await fetch(BASE + path, {
        headers: { Authorization: `ApiKey ${process.env.GETRATES_API_KEY}` },
      });
    } catch (networkError) {
      if (attempt >= maxAttempts) throw networkError;
      await sleep(backoff(attempt));
      continue;
    }

    if (res.ok) return res.json();

    const body = await res.json().catch(() => ({}));

    if (body.code === "rate_limit_exceeded" && attempt < maxAttempts) {
      const wait = (body.retry_after_seconds ?? 1) * 1000;
      await sleep(wait + Math.random() * 250);
      continue;
    }
    if (body.code === "temporarily_unavailable" && attempt < maxAttempts) {
      await sleep(backoff(attempt));
      continue;
    }

    // quota_exceeded, unauthorized, invalid_*, unsupported_pair, or out of attempts
    throw new ApiError(body, res.status);
  }
}

const rate = await getJson("/v1/rates/EUR/USD");
console.log(rate.rate, rate.status, rate.as_of);

Cap the number of attempts. Four is plenty for a checkout, where a user is waiting. A background job can afford more, but it should still give up eventually and report.

Log the request_id from every failed call. If you ever contact support, it is the fastest way to locate the exact request.

Reduce requests before you hit a limit

The cheapest retry is the one you never need. Most rate-limit trouble comes from avoidable request volume.

Batch quotes against one base

If you need several currencies against the same base, do not loop. One call returns up to 20 quotes and costs 1 request unit:

curl -H "Authorization: ApiKey $GETRATES_API_KEY" \
  "https://api.getratesapi.com/v1/rates/USD?quote=EUR,GBP,JPY,CHF"

A product page that shows prices in four currencies needs one request, not four. If a quote is not supported, it comes back in an unsupported list instead of failing the whole call, so a single odd code will not break the batch.

Fetch once, serve many

Ten thousand visitors do not need ten thousand upstream calls. Fetch a rate on a schedule or on first demand, then serve it from memory or a shared cache. How long you can safely hold a rate depends on the as_of and status fields. We cover that in detail in How to Cache Exchange Rates Without Showing Stale Prices.

Match your refresh interval to the data

There is no benefit in polling faster than the data changes. Crypto prices refresh every 10 seconds, and fiat currencies and metals every 60 seconds. Polling a fiat pair every second just spends units on identical answers.

Throttle on your side

If you run parallel workers, a small client-side limiter keeps you under your plan's per-second limit so that 429s become rare. A simple approach is a shared queue that releases one request every 1000 / requests_per_second milliseconds. The limits per plan are on the pricing page, and rate limit behavior is documented.

Watch your quota before it runs out

A quota failure is the worst kind because it arrives all at once. Do not wait for quota_exceeded to find out. The usage endpoint returns the period, units used, the quota and what remains, and calling it does not need guesswork:

import os
import requests

resp = requests.get(
    "https://api.getratesapi.com/v1/account/usage",
    headers={"Authorization": f"ApiKey {os.environ['GETRATES_API_KEY']}"},
    timeout=10,
)
resp.raise_for_status()
usage = resp.json()

used, quota = int(usage["used"]), int(usage["quota"])
if used / quota > 0.8:
    print("Over 80% of monthly request units used; review traffic or plan.")

Run a check like this daily from a scheduled job and send an alert at 80 percent. Details on how units are counted are in usage and quotas. Catalog calls such as /v1/assets are free, so you can validate currency codes against them without spending units.

What to do when the rate cannot be fetched

Even with good retries, there will be moments when you have no fresh answer. Decide the fallback in advance, per use case:

  • Display prices: show the last known rate and its as_of time internally, and keep going. A slightly old price estimate is usually better than an error page.
  • Checkout and invoicing: a final charge should use a rate you can record and explain. If you cannot get one, pause the step or use a locked rate you already stored, rather than inventing a number.
  • Dashboards: show the value with a "last updated" label so users can judge it themselves.
  • Background jobs: queue the work and retry later instead of failing the whole batch.

Remember that GetRatesAPI flags old data instead of hiding it. A rate with "status": "stale" is still returned, and your code decides whether it is good enough for the task. A stale value in cache is not the same as a failed request, and treating them differently keeps your app responsive.

Quick checklist

  • Branch on code, never on message text or only on HTTP status.
  • Retry rate_limit_exceeded using retry_after_seconds plus jitter.
  • Retry temporarily_unavailable and network errors with capped exponential backoff.
  • Never retry quota_exceeded, unauthorized, or 400 and 404 errors.
  • Batch up to 20 quotes per call and cache what you fetch.
  • Monitor usage and alert well before the quota runs out.
  • Define a fallback for every place a rate is used.

Try it on the free plan

You can test all of this without a credit card. Sign up for the free plan, use the dashboard playground to see real error responses, and check the current rate endpoint docs for the full response shape. When your traffic grows, compare plans on the pricing page.

All articles →
How to Cache Exchange Rates Without Showing Stale Prices

6 min read

How to Cache Exchange Rates Without Showing Stale Prices

Calling a rates API on every page view wastes quota and slows pages. Here is how to cache exchange rates with the right TTL for each use case, and how to fall back safely when the API is unavailable.

Exchange Rate API Rate Limits: Handle 429s and Retries — GetRatesAPI