Skip to main content
The Leonar API uses standard HTTP status codes and returns structured error responses.

Error format

{
  "error": {
    "code": "validation_error",
    "message": "email: Invalid email format"
  }
}

Error codes

CodeHTTP statusDescription
validation_error400Invalid request data
invalid_api_key401Missing or invalid API key
insufficient_credits402The workspace does not have enough credits to cover this request. Returned by POST /sourcing/advanced/profiles/search when the sourcing credit balance is empty.
insufficient_scope403API key lacks the required scope
billing_required403No active subscription on the workspace
plan_upgrade_required403The current plan does not include this feature
not_found404Resource not found
rate_limit_exceeded429Too many requests
internal_error500Server error

insufficient_credits payload

When credits are missing, the response includes an error.details object describing the credit type and the gap:
{
  "error": {
    "code": "insufficient_credits",
    "message": "Insufficient sourcing credits to cover the returned profiles",
    "details": {
      "credit_type": "sourcing",
      "available": 0,
      "required": 1
    }
  }
}

Handling errors

const response = await fetch(`${BASE_URL}/contacts`, {
  headers: { Authorization: `Bearer ${apiKey}` },
});

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

  switch (error.code) {
    case "invalid_api_key":
      throw new Error("Check your API key");
    case "rate_limit_exceeded":
      // Wait and retry
      break;
    case "validation_error":
      console.error("Validation:", error.message);
      break;
    default:
      throw new Error(error.message);
  }
}

const { data } = await response.json();