Clay logo

LeadMagic has made more than one billion API calls with Clay and won The Unstoppable Wheel award.

Recap
LeadMagicDocs

SDK reference

Functions, options and TypeScript types in the leadmagic SDK.

createClient(options?)

OptionDefault
apiKeyLEADMAGIC_API_KEYServer-side only
sandboxLEADMAGIC_SANDBOX=1Synthetic data, no key, no credits
baseUrlhttps://api.leadmagic.ioOr LEADMAGIC_BASE_URL. Must be https
timeoutMs10000Per call, retries included
maxRetries2For 429, 502, 503, 504 and network errors
fetchglobal fetchFor tests or proxies
headers{}Sent with every request

Throws a config error when the key is missing or exposed. The top-level validateEmail, findCompany and getCredits use the same defaults.

validateEmail(email, options?)

POST /v1/people/email-validation. Returns Result<EmailValidation>.

Option
verificationPolicy"legacy" (default) or "strict". Strict reports policy-only rejections as unknown, which is free
includeExtendedInfoAdds extended_info
includeVerificationDetailsAdds verification

EmailValidation is the API response plus verdict:

email_statusverdictCredits
validdeliverable0.25
invalidundeliverable0.25
unknownunknown0

Input that is not an email address returns an invalid_input error without a request.

findCompany(input, options?)

POST /v3/companies/search. Pass domain, name or linkedinUrl; domain is the most precise. Returns Result<CompanyLookup>:

Company types the common fields and keeps every other field the API returns.

getCredits(options?)

GET /v1/credits. Free. Returns { available, frozen, raw }.

Per-call options

Every method accepts:

Option
timeoutMsOverrides the client's timeout
maxRetriesOverrides the client's retries
signalAn AbortSignal
idempotencyKeyReused across retries; generated when omitted
sandboxOutcomeSandbox only: found, empty, 400, 401, 402, 404, 429, 500

Result<T>

leadmagic/next

createValidateEmailHandler(options?) returns a POST Route Handler. Options are on Validate emails in Next.js forms.

leadmagic/react

useEmailValidation(options?)

Every option is optional.

OptionDefault
endpoint/api/leadmagic/validate-emailYour route, wherever you mounted it
validateOn"blur""blur", "change" (debounced) or "manual" (only validate())
debounceMs600Wait after the last keystroke with "change"
enabledtruefalse stops the field checking by itself; validate() still works
staleTime600000How long an answer is reused for the same address
retry0Extra attempts after a failed check
retryDelaydoubles from 1000 to 8000A number of ms, or (attempt) => ms
timeoutMsnoneGive up on the request after this long
headersnoneAn object, or a function that returns one for each request
fetchglobal fetchCustom fetch for the built-in request
queryFnnone(email, { signal }) => Promise<{ verdict, roleBased? }>. Replaces the request
shouldValidatenone(email) => boolean. false skips the check; it reads as unknown
onSuccessnone(result) => void
onErrornone(error, email) => void
onSettlednone(result, error, email) => void

Returns:

Field
statusidle, checking, deliverable, undeliverable or unknown
data{ email, verdict, roleBased }, or undefined before an answer
errorWhy the last check failed, or null
isChecking, isDeliverable, isUndeliverable, isUnknownBooleans for status
roleBasedThe address is a shared mailbox such as info@
validate(value)Checks now and resolves to the verdict. Never rejects
reset()Back to idle
inputPropsSpread onto your <input type="email">

A failed check never blocks the form: status becomes unknown and error says why. A refusal from your route, such as 403, is not retried.

LeadMagicProvider

Sets options once for every useEmailValidation below it: endpoint, headers, fetch, queryFn, staleTime, retry, retryDelay, timeoutMs, validateOn and debounceMs. Options passed to a hook override it. Fields under one provider share answers, so an address is asked about once even when two fields check it together.

checkEmail(email, options?)

The request the hook makes, as a plain function for any framework. Takes endpoint, headers, fetch, timeoutMs and signal. Resolves to { email, verdict, roleBased } and rejects with an EmailCheckError (with the route's status) when there is no verdict.

emailValidationQueryOptions(email, options?)

Returns { queryKey, queryFn, enabled, staleTime } for TanStack Query. enabled is false until the text looks like an address.

Types

The package ships its own type declarations. Import types with import type:

ImportTypes
leadmagicResults: ValidateEmailResult, FindCompanyResult, GetCreditsResult, Result<T>, ResponseMeta, RateLimitInfo
Data: EmailValidation, EmailStatus, EmailVerdict, EmailCompanyLocation, CompanyLookup, Company, Credits
Inputs: LeadMagicOptions, LeadMagicClient, RequestOptions, ValidateEmailOptions, FindCompanyInput, SandboxOutcome
Errors: LeadMagicError (a class), LeadMagicErrorKind, LeadMagicErrorCode, LeadMagicApiErrorCode, LeadMagicClientErrorCode
leadmagic/nextValidateEmailHandlerOptions, ValidateEmailResponse, ValidateEmailEvent, ProtectResult
leadmagic/reactUseEmailValidation, UseEmailValidationOptions, EmailFieldStatus, EmailInputProps, EmailVerdict, EmailValidationResult, EmailCheckError (a class), CheckEmailOptions, EmailValidationQueryOptions, LeadMagicProviderProps, EmailValidationDefaults, RequestHeaders
API key for REST · OAuth for LeadMagic CLI and MCP

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.