Errors and refusals
Why a governed call gets refused, and how to handle each refusal in code.
Status codes
| Status | Means | Body |
|---|---|---|
401 | No credential, or the credential is wrong, rotated, revoked or expired. | {"detail":"unknown api key"} |
402 | A budget, plan, license, or usage cap refuses the request. Budget refusals before dispatch do not incur provider spend. | {"detail":{"code":"budget_exceeded",...}} — see below |
403 | Authenticated, but the key's scope, model allowlist, or tool binding does not cover this request. | {"detail":{"error":"model_not_allowed","model":...,"allowed_models":[...]}} |
400 | The request is invalid, or an inline guardrail blocks content. Output guardrail blocks can happen after a billable provider call. | {"detail":{"code":"invalid_request",...}} |
429 | A 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",...}} |
503 | Reports (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",...}} |
504 | A 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",...}} |
409 | The 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"} |
413 | The request body is too large. Send a smaller file, or a URL where the endpoint accepts one. | A message naming the limit |
422 | The 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 |
502 | A 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 a429(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 theaudit:readscope 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.
| Status | Code | Meaning |
|---|---|---|
400 | guardrail_blocked | An inline guardrail blocked the call. See Guardrails. |
400 | provider_key_missing | The workspace has no key for the model's provider. An admin adds it. See Handle refusals. |
400 | ends in _streaming_unsupported | The request can't be streamed under your policy. Send it with stream=false. See Streaming. |
402 | plan_required | The trial ended. See Sign up. |
403 | mcp_tool_not_authorized | The agent isn't bound to that MCP tool. See MCP servers. |
403 | mandatory_skills_missing | A required skill is missing from the request and enforcement is set to block. See Govern skills. |
403 | marking_required | The speech model is below the marking level your workspace requires. See Voice governance. |
403 | not_permitted | The agent-to-agent binding isn't live. See Tasks. |
409 | agent_name_ambiguous | Two agents share the name. See Agent cards. |
409 | voice_asset_exists | That provider voice is already registered. See Voice governance. |
422 | disclosure_missing, consent_required | A voice rule refused the call before anything was charged. See Voice governance. |
422 | binding_cross_environment | The binding crosses environments. See Agent-to-agent. |
429 | ceiling_exceeded | An agent reached a tool's call ceiling. See Tool registry. |
429 | ocr_busy | Too many OCR requests are running. Retry after the Retry-After delay. See Document OCR. |
WebSocket close 1008 | unsupported_model | The 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.

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:BudgetExceededError401:AuthenticationError403:PermissionDeniedError429: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)import { Forgebench, BudgetExceededError, PermissionDeniedError, AuthenticationError, RateLimitError } from "@seedlinglabs/forgebench-sdk";
const forgebench = new Forgebench({ apiKey: "sk_...", baseUrl: "https://api.forgebench.ai" });
const messages = [{ role: "user" as const, content: "..." }];
try {
const res = await forgebench.chat.create({ model: "gpt-4o", messages });
} catch (e) {
if (e instanceof BudgetExceededError) {
console.warn("budget gate refused the call", e.body);
} else if (e instanceof PermissionDeniedError) {
console.error("not authorized", e.body);
} else if (e instanceof AuthenticationError) {
console.error("auth failed", e.body);
} else if (e instanceof RateLimitError) {
console.warn("rate limit refused the call", e.body);
} else {
throw e;
}
}import ai.forgebench.ChatCompletionRequest;
import ai.forgebench.ChatMessage;
import ai.forgebench.Forgebench;
import ai.forgebench.errors.AuthenticationException;
import ai.forgebench.errors.BudgetExceededException;
import ai.forgebench.errors.PermissionDeniedException;
import ai.forgebench.errors.RateLimitException;
import ai.forgebench.types.ChatCompletion;
import java.util.List;
Forgebench client = Forgebench.builder().apiKey("sk_...").baseUrl("https://api.forgebench.ai").build();
List<ChatMessage> messages = List.of(ChatMessage.user("..."));
try {
ChatCompletion resp = client.chat().completions().create(ChatCompletionRequest.builder()
.model("gpt-4o")
.messages(messages)
.build());
} catch (BudgetExceededException e) {
log.warn("budget gate refused the call: {}", e.getBody());
} catch (PermissionDeniedException e) {
log.error("not authorized: {}", e.getBody());
} catch (AuthenticationException e) {
log.error("auth failed: {}", e.getBody());
} catch (RateLimitException e) {
log.warn("rate limit refused the call: {}", e.getBody());
}# -i prints the status line: 402 budget, 403 not authorized, 401 auth failed
curl -i -X POST https://api.forgebench.ai/v1/chat/completions \
-H "Authorization: Bearer sk_..." \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "..."}]
}'
