As soon as you move from clicking buttons to running software — a trading script, a portfolio tracker, a third-party tool — you meet API keys. They are the credentials that let a program talk to a service on your behalf. They are also one of the most common ways that accounts are exposed, usually not through sophisticated hacking but through a key pasted into the wrong place.
This guide explains what API keys are, how they differ from passwords, how permissions should be scoped, how to store, rotate and revoke them, and how to recognise when a key may have been compromised. The principles apply to any service that issues keys.
What an API is
An API (application programming interface) is a defined way for software to talk to a service. A trading platform's API might let a program request prices, read account balances or, on platforms that support it, place orders — the same things you do in the app, but automated.
Because a program cannot type a password and answer a two-factor prompt the way a person does, APIs usually authenticate requests with a key.
What an API key is
An API key is a long, random secret string issued by the service. When your program sends a request, it includes the key (often with a separate secret used to sign requests). The service checks the key and, if it is valid, performs the request with whatever permissions that key carries.
The crucial consequence: anyone who has the key can do whatever the key is allowed to do. The service cannot tell your script from a stranger's script using the same key.
API keys versus passwords
| Password | API key | |
|---|---|---|
| Used by | A person signing in | A program making requests |
| Typical form | Chosen by you; memorable | Generated by the service; long and random |
| Second factor | Usually combined with 2FA | Usually used alone, so must be guarded closely |
| Permissions | Full account access | Can often be limited to specific actions |
| Revocation | Changing it affects all your sign-ins | Each key can be revoked individually |
Because keys are typically used without a second factor, a leaked key can be more dangerous than a leaked password on an account protected by 2FA.
Permissions and scopes: the principle of least privilege
Many services let you limit what each key can do, often called scopes or permissions. Common categories on trading platforms include:
- Read-only: view prices, balances and history.
- Trade: place and cancel orders.
- Withdraw / transfer: move funds out of the account.
The rule is simple: give each key only the permissions it needs, and nothing more. A portfolio tracker needs read-only access. A trading script needs to trade but not to withdraw. Almost nothing you run yourself should need withdrawal rights, and no third party should ever have them.
Some services also let you restrict a key to specific IP addresses, so it only works from your own server. Where that is available, use it.
How services should store your keys
A well-designed service shows you a new key once, at the moment it is created, and stores only a one-way hash of it — so even the service's own database cannot reveal the original key. If you lose it, you create a new one rather than "recovering" it.
On RumiEX, keys are created with a label you choose, shown in full only once at creation, and stored as a hash; afterwards you can see only a short prefix to recognise each key, and you can revoke any key at any time from your account settings.
How you should store your keys
Never put keys in code
The most common leak is a key written directly into a script that is later shared, published or committed to a code repository. Automated tools continuously scan public repositories for exactly these strings.
Use environment variables or a secrets manager
Keep keys in an environment variable, a configuration file excluded from version control, or a dedicated secrets manager. Your code reads the key at runtime; the key never appears in the code itself.
Keep keys out of screenshots, chats and documents
Screenshots of terminals and configuration screens, copied error logs and messages to a helper are frequent accidental leaks. Check before you share.
Separate keys for separate purposes
Use a different key for each program or service. If one is compromised, you can revoke it without disrupting everything else, and you can tell which program a request came from.
Rotation and revocation
- Rotate periodically. Create a new key, switch your program to it, and revoke the old one. Regular rotation limits how long a silently leaked key remains useful.
- Revoke immediately when in doubt. If a key may have been exposed — a shared screen, a lost laptop, a former collaborator — revoke it. Creating a new one takes seconds.
- Remove keys you no longer use. Unused keys are risk with no benefit.
A checklist for every new key
Before creating any key, answer these questions:
- What exactly will use it? One program, one key.
- What is the minimum it needs to do? Read-only if possible.
- Where will it be stored? An environment variable or secrets manager — decided before the key exists.
- Who else could see it? Collaborators, logs, backups, screenshots.
- Can it be limited further? IP restrictions, expiry dates, usage limits, if the service offers them.
- When will it be rotated or removed? Put a reminder in your calendar.
- How will you notice misuse? Know where to check account activity.
Give the key a clear label — "balance-logger on home server, read-only" — so that months later you know exactly what it is and whether it can be safely revoked.
Common mistakes
- One key for everything. When it leaks, everything is exposed, and you cannot revoke it without breaking every tool at once.
- Full permissions "just in case". Unneeded permissions are pure risk.
- Keys committed to code repositories, including private ones that later become shared or public.
- Keys sent over chat or email to a collaborator or support agent. Legitimate support never needs your secret key.
- Forgotten keys for tools you stopped using years ago, still active.
- Assuming deletion of a file deletes the key. A key that was ever exposed must be revoked, not just removed from where you noticed it.
Signs a key may have been compromised
- Requests or activity in your account that you did not make.
- Orders or positions you don't recognise.
- Unexpected errors indicating a key has hit usage limits.
- The key appearing in a place it shouldn't — a public repository, a shared document, an error report.
If you see any of these, revoke the key first and investigate second.
API security from the service's side
Securing an API is a shared responsibility. The OWASP Foundation's API Security Top 10 lists the most common weaknesses in APIs, with broken object-level authorisation (one user being able to access another's data) and broken authentication at the top of the list. As a user you cannot fix a service's API, but you can prefer services that support scoped keys, show keys only once, store them hashed and let you revoke them individually — and you can limit the damage of any leak through least privilege.
Keys in shared and team setups
Keys get harder to control once more than one person or machine is involved.
- Give each person their own key where the service allows it, so access can be removed for one person without affecting others.
- Never share keys through chat or email. Use a shared secrets manager with access controls, or have each person generate their own.
- Revoke keys when someone leaves a project, even if you trust them — it is simply good practice.
- Keep keys out of shared logs. Programs sometimes print their configuration when they start or when they hit an error. Check that your logging never includes the key.
- Be careful with backups and cloud sync. A configuration file containing a key may be copied to backup drives and cloud folders you have long forgotten about.
The more places a key exists, the more places it can leak from.
Third-party tools and trading bots
Many traders connect third-party services — trackers, analytics tools, trading bots — to their accounts using API keys. Before doing so:
- Check who runs the service and whether it has a credible track record.
- Grant read-only access wherever that is enough.
- Never grant withdrawal permission to a third party.
- Be wary of promised returns. Bots and "copy-trading" services that guarantee profits are a common scam; the U.S. FTC states that only scammers guarantee profits or big returns. See crypto trading scams and risks.
- Revoke the key as soon as you stop using the service.
A worked example
A trader writes a script to log their account balance every hour and posts it on a coding forum to ask for help with a bug. They forget that the script contains their API key in plain text.
- If the key was read-only: an attacker can see balances and history — unpleasant, but no funds can move.
- If the key could trade: an attacker could place damaging trades.
- If the key could withdraw: funds could be stolen.
Had the key been stored in an environment variable, the posted script would have contained only the variable name. Had it been read-only, the leak would have been an inconvenience rather than a loss. Revoking the key the moment the mistake was noticed would have closed the door entirely.
API keys and your wider security
API keys are only one part of account security. They do not replace a strong, unique password and two-factor authentication on the account itself — see how to secure your trading account. And any automated program using keys should have the safeguards described in algorithmic trading for beginners: loss limits, order caps and a way to stop it instantly.
Key takeaways
- An API key lets a program act on your account; anyone holding it can do whatever it permits.
- Give each key the minimum permissions it needs — never withdrawal rights for third parties.
- Store keys in environment variables or a secrets manager, never in code, screenshots or chats.
- Use separate keys per purpose, rotate them periodically and revoke them immediately when in doubt.
- Watch for unexplained activity, and treat services promising guaranteed returns for your keys as scams.
This completes the Technology series. Continue with the Psychology series, or explore the RumiEX platform.
Frequently asked questions
What is an API key?
An API key is a long secret string that identifies and authenticates a program, rather than a person, when it connects to a service's application programming interface (API). Anyone who has the key can act with whatever permissions the key carries.
Is an API key the same as a password?
They are similar in that both are secrets, but an API key is meant for software, is usually much longer and random, often carries limited permissions, and can be revoked individually without changing your account password.
Where should I store an API key?
In a dedicated secrets store or, at minimum, an environment variable or configuration file kept outside your code and excluded from version control. Never paste a key into source code, screenshots, chat messages or shared documents.
Should I give my API key to a trading bot service?
Only if you fully trust the service, and only with the minimum permissions it needs. Never give a key with withdrawal permissions to a third party. Services that promise guaranteed returns in exchange for your keys are a common scam.
What should I do if my API key is leaked?
Revoke it immediately from your account settings, create a new one if you still need it, and check your account activity for anything you did not do. Then find out how it leaked so it doesn't happen again.
Sources and further reading
Written and reviewed by the RumiEX Editorial Team. This article is for education only and is not financial, investment or tax advice. Read our editorial standards.