Skip to content
QwryAI
Documentation
Pages

Getting Started

Error Handling

Error envelopes, every error code, and how to react to each

Every QwryAI API error comes back as JSON with a machine-readable code and a readable message. Branch on code, never on message: messages can change, codes don't. The Chat API and the Tools API wrap errors slightly differently, so this page covers both.

Error Response Format

Errors from https://api.qwryai.com/api/v2 use this envelope:

JSON
{
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable description",
    "details": {}
  }
}
FieldTypeDescription
codestringMachine-readable error code. Use it in your code.
messagestringHuman-readable description.
detailsobjectOnly on VALIDATION_INVALID_BODY: one entry per field that failed, keyed by field name.

Error Codes

Chat API

CodeHTTPDescription
VALIDATION_INVALID_BODY400The body failed validation: a missing message, an unknown field, a userId with characters outside a-z A-Z 0-9 . _ -, or a body over 1 MB. details names each field.
VALIDATION_INVALID_JSON400The body isn't valid JSON.
CHAT_RETRY_NO_USER_MESSAGE400The message you asked to retry has no customer message before it.
AUTH_MISSING_API_KEY401No Authorization header was sent.
AUTH_INVALID_API_KEY401The header isn't Bearer <key>, or the key doesn't exist or was deleted.
AUTH_EXPIRED_API_KEY401The key has expired. Create a new one in Workspace settings › API keys.
CHAT_CREDITS_EXHAUSTED402The workspace doesn't have enough message credits for this answer. Top up or upgrade in Plans.
AUTH_INSUFFICIENT_PERMISSIONS403The key doesn't hold Chat with agents, or its creator is no longer in the workspace.
SUBSCRIPTION_API_RESTRICTED_PLAN403The workspace's plan doesn't include API access. API keys need Starter, Growth or Enterprise.
ACCESS_COUNTRY_BLOCKED403The request comes from a country the agent blocks in Guardrails.
CHAT_CONVERSATION_MISMATCH403The conversation doesn't exist or belongs to a different agent.
AGENT_NOT_FOUND404No agent with that id in your workspace.
RESOURCE_NOT_FOUND404No such endpoint. Check the method and path.
RESOURCE_TOOL_CALL_NOT_FOUND404No client action waiting for this toolCallId. It expired, or its result was already submitted.
CHAT_RETRY_MESSAGE_NOT_FOUND404The messageId to retry isn't an agent answer in this conversation.
CHAT_CONVERSATION_NOT_ONGOING409The conversation can't take a message now: it ended, a teammate took it over, or you asked for a retry while another answer was still being written or a client action was waiting for its result.
RATE_LIMIT_TOO_MANY_REQUESTS429Too many requests, or too many open streams. Wait for Retry-After seconds. See Rate limiting.
INTERNAL_SERVER_ERROR500Something failed on our side. If it keeps happening, contact support with the x-request-id value.

Once a stream has started, errors can't change the HTTP status. They arrive in the stream as an error event, followed by finish with finishReason: "error". See Streaming.

Tools API

CodeHTTPDescription
INVALID_ARGUMENTS400The body isn't a JSON object, or an argument failed the tool's input schema. issues lists each one.
CHATBOT_ID_REQUIRED400The tool works on one agent and the body has no valid chatbotId. Get one from list_agents.
TOO_MANY_CHANGES400A single review can hold at most 20 changes. Split the request.
API_KEY_REQUIRED401No credential was sent.
INVALID_API_KEY401The API key is malformed, unknown or deleted.
INVALID_OAUTH_TOKEN401The OAuth access token is malformed, unknown or expired. Refresh it.
AUTH_EXPIRED_API_KEY401The key has expired.
API_ACCESS_PLAN_REQUIRED403The workspace's plan doesn't include API access.
CREATOR_NOT_ACTIVE403The member who created the credential is no longer in the workspace.
INSUFFICIENT_PERMISSION403The credential doesn't hold the permission this tool needs; required names it.
UNKNOWN_TOOL404No tool with that name for API clients. GET /public/v1/tools lists yours.
CHATBOT_NOT_FOUND404No agent with that chatbotId in your workspace.
REVIEW_NOT_FOUND404No review with that reviewId for this credential. A review can only be applied by the credential that prepared it.
NOTHING_TO_CHANGE409The values you asked for are already set.
VALIDATION_INVALID_BODY409The tool rejected the input on its own rules, such as a date range over 184 days. message says what to fix.
REVIEW_ALREADY_USED409The review was already applied, or it failed.
REVIEW_EXPIRED409More than 15 minutes passed since the review. Call the tool again.
STALE_REVIEW409The resource changed after the review. Call the tool again for a fresh one.
RESULT_TOO_LARGE413The answer is over 40,000 bytes. Use a narrower filter, a shorter date range or a later page.
INTEGRATION_RATE_LIMIT_EXCEEDED429More than 2,000 requests in 15 minutes for this credential. Wait for Retry-After seconds.
TOOL_FAILED500The tool failed on our side. Try again; if it keeps failing, contact support.
UNKNOWN_WRITE_OUTCOME502The change was sent but not confirmed. Read the resource before you retry.

Some tools add codes of their own for problems in your workspace's data. Those use a 4xx status with the same envelope.

Example with field-level details (VALIDATION_INVALID_BODY):

JSON
{
  "error": {
    "code": "VALIDATION_INVALID_BODY",
    "message": "Invalid request",
    "details": {
      "message": "Required"
    }
  }
}

Example with argument issues (INVALID_ARGUMENTS):

JSON
{
  "success": false,
  "error": {
    "code": "INVALID_ARGUMENTS",
    "message": "Invalid arguments for query_tickets: page: Invalid input: expected number, received undefined",
    "issues": [
      { "path": "page", "message": "Invalid input: expected number, received undefined" }
    ]
  }
}

Handling Errors

JavaScript
const response = await fetch(
  "https://api.qwryai.com/api/v2/agents/YOUR_AGENT_ID/chat",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ message: "Hello", stream: false }),
  }
);

if (!response.ok) {
  const { error } = await response.json();
  const requestId = response.headers.get("x-request-id");

  switch (error.code) {
    case "RATE_LIMIT_TOO_MANY_REQUESTS": {
      const retryAfter = Number(response.headers.get("Retry-After"));
      // Wait retryAfter seconds, then retry
      break;
    }
    case "CHAT_CREDITS_EXHAUSTED":
      // Tell the customer you'll get back to them; top up credits
      break;
    case "CHAT_CONVERSATION_NOT_ONGOING":
      // Start a new conversation without conversationId
      break;
    case "VALIDATION_INVALID_BODY":
      console.log("Fix these fields:", error.details);
      break;
    default:
      console.error(`[${error.code}] ${error.message} (request: ${requestId})`);
  }
}
Python
import requests

response = requests.post(
    "https://api.qwryai.com/public/v1/tools/query_tickets",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"chatbotId": "YOUR_AGENT_ID", "page": 1, "status": "open"},
)
body = response.json()

if not response.ok:
    error = body["error"]
    if error["code"] == "INSUFFICIENT_PERMISSION":
        print("Create a key with:", error["required"])
    elif error["code"] == "INVALID_ARGUMENTS":
        for issue in error["issues"]:
            print(issue["path"], issue["message"])
    else:
        print(f"[{error['code']}] {error['message']}")
else:
    tickets = body["data"]["items"]

Explore the documentation