Skip to main content
When an API request fails, IllumiChat returns a structured error response with an HTTP status code, a human-readable message, and a machine-readable error code.

Error Response Format

{
  "error": "Human-readable error message",
  "code": "error_type:context"
}
FieldTypeDescription
errorstringA message suitable for displaying to users or logging
codestringA structured code in type:context format for programmatic handling

Validation Errors

Some endpoints return field-level details when validation fails:
{
  "error": "Validation failed",
  "code": "bad_request:api",
  "details": {
    "name": "Name is required",
    "email": "Invalid email format"
  }
}

HTTP Status Codes

CodeMeaningDescription
200OKSuccessful GET, PATCH, or DELETE request
201CreatedSuccessful POST request that created a resource
400Bad RequestValidation failed or required fields are missing
401UnauthorizedNot authenticated — session is missing or expired
403ForbiddenAuthenticated but insufficient permissions
404Not FoundThe requested resource does not exist
409ConflictResource already exists (e.g., duplicate name)
429Too Many RequestsRate limit exceeded
500Internal Server ErrorAn unexpected error occurred on the server

Error Code Reference

Authentication & Authorization

CodeHTTP StatusDescription
unauthorized:api401Not authenticated for an API operation
unauthorized:chat401Not authenticated for a chat operation
unauthorized:widget401Not authenticated for a widget operation
forbidden:api403Insufficient permissions for the operation

Request Errors

CodeHTTP StatusDescription
bad_request:api400Invalid request parameters or missing fields
bad_request:chat400Invalid chat request
not_found:api404Requested resource was not found
not_found:chat404Chat conversation not found
not_found:widget404Widget configuration not found
conflict:api409Resource conflict such as a duplicate entry

Rate Limit Errors

CodeHTTP StatusDescription
rate_limit:widget429Widget endpoint rate limit exceeded

Server Errors

CodeHTTP StatusDescription
internal_server_error:api500Unexpected server-side error

Handling Errors

Check the HTTP status code first

const response = await fetch("https://beta.illumichat.com/api/assistants", {
  credentials: "include",
});

if (!response.ok) {
  const { error, code } = await response.json();

  switch (response.status) {
    case 401:
      window.location.href = "/login";
      break;
    case 403:
      showError("You don't have access to this resource.");
      break;
    case 429:
      await delay(getBackoffMs(retryCount));
      break;
    default:
      console.error(`API error [${code}]: ${error}`);
      showError(error);
  }
}

Use the code field for programmatic handling

The code field is a stable identifier you can match against, while the error message may change.
if (code === "not_found:chat") {
  router.push("/chats");
} else if (code === "forbidden:api") {
  showUpgradePrompt();
}

Handle 429s with exponential backoff

function getBackoffMs(retryCount) {
  return Math.min(1000 * Math.pow(2, retryCount), 30000);
}
Log the full error response (including code and details) to make debugging easier during development.