Knowledge base

Detection scenarios

How do I detect the theft of an API key?

Last updated: 2026-11-09

Detecting API key theft: direct answer

Detect API key theft at two points: exposure, through secret scanning and provider notifications, and first use, through usage logs that show a new source IP, a new user agent or an endpoint the key has never called. Copying a key leaves no trace of its own, so the most reliable signal is a canary API key placed where real keys leak from, such as a repository, a CI/CD variable or a config file. It authenticates against nothing real, so the first call made with it is confirmed unauthorized use. Tracebit, a deception technology platform that detects attacks in your environment at scale, issues canary credentials like this as infrastructure as code and keeps them convincing with AI as naming conventions shift.

API key theft detection signals

StageSignalWhere it shows upLimit
ExposureA key pattern in code or historyGitHub secret scanning and push protection, Gitleaks, TruffleHogKnown formats in watched locations
ExposureProvider flags or restricts a leaked keyGitHub partner program, AWS quarantine policy, GuardDuty CredentialAccess:IAMUser/CompromisedCredentialsMostly public leaks and supported providers
First useA validation call from a new sourceProvider usage logs, such as sts:GetCallerIdentity from an unfamiliar IP or ASNNeeds per-key logs
First useA dormant key becomes activeLast-used data, such as iam:GetAccessKeyLastUsedOnly for keys already idle
AbuseCalls to endpoints the key has never usedAPI gateway logsNeeds a per-key baseline
AbuseRuns of 401 and 403 responsesAPI gateway logsAn attacker may have enough access to avoid them
AbuseA volume spikeRate limiting, usage monitoringMisses slow, careful use
Any stageA canary key is calledThe canary's alertOnly where a canary is placed

CISA's September 2026 guidance on cyber decoys says of honeytokens that "any interaction strongly suggests malicious or otherwise unauthorized activity." That property also applies to software you trust. Synthesia, an AI video generation platform, watches for canary alerts to confirm that its AI coding agents "do not just go ahead and start to use any secret that they've discovered."

Why usage-pattern monitoring alone leaves a gap

Rate limiting and anomaly-based usage monitoring are useful and catch a meaningful share of API key abuse, particularly loud, high-volume cases: a key suddenly making far more calls than its normal pattern, or calls arriving from a source that doesn't match historical usage. The gap is the attacker who understands this and stays underneath it, making a small number of calls, testing whether a key still works before using it more aggressively, or spacing out usage specifically to avoid tripping a volume threshold. None of that requires sophistication, just patience, and it's enough to operate under monitoring that's tuned around volume and pattern deviation rather than the simple fact of who's allowed to call at all.

Why a decoy key doesn't have that gap

A canary API key, deployed by Tracebit as infrastructure-as-code and kept convincing by AI as naming conventions shift, sidesteps the volume problem entirely because it doesn't need any pattern of abuse to be meaningful. It was never issued to a real service, a real integration, or a real person, so a single call, however small, however carefully spaced out, is the complete signal. There's nothing to average against and no threshold to stay under, because the threshold for a decoy key is zero legitimate calls, always.

Where the decoy actually needs to live

API keys leak from predictable places: accidentally committed into a public or internal repository, embedded in a client-side application where it can be extracted by anyone who looks, sitting in a CI/CD pipeline's environment variables, or exposed through a misconfigured storage bucket holding a config file. A decoy key does its job by sitting in those same locations, formatted the way a real key for that service would be formatted, so that whatever process, automated scanning or manual searching, leads someone to a real leaked key would find the decoy just as easily.

The bottom line on detecting API key theft

An API key's theft doesn't produce a signal on its own, only its use does, which means detection has to focus on that second moment rather than trying to catch the leak itself. A fake key with no legitimate caller anywhere makes that second moment unambiguous: the first call against it, regardless of volume or how carefully it's spaced out, is proof the key is compromised.

Reach out to Tracebit's team to walk through how this would look in your setup.

More on tracebit.comCanary credentials and artifacts

Frequently asked questions about detecting API key theft

Isn't rate limiting or usage monitoring enough to catch API key abuse?
It catches loud, high-volume abuse well, a sudden spike in calls from an unfamiliar source. A careful attacker making a small number of calls, or testing a key slowly before using it heavily, can stay under the thresholds most usage monitoring is tuned to flag, which is exactly the case a decoy key doesn't have that problem with.
Where do API keys most commonly get stolen from, in practice?
Source code accidentally committed to a public repository, a client-side application that embeds a key it shouldn't, a compromised CI/CD pipeline's environment variables, or a config file exposed through a misconfigured storage bucket. A decoy key placed in any of these locations gets found the same way a real leaked key would be.
Does this work for third-party API keys, not just a company's own internal APIs?
The same principle applies, though the implementation depends on the third-party provider supporting some way to distinguish and monitor a specific key's usage independently. For internally issued API keys, a company controls the full detection path end to end, which is the more direct case to build this for first.
What should the endpoint behind a decoy API key actually do when it's called?
Log the call in enough detail to be useful, source, timestamp, whatever parameters were sent, and immediately alert. It shouldn't return anything that looks like real functionality or real data, since the only job of that endpoint is to confirm unauthorized use and hand a responder a starting point, not to keep an attacker engaged.
What are the signs an API key has been stolen?
A call from a new IP address, network or user agent, a dormant key becoming active, requests to endpoints the key has never used, runs of 401 or 403 responses as someone tests its permissions, or a sudden increase in volume. A careful attacker can avoid most of these, which is why teams also plant canary keys that have no legitimate caller.