SDK errors
How the leadmagic SDK reports failures: six kinds to branch on, stable codes from the API, and what to do about each.
API and network failures come back in error. Branch on error.kind; use error.code when you need the detail.
Kinds
kind | Means | What to do |
|---|---|---|
config | Missing or malformed key, key in a public env var, key used in a browser, or a base URL that is not https | Fix the setup. These throw instead of returning |
auth | Key invalid, revoked, outside its scopes, or blocked by its IP allowlist | Check the key in Settings → API Keys |
billing | Out of credits, credits frozen, no plan, or a spending limit reached | Add credits or raise the limit |
rate_limit | Too many requests | Wait retryAfter seconds |
invalid_input | Not an email address, missing field, unknown resource | Fix the request. Not billed |
unavailable | Timeout, network failure, or a LeadMagic outage | Retry later. error.retryable is true |
Fields
| Field | |
|---|---|
code | Stable code from the API, such as insufficient_credits, or an SDK code below |
kind | One of the six kinds |
status | HTTP status, or 0 when no response arrived |
message | What went wrong |
reason | Extra detail, such as api_key_scope or plan_entitlement |
param | Request fields the API rejected |
requestId | Quote this to support |
retryAfter | Seconds to wait, from Retry-After |
action | The API's suggested next step |
retryable | true for rate_limit and unavailable |
The API's full code list is in Errors.
SDK codes
code | kind |
|---|---|
missing_api_key | config |
public_api_key | config |
malformed_api_key | config |
insecure_base_url | config |
browser_runtime | config |
invalid_input | invalid_input |
timeout | unavailable |
network_error | unavailable |
unexpected_response | unavailable |
Retries
The SDK retries 429, 502, 503, 504 and network errors up to twice. It waits for Retry-After when the API sends one, uses the same idempotency key for every attempt, and stops when the next wait would pass timeoutMs.
Get your LeadMagic API key and test endpoints live.
Use your API key in the interactive REST playground. For the LeadMagic CLI, install the lm command and run lm login; hosted MCP clients also sign in with OAuth.
Was this page helpful?
We value your feedback.