Skip to main content
LeadMagic is built with developers in mind. Every response includes rich metadata, standardized headers, and detailed error messages to make debugging and monitoring effortless.

Why We Build This Way

Our Philosophy: APIs should be predictable, transparent, and never surprise you. Every decision in our API design prioritizes developer happiness and operational confidence.

Design Principles

Standards-First

We follow RFC 9457 for errors, IETF draft-ietf-httpapi-ratelimit-headers for rate limits, and RFC 7807 patterns throughout. No proprietary formats to learn.

Observable by Default

Every response includes 15+ headers giving you complete visibility into credits, rate limits, concurrency, and usage - without extra API calls.

Graceful Degradation

Soft-mode rate limiting, automatic retries, and fallback mechanisms mean our limits guide you rather than break you.

Context-Rich Errors

Errors include actionable suggestions, documentation links, and machine-readable context so you can handle them programmatically.

Why Response Headers Matter

Traditional APIs force you to make extra calls to check your balance or limits. LeadMagic embeds everything in response headers:
Every response includes:
  • Your remaining credits (X-Credits-Remaining)
  • Rate limit status (RateLimit-Remaining, RateLimit-Reset)
  • Daily quota (X-RateLimit-Remaining-Daily)
  • Usage percentages (X-RateLimit-Daily-Usage-Percent)
  • Soft mode status (X-RateLimit-Soft-Mode)
This means you can build dashboards, set up alerts, and implement smart rate limiting without polling separate endpoints.

Response Headers

Every API response includes comprehensive headers for monitoring, debugging, and rate limit management.
Following the IETF draft-ietf-httpapi-ratelimit-headers standard:

Legacy X- Headers (Backwards Compatible)

Daily Limit Headers

Complete Header Reference

Here’s a real-world example showing all headers in a typical response:
Pro Tip: Log these headers after every request. When debugging issues, you’ll have complete visibility into your API state at that exact moment.

Request Headers

Required Headers

Case-Insensitive Authentication: The X-API-Key header accepts any case variation: X-API-Key, X-API-KEY, x-api-key all work identically.

Optional Headers


Success Messages

Every endpoint returns a human-readable message field that tells you exactly what happened. These are designed to be user-friendly and can be displayed directly in your UI.
Why Messages Matter: These aren’t just for humans - they’re also machine-readable. Check the message field to determine success vs. not-found scenarios, especially when credits_consumed might still be > 0 for verified “not found” results.

Analytics Endpoints

Monitor your API usage programmatically with our comprehensive analytics suite.
All analytics endpoints are FREE - they don’t consume any credits and are exempt from rate limiting.

Dashboard Overview

Get a real-time snapshot of your account status:
Response:

Available Analytics Endpoints

GET /v1/analytics/dashboard

Real-time dashboard with credits, rate limits, and usage stats for today, this week, and this month.

GET /v1/analytics/usage

Daily usage summary with total requests, credits consumed, and chargeable rates.Query params: ?days=30 (1-90)

GET /v1/analytics/products

Per-product breakdown showing requests, credits, success rates, and average costs.Query params: ?days=30 (1-90)

GET /v1/analytics/credits

Credit consumption history with daily breakdown and chargeable request analysis.Query params: ?days=30 (1-90)

GET /v1/analytics/summary

All-time statistics including total requests, credits consumed, success rates, and first/last request timestamps.Query params: ?start_date=YYYY-MM-DD&end_date=YYYY-MM-DD

GET /v1/analytics/daily

Detailed daily metrics with latency percentiles, error rates, and performance data.Query params: ?days=30 (1-90)

GET /v1/analytics/day/:date

Per-product breakdown for a specific day. Top 15 products plus aggregated “other” category.Path param: :date in YYYY-MM-DD format

Usage Example: Daily Breakdown

Response:

Credits Endpoints

Check Your Balance

Response:

Additional Credits Endpoints

