Reference

Error Reference

All HyperSearchX API errors follow a consistent JSON format with machine-readable error codes, human-readable messages, and a unique request ID for support.

Error format

json
{
  "error": {
    "code": "invalid_request",
    "message": "Human-readable description of what went wrong.",
    "field": "query",
    "request_id": "req_01j8xk3m7p4qr5st6uv7wx8yz"
  }
}
FieldTypeDescription
codestringMachine-readable error identifier
messagestringHuman-readable explanation
fieldstring?Request field that caused the error (validation errors)
request_idstringUnique ID — include when contacting support

HTTP status codes

StatusMeaning
200Success
400Bad request — validation error in request body
401Unauthorized — missing or invalid API key
403Forbidden — key lacks required scope
404Not found — endpoint does not exist
422Unprocessable — request parsed but semantically invalid
429Rate limited — per-minute or monthly quota exceeded
500Internal server error
503Service unavailable — upstream dependency down

Error codes

Authentication errors (401)

CodeCause
missing_authNo Authorization header provided
invalid_authAuthorization header is not a Bearer token
invalid_keyAPI key not found or has been revoked
expired_keyAPI key has passed its expiration date

Authorization errors (403)

CodeCause
insufficient_scopeKey does not have permission for this endpoint

Validation errors (400)

CodeCause
invalid_requestRequest body validation failed (see field)
query_too_longQuery exceeds 500 characters
invalid_tierUnknown tier value (must be key_facts, summary, detailed, complete)
invalid_budgettoken_budget out of range (100–10,000 for search)
invalid_sourcesmax_sources out of range (1–20)
invalid_urlProvided URL is not valid or not accessible
payload_too_largeRequest body exceeds 1 MB limit

Rate limit errors (429)

CodeCause
rate_limitedPer-minute limit exceeded; wait Retry-After seconds
quota_exceededMonthly quota exhausted; upgrade plan or wait for reset

Server errors (500 / 503)

CodeCause
internal_errorUnexpected server error; please retry
upstream_errorA search backend returned an error; results may be partial
timeoutRequest exceeded the 60-second processing limit
service_unavailableCritical dependency is down; check status page

Example error handling

error-handling.ts
interface HsxError {
  code: string;
  message: string;
  field?: string;
  request_id: string;
}

async function search(query: string) {
  const res = await fetch("https://api.hypersearchx.zuhabul.com/v1/search", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.HSX_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ query, tier: "summary" }),
  });

  if (!res.ok) {
    const body = await res.json();
    const err: HsxError = body.error;

    switch (err.code) {
      case "rate_limited": {
        const retryAfter = parseInt(res.headers.get("Retry-After") ?? "60", 10);
        throw new Error(`Rate limited. Retry after ${retryAfter}s`);
      }
      case "quota_exceeded":
        throw new Error("Monthly quota exhausted. Please upgrade your plan.");
      case "invalid_key":
        throw new Error("Invalid API key. Check HSX_API_KEY.");
      default:
        throw new Error(`API error [${err.code}]: ${err.message} (req: ${err.request_id})`);
    }
  }

  return res.json();
}