API Keys
How to authenticate and identify yourself when using APIs
Just like some websites require you to login to see information, APIs also need to identify who is sending requests.
Why API Keys Exist
When you use an API:
- the API needs to know who you are
- the API uses a computer to process your request
- some AI models are very costly to run
Therefore, there is something called an API key.
What Is an API Key?
An API key is like a combination of an email and a password that identifies you as the user when you send a request.
When you send a request, you attach the API key to it.
How API Keys Are Used
Mostly, API keys are added to the website URL:
https://api.example.com/weather?api_key=YOUR_KEY_HEREThe ?api_key= parameter tells the API who is sending the message and wants to get a response.
Different Names
Sometimes API keys are called by different names:
api_keyapi_tokenToken
They all serve the same purpose: identifying the user.
Public and Private Keys
In some applications, there are two types of keys:
- Public keys: Can be shared, used for identification
- Private keys: Must be kept secret, used for authentication
This is like a 2-factor authentication system.
The public key says "this is my account." and lets you enter. The private key proves "I am really the owner of this account." and defines what you are allowed to do and lets you act on it.
When working with AI models, API keys help track usage and manage costs.