Error Codes Reference

OpenClaw uses structured error codes to identify specific failure modes. Knowing the error code lets you quickly look up the cause and remediation, whether you're debugging in logs or handling errors in code that calls the API.

Error Response Format

All error responses from the API use a consistent JSON structure:

{
  "error": {
    "code": "AGENT_BUDGET_EXCEEDED",
    "message": "Task exceeded configured token budget of 50000 tokens (used: 52341)",
    "detail": {
      "budget": 50000,
      "used": 52341,
      "task_id": "task_abc123"
    },
    "docs_url": "https://openclaw.ai/reference/error-codes/#agent_budget_exceeded"
  }
}

Agent Errors (1xxx)

CodeHTTPCauseResolution
AGENT_MAX_STEPS200Agent looped without completingIncrease max_steps or improve system prompt to prevent loops
AGENT_BUDGET_EXCEEDED200Token budget exhaustedIncrease max_tokens or break task into smaller subtasks
AGENT_TIMEOUT200Wall-clock timeoutIncrease timeout_seconds or reduce task scope
AGENT_TASK_INVALID400Task string is empty or malformedValidate input before submission

LLM Provider Errors (2xxx)

CodeCauseResolution
LLM_AUTH_FAILEDAPI key invalid or expiredCheck API key configuration and provider account status
LLM_RATE_LIMITEDProvider rate limit hitReduce concurrency or request rate limit increase from provider
LLM_CONTEXT_OVERFLOWRequest exceeded model context windowReduce max_turns in memory config or truncate input
LLM_PROVIDER_ERRORProvider returned 5xx errorCheck provider status page; OpenClaw will retry automatically
LLM_TIMEOUTLLM API call timed outIncrease llm.timeout_seconds or switch to faster model

Tool Errors (3xxx)

CodeCauseResolution
TOOL_NOT_FOUNDLLM referenced a tool that doesn't existCheck tools.enabled list; ensure tool name in prompt matches config
TOOL_INVALID_ARGSLLM provided args failing JSON Schema validationReview tool's argument schema; improve system prompt specificity
TOOL_PERMISSION_DENIEDTool tried to access resource outside allowed scopeUpdate tools.config permissions or restrict system prompt
TOOL_TIMEOUTTool execution exceeded timeoutIncrease tool-specific timeout in tools.config
TOOL_EXECUTION_FAILEDTool threw an unhandled exceptionCheck tool logs for exception details; fix tool implementation

Configuration Errors (4xxx)

CodeCauseResolution
CONFIG_MISSINGConfig file not found at expected pathRun openclaw config init or specify path with --config
CONFIG_INVALID_SCHEMAConfig fails JSON Schema validationRun openclaw config validate for details
CONFIG_MISSING_REQUIREDRequired config key not setAdd the required key to config or set via environment variable

Authentication and Authorization (5xxx)

CodeHTTPCause
AUTH_MISSING_KEY401X-API-Key header not provided
AUTH_INVALID_KEY401X-API-Key does not match configured server.api_key
PERMISSION_DENIED403API key lacks required permission for this operation

Handling Errors in Application Code

When calling the OpenClaw API from your application, handle errors by checking the error code and taking appropriate action per error class. Not all errors warrant the same response — a rate limit error should trigger a backoff and retry, while an auth error should surface to the user immediately rather than retrying:

import time
import httpx

def run_task_with_retry(task: str, max_retries: int = 3) -> dict:
    for attempt in range(max_retries):
        response = httpx.post("/v1/tasks", json={"task": task})
        if response.status_code == 200:
            return response.json()
        error = response.json().get("error", {})
        code = error.get("code", "")
        if code == "LLM_RATE_LIMITED":
            wait = 2 ** attempt   # exponential backoff
            time.sleep(wait)
            continue
        if code in ("AUTH_MISSING_KEY", "AUTH_INVALID_KEY"):
            raise ValueError(f"Authentication failed: check your API key")
        raise RuntimeError(f"Task failed: {code} — {error.get('message')}")
    raise RuntimeError("Max retries exceeded")

The docs_url field in every error response links to this reference page with the section anchored to the specific error code — your error handling code can surface this URL directly to developers investigating failures.

Task Status vs. Error Responses

Note that agent errors (AGENT_* codes) result in HTTP 200 responses with a status: "failed" field in the task result — the task ran but the agent could not complete it. These are not HTTP errors; the API call itself succeeded. HTTP error codes (4xx, 5xx) occur only for infrastructure-level failures: invalid requests, authentication failures, server errors. Always check both the HTTP status code and the task status field when determining whether a task completed successfully.

Error Codes in Logs

Every task failure in the logs includes the error code as a structured field: "error_code": "AGENT_MAX_STEPS". This makes it trivial to write log-based alerts on specific error types (alert on any LLM_AUTH_FAILED log event) and to query for failure distributions (what percentage of failures are budget-exceeded vs. LLM errors vs. tool errors?). Build a Grafana dashboard showing error code distribution over time — seasonal patterns often emerge that guide configuration tuning: if Monday mornings see more AGENT_TIMEOUT errors, it may indicate peak load requiring more concurrency.

Self-Healing Behavior

Several error conditions trigger automatic self-healing behavior rather than immediate failure. When LLM_RATE_LIMITED occurs, OpenClaw waits the duration specified in the provider's Retry-After header and then retries — up to the configured llm.max_retries times. When a tool produces a TOOL_EXECUTION_FAILED result, the agent receives the error description and can choose to retry with different arguments or try an alternative approach, rather than failing immediately. This resilience to transient errors is a key design property of the ReAct loop — it enables agents to recover gracefully from the kinds of errors that real production environments regularly produce.

Error Monitoring Best Practices

Track error code distributions in your monitoring system. A sudden spike in LLM_RATE_LIMITED suggests your traffic has grown beyond your current tier — contact your LLM provider for a quota increase before it impacts users. A steady accumulation of AGENT_MAX_STEPS on specific task types indicates those tasks need a refined system prompt or a higher max_steps value. TOOL_PERMISSION_DENIED in production is almost always a configuration mistake — the allowed_dirs or allowed_domains list wasn't updated when a new tool or task pattern was added. Investigate and resolve it immediately rather than expanding permissions blindly.