What Is an API Key? The Basics Every Developer Needs
An API key is a unique string of characters that identifies and authenticates whoever is calling an API. When you send a request to a service, you attach the key — usually in an HTTP header — and the server checks it to decide whether to process the request, who's making it, and what they're allowed to do.
That's the short answer. The longer answer is that an API key does two jobs at once: authentication (proving who you are) and often authorization (defining what you're allowed to access). It's the digital equivalent of a badge you swipe before entering a building — the badge doesn't prove you're trustworthy, it just proves you're the person the system already knows about, and it lets the system log what you did while you were inside.
How an API key actually works
Most APIs expect the key to travel with every request, typically as a header:
curl https://api.example.com/v1/data \
-H "Authorization: Bearer YOUR_API_KEY"
Some older or simpler APIs pass the key as a query parameter (?api_key=xxxx), but that's less common now because query strings tend to end up in logs, browser history, and proxy caches — all places you don't want a secret credential to live.
When the request arrives, the server does roughly this:
- Looks up the key in its database.
- Confirms it's valid and not revoked or expired.
- Checks what permissions, rate limits, or plan tier are attached to it.
- Processes the request and, usually, logs the usage against that key.
That last point matters more than people expect. API keys aren't just gatekeepers — they're also the unit of accounting. Billing, rate limiting, and usage dashboards almost always key off the API key, not the human account.
API key vs. other credentials
It's worth distinguishing an API key from a few similar-sounding things:
- Password: tied to a human login session, meant to be typed by a person, often paired with 2FA.
- OAuth token: short-lived, scoped, usually issued after a user consents to an app accessing their data on their behalf.
- API key: usually long-lived, tied to an application or project rather than a person, and simpler to implement than OAuth.
API keys trade some security nuance for simplicity. There's no login flow, no token refresh dance — you generate a key once and use it in every request until you rotate or revoke it. That's exactly why they're the default choice for server-to-server integrations, internal tools, and anything where a human isn't sitting in a browser approving access.
Why services use API keys instead of just usernames
If you're building or integrating with an API, you'll notice almost none of them ask for a username and password on every request. There are practical reasons for that:
- Statelessness: keys don't require session management on the server.
- Granularity: you can issue multiple keys per account, each scoped to a different app, environment, or team member, and revoke one without touching the others.
- Traceability: if something goes wrong — a bug spamming requests, a leaked credential — you can identify exactly which key caused it and kill it without locking out the whole account.
- Billing: usage-based pricing is far easier to meter per key than per login session.
This is the same pattern used by SubToAPI. Instead of one shared credential, every project gets its own application key in the format sub_live_..., generated from the dashboard. That key is what your code sends to https://api.subtoapi.app/v1/messages — it's what ties usage, rate limits, and billing back to that specific application, separate from any other project on the same team.
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-3-5-sonnet",
"max_tokens": 512,
"messages": [{"role": "user", "content": "Explain API keys in one sentence."}]
}'
Where to keep your API key
Since a key is a bearer credential — anyone holding it can use it — how you store it matters as much as understanding what it is:
- Never commit keys to source control. Add
.envfiles to.gitignorefrom day one. - Load them from environment variables in your application, not hardcoded strings.
- Use separate keys for development, staging, and production so a leaked dev key doesn't touch production data.
- Rotate keys periodically, and immediately if one is ever exposed (pushed to a public repo, logged accidentally, pasted in a support ticket).
- Give each team member or service their own key rather than sharing one, so you know exactly who or what generated a given request.
Most API providers, including SubToAPI, let you generate and revoke keys per project or per team seat from a dashboard — check the docs for the specific setup at /docs/quickstart.
A quick mental model
If you remember nothing else: an API key is a password for software instead of for a person. It doesn't need to be memorable, it's generated rather than chosen, and it's meant to be attached to every single request an application makes, silently, in the background, so the server always knows who's calling and can respond accordingly — whether that means serving data, applying a rate limit, or rejecting the request outright.
questions
Is an API key the same as a password? No. A password authenticates a human during a login session; an API key authenticates an application or script on every request, without a login flow. Keys are typically longer, randomly generated, and not meant to be typed by a person.
Can I use the same API key in multiple apps? Technically yes, but it's not recommended. Sharing one key across apps means you lose the ability to track, rate-limit, or revoke access per application — if one app misbehaves or leaks the key, you have to rotate it everywhere at once.
What happens if my API key is exposed publicly? Treat it as compromised immediately: revoke or rotate it from the provider's dashboard, check usage logs for unexpected activity, and issue a new key. Most providers, including SubToAPI, let you regenerate keys instantly from account settings without downtime if you swap the new key into your app right away.