Get started Errors & refusals

Errors and refusals

Why a governed call gets refused, and how to handle each refusal in code.

Status codes

StatusMeansBody
401No credential, or the credential is wrong, rotated, revoked or expired.{"detail":"unknown api key"}
402A budget, plan, license, or usage cap refuses the request. Budget refusals before dispatch do not incur provider spend.{"detail":{"code":"budget_exceeded",...}} — see below
403Authenticated, but the key's scope, model allowlist, or tool binding does not cover this request.{"detail":{"error":"model_not_allowed","model":...,"allowed_models":[...]}}
400The request is invalid, or an inline guardrail blocks content. Output guardrail blocks can happen after a billable provider call.{"detail":{"code":"invalid_request",...}}
429A rate limit (requests per minute) or tool-call limit (calls per window) was hit. Console actions (platform report download, sending invites, opening an invite link) have their own per-minute limits, and the response carries Retry-After in seconds.{"detail":{"code":"rate_limit_exceeded",...}}
503Reports (analytics report, report PDFs, report emails) are busy: one is already being built. The response carries Retry-After in seconds; retry after it.{"detail":{"code":"report_build_busy",...}}
504A report took too long to build and was stopped (retry with a shorter date range), or a model provider didn't answer in time (provider_timeout). A sarvam-vision OCR job that runs over two minutes also returns it; see Document OCR.{"detail":{"code":"report_build_timeout",...}}
409The resource isn't in the right state, for example deleting something that must be revoked first. Fix its state; don't retry the same call.{"detail":"only a revoked server can be deleted — revoke it first"}
413The request body is too large. Send a smaller file, or a URL where the endpoint accepts one.A message naming the limit
422The request is well formed but can't be served, for example a model that doesn't fit the endpoint or a field the model refuses. Nothing is charged. Fix the request; don't retry it.A message naming the field or model
502A model provider's reply couldn't be read or used. Retry once. For a charged OCR job, see Document OCR.A message naming the provider

401 — unauthorized: bad credential or paused agent

{"detail":"unknown api key"}

The key is missing, malformed, rotated, revoked or expired ({"detail":"api key expired"}). Rotation replaces the stored secret hash with no planned overlap. An expired fixed-date key needs a replacement. Rotating an agent or template key with a renewable lifetime starts its clock again. Manage keys on API keys and spend. A paused or retired agent's key is unauthorized too; see Agents.

402 — budget exceeded

{
  "detail": {
    "code": "budget_exceeded",
    "message": "monthly budget exceeded",
    "limit_usd": "0.000100",
    "spent_usd": "0.000385",
    "attempted_cost_usd": "0.005000"
  }
}

A call is refused when spent + attempted would cross the cap, so you can be refused while the dashboard still shows headroom. With $0.00542 spent against a $0.01 cap, a $0.005 call is refused because $0.01042 is over. See Budgets.

Per-key limits use the same shape with a different code: key_daily_limit_exceeded and key_monthly_limit_exceeded, both with a resets_at. A license_blocked or plan_required 402 means your plan doesn't include the feature, not that you ran out of budget.

A token cap refusal has the code token_cap_exceeded and carries level, period, limit_tokens, used_tokens and attempted_tokens. The SDKs raise TokenCapExceededError (TokenCapExceededException in Java), a subclass of the budget error, so one handler covers both.

Workspace daily caps return daily_budget_exceeded. Model caps return model_budget_exceeded or model_daily_budget_exceeded; agent caps return agent_budget_exceeded. Routing policy budgets return routing_budget_exceeded. Use the code and identifiers in the response to find the binding cap.

Budget pools add pool_budget_exceeded (the pool's limit) and pool_member_share_exceeded (the calling key's share). The body says which limit was hit and who owns it (limit_kind, pool_owner, key_owner). See Pool API and errors.

403 — model not allowed, tool not authorized, or missing scope

Three causes share this status:

  • Model not allowed for this key: {"detail":{"error":"model_not_allowed","model":...,"allowed_models":[...]}}. The key's model list doesn't include the requested model.
  • Tool not authorized: {"detail":{"code":"tool_not_authorized","tool_name":...}}. The model tried to call a tool the agent isn't bound to. Repeated attempts on the same tool escalate to a 429 (tool_repeatedly_unauthorized).
  • Role/scope: {"detail":"requires role '<role>' or one of scopes: <scopes>"}. The caller's role or scopes don't cover the action, for example reading audit without the audit:read scope or an admin role.

