Rate limits
Over a limit, the API refuses the request and tells you how long to wait in the Retry-After header (seconds). A refused request is not charged. Console sessions count as one caller per account.
| Limit | Value | Over it |
|---|---|---|
Per client IP, all /v1/* routes | 60 requests/s, burst 120 | 429 rate_limited + Retry-After, before authentication |
Per API key, /v1/detect | 60 requests/s, burst 120 | 429 rate_limited + Retry-After |
| Console session, per account | 10 requests/s, burst 30 | 429 rate_limited + Retry-After |
| Console billing routes, per account | 20 per minute, burst 5 | 429 rate_limited + Retry-After |
| Detections in progress, per account | 1 at a time | 429 rate_limited + Retry-After |
| Model capacity | n/a | 429 model_busy + Retry-After |
Text, /v1/detect | 20,000 code points | 413 text_too_long |
Request body, /v1/detect | 1 MB | 413 text_too_long |
| Request body, other customer routes | 64 KB | 413 request_too_large |
| Active API keys, per account | 25 | 409 key_limit_reached |
| Slow requests | body over 30 s, request over 60 s | 408 request_timeout |
The detection limit covers the whole account: all its API keys and its playground. Send detections one after another. Contact us if you need more.
See the error table for every code.
How to retry
Send an Idempotency-Key with each call. The API does not replay results: a reuse of a key within 24 hours returns 409 idempotency_key_reused, with no inference and no charge, when the first call was charged or is still running. A call that ended with nothing charged (model_busy, model_unavailable) frees its key.
- You got a 429 (
rate_limitedormodel_busy): the call was never charged and its key is free. WaitRetry-Afterseconds, or use exponential backoff with jitter when there is no header. Then retry with the same key. - You got
503 model_unavailable: nothing was charged and the key is free. WaitRetry-Afterseconds, or use exponential backoff with jitter when there is no header. Then retry with the same key. - You got another response (408, other 5xx or any other error): that attempt is finished and was not charged. Wait
Retry-Afterseconds, or use exponential backoff with jitter when there is no header. Then retry with a new key. - You got no response (timeout or dropped connection): retry with the same key. If you get
409 idempotency_key_reused, the first attempt was charged or is still running, so you were not charged twice. Its result cannot be recovered. Check your usage, and send with a new key only if you still need the result. That call can be charged. If that retry gets a 429, waitRetry-Afterand retry again with the same key. - Stop after a few attempts.
curl
KEY=$(uuidgen)
curl -i https://api-protect.opami.ai/v1/detect \
-H "Authorization: Bearer $OPAMI_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $KEY" \
-d '{"model":"protect-v1","text":"Zoë Müller lives in Berlin."}'
# After a 429 with "Retry-After: 2": wait 2 seconds, then run the same curl again (same $KEY).
# After a 503 model_unavailable: wait, then run the same curl again (same $KEY).
# After a 408 or another 5xx: run KEY=$(uuidgen) first, then the curl.TypeScript
async function detect(text: string, maxAttempts = 5): Promise<unknown> {
let key = crypto.randomUUID();
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
let res: Response;
try {
res = await fetch("https://api-protect.opami.ai/v1/detect", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPAMI_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": key,
},
body: JSON.stringify({ model: "protect-v1", text }),
signal: AbortSignal.timeout(65_000),
});
} catch {
// No response: keep the same key.
await sleep(backoff(attempt));
continue;
}
if (res.ok) return res.json();
const retryable = res.status === 408 || res.status === 429 || res.status >= 500;
if (!retryable) throw new Error(`detect failed: ${res.status}`);
// A 429 or 503 ended with nothing charged and frees the key: keep the same key.
// After 408 or another 5xx the attempt is finished: use a new key.
if (res.status !== 429 && res.status !== 503) key = crypto.randomUUID();
const wait = Number(res.headers.get("Retry-After"));
await sleep(wait > 0 ? wait * 1000 : backoff(attempt));
}
throw new Error("detect failed after retries");
}
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
const backoff = (n: number) => Math.min(30_000, 500 * 2 ** n) * (0.5 + Math.random() / 2);A 409 idempotency_key_reused is not retried above. It means an earlier attempt with that key was charged or is still running. Check your usage before you send again.
Need more (design partners, batch jobs)? Contact us; higher limits per account on request.