API keys and authentication

What your API key actually does, what the server says when it is missing or wrong, and the small set of habits that stop it from leaking into a browser bundle or a public repository.

Every call you made in the first two lessons carried a header you copied without much thought: x-api-key. Take it away and the server stops answering your questions. This lesson is about why, what each kind of rejection looks like, and how to handle a key so it never ends up somewhere it can be stolen.

What the key is for

A public website does not care who you are. An API usually does, for three reasons:

  • Billing. Calls cost money to serve. The key tells the server whose account to charge.
  • Limits. Your plan decides how many calls you can make per minute and per month. The key is how the server knows which plan applies.
  • Control. A key can be restricted, revoked or replaced. If something goes wrong, the owner can shut off one key without touching anything else.

An APIVerve key is a long random identifier in UUID format: groups of letters and digits separated by dashes. One key covers your whole account, so the same key that calls Number to Words also calls Email Validator, Country Lookup and everything else in the catalog. There is no separate signup per API.

The important property is that a key is a bearer credential. Whoever holds it can use it. The server has no way to tell you from someone who copied your key out of a screenshot, so the key deserves the same care as a password. Most of this lesson is about that.

Sending the key

You have already done this. The key goes in a request header named x-api-key:

curl 'https://api.apiverve.com/v1/[email protected]' \
  -H 'x-api-key: YOUR_API_KEY'
{
  "status": "ok",
  "error": null,
  "data": {
    "email": "[email protected]",
    "domain": "myspace.com",
    "username": "support",
    "isRegexValid": true,
    "isMxValid": true,
    "isValid": true,
    "isFreeEmail": false,
    "isCompanyEmail": true,
    "isDisposable": false,
    "isRoleAccount": true,
    "canReceiveMail": true
  }
}

(Trimmed. The full Email Validator response has more fields.) Run it yourself:

Try it liveEmail Validator20 credits
GEThttps://api.apiverve.com/v1/emailvalidator
curl "https://api.apiverve.com/v1/emailvalidator?email=support%40myspace.com" \
  -H "x-api-key: YOUR_API_KEY"
Sign in or create a free account to run this with your own key.

isRoleAccount is true because support@ is a shared role address, not a person.

A few details about the header that save time later:

  • Header names are case-insensitive. x-api-key, X-API-Key and X-Api-Key are the same header. Lowercase is the convention.
  • There is an alternative form. Some HTTP tools only let you set an Authorization header. APIVerve also accepts Authorization: Bearer YOUR_API_KEY, which resolves to the same account. Use one form or the other, not both.
  • Why a header and not the URL? URLs get written down everywhere: server logs, browser history, proxy logs, analytics tools, the address you paste into a chat. A key in a query string leaks into all of them. A header is still not secret from anyone who can see the request, but it is not recorded in nearly as many places by default.
Check yourself

Why is a header a better place for an API key than the query string?

Answer the check above to continue.

Run every example on your own key. Free plan, no card.

Scaling up?

Volume pricing, custom SLAs, and dedicated support for high-traffic teams.

Contact sales