Error Handling

LeadMagic follows RFC 9457 Problem Details for standardized, machine-readable error responses.

Error Response Format

Response Fields Explained

HTTP Status Codes

200

Success - Request completed

400

Bad Request - Invalid input

401

Unauthorized - Invalid API key

402

Payment Required - Low credits

429

Too Many Requests - Rate limited

500

Server Error - Our fault

Error Types

HTTP 401 - Unauthorized

Idempotency

Every request can include a unique identifier for tracking and debugging:
The X-Request-ID is returned in error responses and logged for debugging:

Graceful Degradation

LeadMagic is designed to handle failures gracefully:
High Availability: Our Durable Objects provide sub-millisecond rate limiting with automatic failover to PostgreSQL when needed.

Best Practices

When you receive a 429 error, use the Retry-After header:
Build proactive monitoring using response headers:
Always include a request ID for easier debugging:
Don’t call /v1/credits before every request. Cache and refresh periodically:

SDK Support

While we don’t have official SDKs yet, our REST API works seamlessly with any HTTP client:

Node.js

Use native fetch or axios for HTTP requests.

Python

Use requests or httpx for async support.

Any Language

Any HTTP client works - just send JSON with your API key.

Why We Built It This Way

Traditional APIs return cryptic errors like {"error": "Bad request"}. This leaves developers guessing what went wrong and how to fix it.Our approach: Every error follows RFC 9457 Problem Details, a standard designed by the IETF specifically for HTTP API errors. This means:
  • type: A URI identifying the error type (bookmarkable, consistent)
  • title: Human-readable summary you can show users
  • status: HTTP status code (redundant but useful)
  • detail: Specific explanation of what went wrong
  • action: Suggested fix (unique to LeadMagic)
  • docs: Link to relevant documentation
  • context: Machine-readable details (credits needed, rate limits, etc.)
This isn’t just for show - your code can programmatically handle errors based on type while showing users the title and action.
We implement the IETF draft-ietf-httpapi-ratelimit-headers standard for rate limit headers:
Why this matters:
  • These headers are on track to become an official standard
  • Libraries already support them (many HTTP clients auto-parse)
  • Consistent across all modern APIs that implement the spec
  • No need to learn LeadMagic-specific header names
We also include legacy X-RateLimit-* headers for backwards compatibility.
Most APIs hard-block you when you hit limits. This causes:
  • Unexpected failures in production
  • Data loss if you’re mid-batch
  • Frustrated developers
Our approach: Soft mode warns but doesn’t block. When you exceed limits, we:
  1. Log the violation
  2. Set X-RateLimit-Soft-Exceeded: true
  3. Still process your request
This gives you time to fix your implementation without breaking production. Watch for the header in logs and fix before we have to enforce limits.
Checking your balance shouldn’t require extra API calls. Every enrichment response includes:
Benefits:
  • Build credit alerts without polling
  • Log spend per-request for cost attribution
  • Pause automatically when credits run low
  • Never wonder “how much did that cost?”
Our message field isn’t just “success” - it tells you what actually happened:
  • "Email is valid." - Great, use it!
  • "Email is invalid." - Do not email
  • "Unable to determine email validity." - Unknown result (free)
This lets you:
  • Display messages directly to end users
  • Make programmatic decisions based on outcomes
  • Distinguish between “not found” and “error”
All analytics endpoints are FREE - no credits consumed, no rate limits. This means you can:
  • Poll /v1/analytics/dashboard every minute
  • Build real-time dashboards
  • Set up alerting without worrying about cost
  • Audit your usage as often as needed
We want you to have complete visibility into your API usage.

Next Steps

Authentication

Deep dive into API key management and security best practices.

Credits Guide

Understand credit costs, billing, and optimization strategies.

API Reference

Explore all available endpoints in the interactive playground.

Integrations

Connect LeadMagic with Clay, Make, Zapier, and more.