What is an API key? Explained with a key to a supplier's stockroom
An API key is a secret code that lets your software use another company's service, with the usage billed to your account. Explained with a key to a supplier's stockroom that anyone holding it can open.
- Author
Umair Mateen- Published
- Reading time
- 5 min
- Category
- Engineering
Today’s news about LangChain’s Tool Gateway is about a common habit: API keys copied into the settings of every AI agent that needs a tool.
In one sentence: An API key is a secret code that lets your software use another company’s service, such as an AI model or a maps service, with the usage charged to your account, and anyone who holds a copy can use it the same way.
The everyday picture
Imagine your business has an account with a wholesale supplier. The supplier gives you a key to their stockroom. Your staff can walk in, take what they need, and the supplier adds it to your monthly bill.
The supplier does not check faces at the door. It only checks the key. So if someone copies your key, they can walk in too, and you pay for what they take.
That is why careful businesses keep the key in a locked cabinet, give separate keys to separate teams, change the locks now and then, and read the bill closely.
Your app takes the key from a locked cabinet, uses it to open the supplier's stockroom, and every use is charged to your account. Whoever holds the key gets the same access.
How it works, step by step
- You create the key (the supplier cuts you a key) in the provider’s dashboard, linked to your account or project.
- You store it in a secrets manager (the locked key cabinet), a service that keeps passwords and keys hidden and records who reads them.
- Your server adds the key to each request (a staff member carries the key to the stockroom). It goes with the request to the provider’s API, the doorway other software uses to ask for a service.
- The provider checks the key (the door opens for that key) and runs the request. It does not know who is holding the key, only that the key is valid.
- The usage is charged to your account (the item goes on your bill). Restrictions you set on the key, such as which services it may open, limit what it can be used for.
Try it · Spot the weak point
Where is this key most likely to be stolen?
A small team added an AI writing feature to its website. Tap the part where the API key is most exposed.
Where the picture stops
- A real key is hard to copy without you noticing. An API key is just text, and one copy-paste into the wrong place, like public code, a chat message or a screenshot, leaks it.
- Changing a lock is slow. Replacing an API key, called key rotation, takes minutes: create a new key, update your apps, then delete the old one.
- Some keys only identify your project, while others can read or change your data. The picture of one stockroom hides that range, so check what each key is allowed to do.
Why it matters for your business
- Cost: Google warns that publicly exposed API keys can lead to unexpected charges on your account. For AI services, a stolen key can mean someone else running large jobs on your bill.
- Data risk: The same Google guidance says an exposed key can give unauthorised access to your data, depending on what the key can reach.
- Less damage when things go wrong: Restricting each key to the services and apps that need it, and deleting keys nobody uses, limits what a thief can do.
- Faster response: Usage monitoring helps you spot someone else using your key before the bill arrives.
An example
Imagine a 15-person travel agency that adds an AI assistant to its booking website. The developer first pastes the AI provider’s key into the web page so the demo works. Before launch, they move it: the page now sends questions to the agency’s own server, which takes the key from a secrets manager and adds it. They restrict the key to the one AI service, set a monthly spending alert, and note a date to rotate it. When a staff member leaves, the agency already knows which keys exist and who can reach them.
Frequently asked questions
Is an API key the same as a password?
They are similar: both are secrets that grant access. But a password usually belongs to a person who logs in, while an API key is used by software, often with no person typing anything.
What should I do if an API key leaks?
Create a replacement, switch your apps to it, and delete the leaked key so it stops working. Then check the usage and bills for anything you did not do.
Can I put an API key in my website or mobile app?
Avoid it for any key that costs money or reaches data. Anything sent to a browser or phone can be read, so let your own server add the key instead.
How often should API keys be rotated?
Security guidance says to rotate keys regularly, so a stolen copy stops working sooner. It is also sensible to replace any key a departing staff member could see. There is no single right schedule.
Related explainers
Sources
Could you explain this to a colleague now?
Mark it and posts that mention it will show a tick. Saved in this browser only.