Keeping your key safe
How the leadmagic SDK keeps API keys out of browsers and limits what a public form route can spend.
An API key in browser code can be copied and used by anyone. The SDK is built so that does not happen by accident.
What the SDK enforces
- Server only. With a key, the SDK throws
browser_runtimein a browser. - No public env vars. It refuses to run outside production when
NEXT_PUBLIC_LEADMAGIC_API_KEY,VITE_LEADMAGIC_API_KEYor a similar variable is set, and warns in production. - Never logged. Error messages and logs never include the key.
- HTTPS only. The key is sent over
https. A plainhttpbase URL throwsinsecure_base_url, except on localhost. - No redirects. A request that carries the key never follows a redirect, so the key cannot be forwarded to another host.
What the form route enforces
The route from leadmagic/next is public, so it is limited by default:
- Same-origin JSON requests only, with a 2 kB body limit.
- Email validation only. Company lookup is never exposed.
- Returns
{ verdict, roleBased }. Company and mail server details stay on your server. - Caches answers per address.
- Caps the checks that reach LeadMagic: 10 a minute per visitor IP and 120 a minute in total, on each server instance. Over a cap it answers
unknownand spends nothing. Change the caps withrateLimit.
The caps are counted in memory, so separate server instances do not share them. Add protect for bot detection or a rate limiter backed by a shared store.
What you should do
- Use a scoped key. In Settings → API Keys, create a key for your website and allow Email Validation only.
- Restrict it by IP when your server has fixed outbound addresses.
- Rotate it if it was ever committed or bundled.
The package
- No runtime dependencies and no install scripts.
- Published from GitHub Actions with npm provenance, so each version links to the commit that built it. Check it with
npm audit signatures. - Report a security problem through the security policy.
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.