Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Rate limits

The Qaf API allows 60 requests a minute per account, plus a weekly number of searches set by the plan. The rate-limit headers, the 429 response, and how to back off.

Limits apply per Qaf account, across all of its API keys:

Limit Applies to
60 requests a minute Every endpoint.
Weekly searches POST /v1/search. 2,500 a week on every plan.

Weekly searches

Every plan, Free included, gets 2,500 searches a week as an introductory offer.

The API and the MCP server share one weekly allowance, so searches from an AI app and from your code add up. A search that fails, such as a 400 for an unknown author ID, isn’t counted. The allowance starts over a week after it last did, not on a fixed weekday. qaf.ai Settings › Usage shows how many searches are left, under MCP / API, and when the allowance resets. Reading passages and looking up the catalog don’t use it.

The MCP server’s minute limit is separate: see MCP server.

Headers

Once the API has accepted your key, its response reports the account’s minute window:

Header Value
X-RateLimit-Limit Requests the account can make per minute.
X-RateLimit-Remaining Requests left in the current minute.
X-RateLimit-Reset Seconds until the minute’s allowance resets.

These headers always describe the minute window. A 429 for the minute or week limit has them too; on a week refusal, Retry-After is the time until searches work again instead. They’re absent when the API refuses a request before it accepts the key: any 401 or 403, an invalid_keys 429, a body over 64 KiB (413), a body that isn’t valid JSON (400), or a path the API doesn’t have (404, 405).

When you reach a limit

The API answers 429 with a Retry-After header, in seconds, and the reason in the body:

{
  "code": "RATE_LIMITED",
  "status": 429,
  "message": "Too many requests. Try again later.",
  "data": { "retryAfter": 23, "reason": "minute" }
}
reason Means
minute The account made 60 requests this minute.
week The account used its weekly searches. The other endpoints still work. Retry-After is the time until searches work again, which can be days.
invalid_keys Your network address has sent too many keys that don’t exist or were revoked, usually the one you sent. While this lasts, a working key sent from the same address can be refused too if it wasn’t used in the last hour, such as a new key.

Back off and retry

When reason is minute, wait Retry-After seconds, then send the request again. The other reasons need more:

  • week: stop searching, and tell your users when searches work again. Retry-After can be several days.
  • invalid_keys: check the key. If it doesn’t exist or was revoked, retrying fails again. If it works, another client at your address is sending bad keys: wait Retry-After (at most a minute) and retry once.

For 500 and 503 responses, which have no Retry-After, wait longer after each failed attempt.

const sleep = (seconds: number) =>
	new Promise((resolve) => setTimeout(resolve, seconds * 1000));

async function callQaf(url: string, init: RequestInit, attempts = 4) {
	let keyRefused = false;

	for (let attempt = 1; ; attempt++) {
		const response = await fetch(url, init);

		if (response.status === 429) {
			const { data } = await response.clone().json();

			if (data?.reason === "week")
				throw new Error(`Weekly searches used. Searches resume in ${data.retryAfter} s.`);

			if (data?.reason === "invalid_keys") {
				// Another client at this address may be sending bad keys: retry once.
				if (keyRefused)
					throw new Error("Too many invalid API keys from this address. Check QAF_API_KEY.");

				keyRefused = true;
			} else if (data?.reason !== "minute") {
				return response;
			}

			if (attempt === attempts) return response;

			await sleep(Number(response.headers.get("Retry-After")));
		} else if (response.status >= 500 && attempt < attempts) {
			await sleep(2 ** attempt);
		} else {
			return response;
		}
	}
}
import time

import requests


def call_qaf(method, url, attempts=4, **kwargs):
    key_refused = False

    for attempt in range(1, attempts + 1):
        response = requests.request(method, url, timeout=30, **kwargs)

        if response.status_code == 429:
            data = response.json().get("data") or {}

            if data.get("reason") == "week":
                raise RuntimeError(f"Weekly searches used. Searches resume in {data['retryAfter']} s.")

            if data.get("reason") == "invalid_keys":
                # Another client at this address may be sending bad keys: retry once.
                if key_refused:
                    raise RuntimeError("Too many invalid API keys from this address. Check QAF_API_KEY.")

                key_refused = True
            elif data.get("reason") != "minute":
                return response

            if attempt == attempts:
                return response

            time.sleep(int(response.headers["Retry-After"]))
        elif response.status_code >= 500 and attempt < attempts:
            time.sleep(2**attempt)
        else:
            return response

Spread requests over the minute rather than sending them in bursts, and cache results you read more than once: passages rarely change.

Need more

If your project needs more than 2,500 searches a week, email us at contact@qaf.ai with what you’re building and the volume you expect.