What is an API key?
Definition
An API key is a secret string that lets a script or app act on your account without your password. Treat it like a password: keep it out of public code, and delete it when you no longer need it.
Also called: API token, Secret key, Developer key
How does an API key work?
You create the key in the service's dashboard, and your code sends it with every request. Most services expect it in a header, often as Authorization: Bearer followed by the key. The server looks the key up, finds the account it belongs to and runs the request as that account.
Anything done with the key counts as you: uploads use your plan and show up in your account. Unlike a signed URL, which opens one file for a short time, a key acts on your whole account until you delete it. Careful services store only a one-way hash of each key, so they show it to you once and never again.
How do you keep an API key safe?
Keep it where only your code can read it. The most common leak is a key pasted into source code and pushed to a public repository, where anyone can find it.
- Store it in an environment variable or a secret manager.
- Never put it in a URL, a chat message or JavaScript that runs in the browser.
- Use one key per tool or machine, named after where it lives.
- Give each AI tool its own key, so one MCP server connection can be cut off without touching the rest.
- Delete a key the moment you think it leaked, then make a new one.
What is the difference between an API key and OAuth?
An API key is one secret you copy by hand, and OAuth is a sign-in flow that hands an app a limited token for you. A key suits your own scripts and developer tools, where you control the machine. OAuth suits apps used by many people, such as an AI assistant, because nobody copies a secret and you approve access on a page you trust.
Both can be revoked. A key usually works until you delete it, while an OAuth token tends to expire soon and renew in the background.
| Who uses it | How long it lasts | How you stop it | |
|---|---|---|---|
| Password | A person signing in | Until you change it | Change the password |
| API key | Your own code or tools | Until you delete it | Delete the key |
| OAuth token | An app you approved | A short time, renewed in the background | Disconnect the app |
API key: common questions
What happens if my API key leaks?
Anyone who has it can act on your account within what the key allows. Delete it right away, which stops it for every request, then create a new one and update your tools.
Can I see my API key again after I create it?
Usually not. Many services store only a hash of the key, so they can check it but can't show it again. If you lose it, delete it and make a new one.
Is it safe to put an API key in front-end JavaScript?
No. Anything sent to a browser can be read by anyone who opens the page. Keep the key on a server or in a tool that runs on your own machine.
Why use an API key instead of my password?
A key can be named, limited and deleted on its own, without changing your password or signing you out anywhere. It also keeps your password out of scripts and config files.
How many API keys should I have?
One per tool or machine is a good rule. Then you can delete a key that leaked without breaking everything else that uses the service.
Related terms
- OAuthOAuth is the standard behind "Sign in with..." and "Allow this app" screens. An app gets a limited token to act for you, you never hand it your password, and you can revoke the token later.
- MCP serverAn MCP server is a service that speaks the Model Context Protocol, an open standard that lets AI assistants like Claude or ChatGPT use outside tools. Connect a file host's MCP server and the assistant can publish a file and hand you the link.
- Signed URLA signed URL is a temporary address for a stored file with a cryptographic signature and an expiry time built in. It lets a browser fetch one specific file for a few minutes, so the storage itself never needs to be public.
- Link analyticsLink analytics is the record of what happened after you shared a link: how many opens, when, from which country and device, how long people stayed and how far they read. Good analytics leave out bots and link-preview fetches.
Go deeper
Updated