To fix any of these, change the request or the key's configuration.

Common codes

The code in the body tells you which rule refused the call. These are the ones you're most likely to meet. Each links to the page that explains it.

StatusCodeMeaning
400guardrail_blockedAn inline guardrail blocked the call. See Guardrails.
400provider_key_missingThe workspace has no key for the model's provider. An admin adds it. See Handle refusals.
400ends in _streaming_unsupportedThe request can't be streamed under your policy. Send it with stream=false. See Streaming.
402plan_requiredThe trial ended. See Sign up.
403mcp_tool_not_authorizedThe agent isn't bound to that MCP tool. See MCP servers.
403mandatory_skills_missingA required skill is missing from the request and enforcement is set to block. See Govern skills.
403marking_requiredThe speech model is below the marking level your workspace requires. See Voice governance.
403not_permittedThe agent-to-agent binding isn't live. See Tasks.
409agent_name_ambiguousTwo agents share the name. See Agent cards.
409voice_asset_existsThat provider voice is already registered. See Voice governance.
422disclosure_missing, consent_requiredA voice rule refused the call before anything was charged. See Voice governance.
422binding_cross_environmentThe binding crosses environments. See Agent-to-agent.
429ceiling_exceededAn agent reached a tool's call ceiling. See Tool registry.
429ocr_busyToo many OCR requests are running. Retry after the Retry-After delay. See Document OCR.
WebSocket close 1008unsupported_modelThe model can't be used for a speech-to-speech conversation. See Voice.

Model providers' own failures come back with a code that names the cause: provider_bad_request, provider_auth_failed, provider_not_found, provider_rate_limited or provider_timeout. Agent groups have their own list of refusals on Agent groups.

Refusals are recorded

Forgebench records governed refusals (budget, rate limit, license, model not allowed, guardrail, tool not authorized, and agent paused) in the Refusals log with their cause. Check it first when an integration stops working after someone tightens a cap or a model allowlist. Authentication failures for unknown or revoked keys can happen before a workspace is identified and do not guarantee a workspace refusal entry.

The refusal log — one row per refused call, with its cause
The refusal log — one row per refused call, with its cause

Select a refusal to see its Trace id and the trace itself, read in place. A call refused before the model ran may have no trace yet, and the page says so. If Observability isn't set up for your workspace, the trace can't be shown but the id still is.

Each cause links to the screen that controls it: budget and rate_limit link to Budgets, tool_not_authorized to the tool registry, and agent_paused to the agent. Budget and input-policy refusals happen before provider dispatch. A tool or output guardrail block can withhold a result after the provider has run; that usage is still billed.

Which exception to catch

All three SDKs raise a typed error for each non-2xx status, so you branch on the exception type. An unauthorized key raises AuthenticationError in Python and TypeScript:

  • 402: BudgetExceededError
  • 401: AuthenticationError
  • 403: PermissionDeniedError
  • 429: RateLimitError

Java uses the same names ending in Exception, such as BudgetExceededException.

Retry on a rate limit

A 429 means a request-rate or tool-call limit, not money. Wait for the number of seconds in Retry-After, then retry. The OpenAI clients already retry a 429 twice (max_retries=2), so a RateLimitError that reaches your code has used those retries: queue the work for later rather than adding another retry loop. A 402 is different: retrying cannot succeed until the budget changes.

Handling refusals in code

Each example catches the refusals above.

from forgebench import Forgebench, BudgetExceededError, PermissionDeniedError, AuthenticationError, RateLimitError

client = Forgebench(api_key="sk_...", base_url="https://api.forgebench.ai")
messages = [{"role": "user", "content": "..."}]

try:
  resp = client.chat.completions.create(model="gpt-4o", messages=messages)
except BudgetExceededError as e:
  log.warning("budget gate refused the call: %s", e)
except PermissionDeniedError as e:
  log.error("not authorized: %s", e)
except AuthenticationError as e:
  log.error("auth failed: %s", e)
except RateLimitError as e:
  log.warning("rate limit refused the call: %s", e)

Next

Cookie settings

Our Cookie Policy lists every cookie and what it does.