JavaScript SDK
Validate emails and look up companies from Node.js, Next.js, Workers or Bun with the leadmagic package.
leadmagic is the official JavaScript and TypeScript SDK. It runs on your server and reads your key from LEADMAGIC_API_KEY. It is written in TypeScript and its types are in the package, so there is no @types package to install.
| Import | Use it for |
|---|---|
leadmagic | validateEmail, findCompany, getCredits from any server runtime: Node.js 20+, Bun, Deno, Cloudflare Workers, Vercel Functions |
leadmagic/next | A Route Handler that validates emails for your forms |
leadmagic/react | useEmailValidation, a headless hook for email fields |
Validate an email
data holds the full Email Validation response with the API's field names, plus verdict. A valid or invalid result costs 0.25 credits. unknown is free.
Look up a company
One credit when a company is found, nothing when it is not.
Results, not exceptions
Every call returns { data, error, meta }. API and network failures come back in error, so you never wrap calls in try. The SDK throws only when it is set up wrong, such as a missing key. See Errors.
meta carries requestId, credits.consumed, credits.remaining and rate-limit numbers from the response headers.
TypeScript
Checking error narrows data, so TypeScript knows the response shape without casts:
Every response, option and error code is exported as a type. error.code autocompletes the codes the API documents and still accepts codes added later. See Types.
Configure a client
The top-level functions use LEADMAGIC_API_KEY. Create a client when you need different settings:
All options are listed in the reference.
Next steps
Validate emails in Next.js forms
Route handler, React hook and a ready-made field.
Create an API key
Scope it to email validation for forms.
Try it without a key
Synthetic data, no credits.
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.