Skip to content

Docs

Errors, limits & retries

In short: every error has the same shape, only 429, 503 and 504 are worth retrying, and failed requests are never billed. Every response, errors included, carries an x-request-id; quote it when you contact support.

402 error bodyjson
{
  "error": {
    "code": "insufficient_credits",
    "message": "Your 1,000 free requests are used; add credits or subscribe at https://mcp-guard.ai/dashboard/billing. This request needs 5 checks (1 credit = 1 check); the workspace has 3.",
    "balance": 3,
    "needed": 5,
    "free_runs_remaining": 0,
    "free_runs_total": 1000,
    "unit": "check"
  }
}

Status codes

StatusMeaning
200

Checked. x-credits-charged says what was billed (1 per check; 0 on a free request), x-free-runs-remaining how many free requests are left.

400No retry

invalid_json: the body is not valid JSON.

invalid_request: the check is invalid (missing action, trigger not one of user_request / tool_result / correction / user_override, constraints or conversation of the wrong shape or too long). In a batch the message names the item, e.g. checks[3].trigger.

too_many_checks: more than 64 checks in a batch.

401No retry

missing_api_key or invalid_api_key: no key, a malformed key, or a revoked one. Send Authorization: Bearer mcpg_live_… (x-api-key also works).

402No retry

insufficient_credits: the workspace's 1,000 free requests are used and its balance cannot cover this request (1 credit per check). The body carries balance and needed. Add credits or subscribe in the dashboard.

413No retry

payload_too_large: the body is over 512 KB, or one field (action, intent, context, …) is over 20,000 characters.

422No retry

invalid_request from the model server: an input passed the edge checks but could not be read (for example an action that is only whitespace). Fix the request.

429Retry

rate_limited: too many requests for this workspace (the limit is shared by all its keys). Honour Retry-After (seconds).

503Retry

inference_unavailable: capacity is busy or restarting (Retry-After: 2).

residency_unavailable: the workspace is set to Swiss-only processing and our Swiss GPUs are unavailable. It never fails over outside Switzerland, by design.

Both carry fallback_verdict: "ask": if you cannot wait, treat the action as ask, never as allow. Also auth_unavailable or usage_unavailable when a dependency is briefly down. Nothing was charged; retry with backoff.

504Retry

Gateway timeout. Rare; treat it like 503.

Limits

LimitValue
Checks per batch64(POST /v1/guard/batch and the guard_batch MCP tool)
Characters per field20,000(action text or JSON, intent, user_message, context)
Constraints per check32
Conversation turns50The model reads about 384 tokens per check in total; longer input is trimmed (the newest turns and recipient or target fields are kept) and the response says truncated: true. Send only the context that matters for this action.
Body size512 KB
Rate limit3,000 requests per 10 sper workspace, across all its keys (write to support@mcp-guard.ai to raise it)

What is billed

A successful check costs 1 credit; a batch of N checks costs N credits. While the workspace has free requests left, a request (a single check or a whole batch) uses one of them instead. Any request that fails, for whatever reason, costs nothing. See pricing.

Retry policy with exponential backoff

Retry 429, 503 and 504 (and network errors) with jittered exponential backoff; never retry other 4xx errors. The small random jitter stops many clients from retrying at the same instant. If the guard stays unreachable, decide on a fallback in advance: most agents should treat the action as ask.

Capacity is saturated for a moment: two 503s, then success.

  1. t=0.00s attempt 1 → 503 · wait 0.37s (0.25·2^0 = 0.25s + 0.12s jitter)
  2. t=0.49s attempt 2 → 503 · wait 0.57s (0.25·2^1 = 0.5s + 0.07s jitter)
  3. t=1.18s attempt 3 → 200

Running…

Pythonpython
import random, time, requests

# If the guard cannot answer, a human decides: never fall back to allow.
FALLBACK = {"verdict": "ask", "p_unsafe": 1.0, "reasons": ["guard unavailable"]}

def guard(check, key, attempts=5):
    for i in range(attempts):
        try:
            r = requests.post("https://api.mcp-guard.ai/v1/guard", json=check,
                              headers={"Authorization": f"Bearer {key}"}, timeout=10)
        except requests.RequestException:   # timeout or network error: retry
            r = None
        if r is not None and r.status_code not in (429, 503, 504):
            if r.status_code >= 500:   # any other 5xx: don't retry, a human decides
                return FALLBACK
            r.raise_for_status()   # other 4xx: fix the request, don't retry
            return r.json()
        if i == attempts - 1:
            break                  # no wait after the last attempt
        wait = float(r.headers.get("retry-after", 0)) if r is not None else 0
        time.sleep((wait or min(8, 0.25 * 2 ** i)) + random.random() * 0.25)
    return FALLBACK

Timeouts and failover

Checks run on our GPUs in Switzerland. A warm check takes about 15 ms of model time, plus your network round trip. If those GPUs do not answer within 2 seconds, or answer with an error, the API fails over to the same model on RunPod GPUs in EU data centres. Those workers scale to zero: when one has to start first, a failover can take tens of seconds (we wait up to 45 s). Workspaces set to Swiss-only processing never fail over; they get a 503 residency_unavailable instead.

Pick your client timeout with that in mind. The recipes use 10 seconds: enough for a quick failover, and on a slow one the call is treated as ask rather than waiting. If you would rather wait for an answer than ask a person, use about 50 seconds. Either way, never treat a timeout or a 5xx as allow: every 503 says so in its body.

503 error bodyjson
{
  "error": {
    "code": "inference_unavailable",
    "message": "All inference backends are busy or unreachable. Retry shortly.",
    "fallback_verdict": "ask",
    "last_status": 504
  }
}

The x-guard-backend response header says which backend answered: local (Switzerland), runpod (EU failover) or none.

Errors over MCP

The MCP server reports authentication and rate-limit failures as HTTP errors with a JSON-RPC error body, and tool problems (invalid arguments, not enough credits, inference busy) as a normal tool result with isError: true and a plain-English message. When inference is unavailable that result carries fallback_verdict: "ask", and the message tells the model to confirm with the user rather than run the action. See MCP server.