API Directory โ€บ Guides โ€บ What Is an API Key? (And How to Keep It Safe)

What Is an API Key? (And How to Keep It Safe)

An API key is a secret that identifies your app to an API. Here's what it does, why APIs use them, and how not to leak yours.

An API key is a secret string — often something like sk_live_8f3b91c0a4e7 — that you send with every request to identify your application to an API. It answers the service’s first two questions: who is calling? and are they allowed to?

What the key is for

How you send it

There is no single standard. Read each API’s auth docs for the exact method:

Query parameter?api_key=YOUR_KEY — simplest, but the key ends up in server logs and browser history. Common on read-only data APIs.
Custom headerX-API-Key: YOUR_KEY or apikey: YOUR_KEY — keeps the key out of the URL.
Authorization headerAuthorization: Bearer YOUR_KEY — the most common modern style, shared with OAuth tokens.
Basic authThe key as the username (empty password), base64-encoded in Authorization: Basic.
# the same request, key in a header (preferred)
curl https://api.example.com/v1/data \
  -H "Authorization: Bearer $API_KEY"

# key in the query string (avoid if you can)
curl "https://api.example.com/v1/data?api_key=$API_KEY"

API key vs. token vs. OAuth

Keeping your key safe

Common errors

FAQ

Is an API key a password?

It plays a similar role — a secret that grants access — but it identifies an application or project rather than a person, and it is designed to be used programmatically and rotated easily.

Can I use an API key in front-end code?

Only if the key is meant to be public (some map and analytics keys are, and are locked to specific domains). For anything secret, call the API from your backend so the key never reaches the browser.

What do I do if my key leaks?

Revoke or rotate it in the provider’s dashboard immediately, then update your app with the new key. Check usage logs for unexpected activity.

Why does my brand-new key return 401?

Besides typos and whitespace, some APIs (e.g. OpenWeatherMap) need time to propagate a new key — wait and retry before assuming it is broken.

Keep going

Try it on a real API

Browse all 196 free APIs โ†’

๐Ÿ”Œ Explore free public APIs

Hundreds of free APIs, searchable by category, with auth & CORS at a glance.

Browse the directory โ†’