Use outside Lockpin: the outside-spend check#
The outside-spend check tells you when a provider billed one of your API keys for use that did not go through this Lockpin. It reads the provider’s own usage per key, compares it with what Lockpin sent with that key, and raises an alert when the provider’s number is larger. This page is for whoever runs Lockpin and holds the provider’s admin key.
Note
The check detects. It does not stop anything: the use has already happened when the alert comes. It never says who used a key. It says the provider billed use that did not go through this Lockpin, which can be another machine, another tool, a script, or someone else who has the key. Your caps work the same with or without the check, and the check never changes, delays or refuses a call.
What it does and does not do#
What it does:
Once per interval, reads each watched provider’s hourly usage per API key, with a read-only admin key.
Compares it with the calls this Lockpin sent with the same provider key, per hour. A key counts as going through this Lockpin from its first call here until 30 days after its last. Hours in between with no call here, such as a weekend, are judged too, so use the provider billed then is detected.
Raises an alert on the destinations you already set up (Slack, Teams, ntfy, the webhook, a paired phone) and on the meter, when the provider billed an hour of a key for at least $1.00 and at least 10% more than Lockpin saw for that key and hour.
Tells you, in Lockpin’s log, which keys and hours it did not judge and why (see What is not judged).
What it does not do:
It does not stop use. It does not turn a key off at the provider. The alert names the provider’s page where you turn the key off yourself.
It does not say who used the key, or from where. The provider’s usage report does not say.
It does not see use the provider does not report per key (see Known limits).
It does not decide any call. A call is allowed or refused by the cap alone, from this machine’s ledger, with the network cut as well as connected.
Which accounts it works for#
It works for an account that has an admin API and a key that can read it:
Provider |
Admin key variable |
What it needs |
|---|---|---|
Anthropic |
|
An Anthropic organisation account. An Anthropic account that is not an organisation has no admin API and cannot be watched. |
OpenAI |
|
An OpenAI organisation with an admin key. Only chat and responses usage is read: embeddings, images and audio are not seen. |
A provider whose admin API does not list use per key, or has none, cannot be watched. Cursor’s admin key is read by lockpin import but lists no use per key, so the check does not use it. If no admin key is set for a provider, that provider is not watched, and Lockpin says so when it starts.
The check needs this machine’s ledger: it cannot run on a forwarder (-upstream-node), which keeps none.
Turn it on#
Put the admin key in the environment of the Lockpin process, and give -outside-check an interval of at least 5 minutes:
lockpin -outside-check 15m
or in lockpin.json, under "flags": "outside-check": "15m". 0, the default, is off. The provider’s usage is read by the hour, so 5 minutes is the shortest interval Lockpin accepts. There is no other setting you must make: the thresholds below have defaults.
Nothing from before the check was first turned on is judged. The first time it starts (there is no state file yet), Lockpin records the time, and no hour that began before it is judged, as other settings may have been in force then. The same holds for a provider watched for the first time later.
At start-up Lockpin prints which providers it watches, and which it does not because no admin key is set. With only ANTHROPIC_ADMIN_KEY set:
outside-spend check: watching Anthropic every 15m; an hour is judged once the hour after it has settled, so an alert for use of a key that did not go through this Lockpin comes about one to two hours after the use for Anthropic, plus up to one check interval
outside-spend check: no OPENAI_ADMIN_KEY, OpenAI is not watched
With both admin keys set, the first line watches Anthropic and OpenAI and gives two to three hours for OpenAI. See When it alerts, and how late.
These flags change the check. Each is also a key in lockpin.json; Configuration lists them with their defaults.
Flag |
Default |
What it does |
|---|---|---|
|
|
How often to check. At least |
|
|
An alert needs at least this many USD of outside use in an hour of a key. |
|
|
An alert also needs at least this percent of what went through this Lockpin with the key in that hour. |
|
none |
Provider key names, or hints, of keys that other machines also use. They are not judged. |
|
none |
|
|
off |
Also alert, once a day, on a provider key with at least |
-outside-shared-keys and -outside-keys take names and hints only. Lockpin refuses a value that looks like a whole key, and refuses to start. A hint is the key’s first 8 characters, …, and its last 4.
What the alert looks like#
An alert for an hour reads like this (the key is shown only as a hint, and the figures are an example):
Anthropic key "prod" (sk-ant-a…WXYZ) was billed about $412.10 for 13:00 to 14:00 UTC that did not go through this Lockpin ($3.20 did). From Anthropic's usage report, as of 15:20 UTC. If this was not you, turn the key off: https://console.anthropic.com/settings/keys
The first figure is what the provider billed for the hour that Lockpin did not send. The figure in brackets is what went through this Lockpin with that key in that hour.
The outside figure is the provider’s token counts priced at the price catalog’s list prices, as of the time shown. It is an estimate, not the provider’s invoice.
When the same key already had alerts in the 24 hours before, the alert ends with
Total since 11:00 UTC: $…, the sum of those hours and this one.Each key and hour is alerted once, also across restarts.
If the key has no name, the alert shows the hint alone, or the provider’s key id. It never shows a key.
If the check cannot run, an alert says so. It is raised after three failed reads of a provider in a row (the provider’s admin API is down, or the admin key is refused), or when the ledger cannot be written:
The outside-spend check for Anthropic has not run since 11:20 UTC: <the error, with any key removed>. Calls are not affected.
The outside-spend check is not judging anything: the ledger could not be written since 11:20 UTC. Calls are not affected.
Another alert follows when the check runs again: The outside-spend check for Anthropic is running again. or The outside-spend check is judging again. 11:00 to 15:00 UTC was not judged. The first two are alerts of the kind outside_check_down; the alert about use is of the kind outside_spend.
When it alerts, and how late#
An alert comes after the use, not during it:
An hour is judged only once the hour after it has ended and the provider’s report for it has settled. The next hour is needed because a call that starts late in one hour can be billed in the next.
Settle lag: 15 minutes for Anthropic, 60 minutes for OpenAI. Lockpin takes both from each provider’s documentation as checked on 24 November 2026: Anthropic documents its usage report as current within about 5 minutes, and OpenAI documents no delay for its usage API. They were read from documentation and not measured.
So an alert for Anthropic use comes between about 1 hour 15 minutes and 2 hours 15 minutes after the use, and for OpenAI use between about 2 and 3 hours after it, plus up to one check interval, as of these settle lags. Where in the hour the use fell decides which.
Each check reads the provider’s last 26 hours. An hour that is no longer in that window when Lockpin next checks is not judged.
To judge an hour, Lockpin also needs the ledger to have been read after the hour after it ended, and no call that began in that hour, or the two after it, to be still open.
The thresholds#
An hour of a key alerts when the outside use is at least $1.00 (-outside-min-usd) and at least 10% (-outside-min-percent) of what the ledger shows for that key and hour. Before the test, Lockpin takes off the dollars of that hour’s estimated, failed and abandoned calls of its own, because the provider’s count of those can differ from Lockpin’s. The dollars are the outside tokens at the model’s list price.
How the sums are made: Lockpin compares tokens, not dollars, per class (input, cached input, cache writes and output). An hour’s outside tokens are what the provider counted beyond what this Lockpin sent, after allowing for a call that started in one hour and was billed in the next. A model the provider reports under a different name than the one Lockpin sent (for example a fallback) does not count as outside use.
What is not judged, and how you are told#
Some hours and keys cannot be judged fairly. Lockpin does not guess: it leaves them out and says so. The first time a key or hour is not judged, and whenever its reason changes, Lockpin writes a warning line to its log, such as:
outside-spend check: Anthropic key "batch" (sk-ant-a…WXYZ) is not judged: shared with other machines
Later checks that say the same thing log it at the lower info level, so it does not repeat as a warning. These are shown in the log and are not alerts.
Not judged |
The line says |
What to do |
|---|---|---|
A key that other machines also use |
|
You named it in |
Two keys that look alike, or one key under two provider names |
|
The hints of the keys Lockpin sent and of the provider’s keys do not pair one to one (one hint fits two provider keys, or one provider key fits two hints), so Lockpin cannot tell which key is which, and leaves them out. The same holds when the ledger has a key’s hint under more than one provider name (see Known limits). |
Keys Lockpin sends with that match no key in the provider’s list |
|
Lockpin sent calls with keys of the provider in the last day, and not one key in the provider’s list matches their hints: the provider’s hint format may differ from the one Lockpin expects, or the keys belong to another organisation. Name the keys that go through this Lockpin in |
An hour holding charges from before this version |
|
Older ledger lines carry no key hint and no send time, so they cannot be matched to a key. The hour is skipped, until those hours age out of the 26-hour window. |
A provider that gives no hint for a key |
|
The provider’s key list shows the key by name only. If it does go through this Lockpin, name it in |
Hours the ledger could not be written |
a warning that nothing from that hour on is judged |
While Lockpin cannot write its ledger, and for the hours around the fault, calls may be missing from the ledger. Lockpin says which hours were not judged when it can write again. |
Any provider, while |
|
Lockpin lets those calls through without a charge, so the provider bills them and the ledger does not have them. |
Any provider, while |
|
A call that fails after it was sent is released, not charged, while the provider can still bill it. |
An hour with a call the client cancelled, and the hour after it |
|
A call the client cancels before its reply came is charged its input only. The provider may finish it and bill its output, in that hour or the next. |
Hours before the check was first turned on |
nothing for each hour |
See Turn it on. |
Use before the key’s first call through this Lockpin |
nothing for each hour |
Use up to the hour of a key’s first call here is not outside use of it. A key stays watched for 30 days after its last call here. A key with no call here in the last 30 days is a key “not behind this Lockpin”: one log line counts such keys and the dollars the provider reported for them, as a warning the first time and whenever their number changes. With |
Use on a model Lockpin has no price for is not alerted, because it cannot be turned into dollars. It is shown as a token count in the log instead:
outside-spend check: Anthropic key "prod" (sk-ant-a…WXYZ): 1,234,567 tokens at 13:00 UTC on a model Lockpin has no price for did not go through this Lockpin. From Anthropic's usage report, as of 15:20 UTC.
Update the price catalog (lockpin prices update) to price it.
Known limits#
A long call can look like outside use. A single call that runs longer than an hour may be reported as outside use if the provider counts it in the hour it completes rather than the hour it was sent. Lockpin has not measured which the providers do.
The time that counts is the time a call is sent. Lockpin records the time a call is sent upstream, not the time it arrived. A call held at the cap for minutes is counted in the hour it was sent.
Only what the provider reports per key. OpenAI chat and responses usage is read; embeddings, images and audio are not seen, so use of those is not detected.
Hints are matched, not keys. Lockpin matches the first 8 and last 4 characters it keeps of each key against the provider’s redacted key. The provider’s real hint formats may differ from the ones Lockpin was tested with. A hint that matches nothing, or two keys, is not judged. When none of the keys Lockpin sends with matches a key in the provider’s list, a log line says so.
One key under two provider names is not judged. The provider name in the ledger must be the one the check reads (
anthropicoropenai). If the same key is also sent under another provider name, such as a catalog entry of your own or a regional base URL that sends the same Anthropic or OpenAI key, or a router given your own key, that key is not judged at all, as part of its use is charged under the other name.A key stays watched for 30 days after its last call here. Within those 30 days an idle hour is judged against an empty ledger, so any use the provider billed then alerts. After them, the key counts as not behind this Lockpin until its next call here.
A full disk at a restart. If the disk is full when Lockpin restarts, the note that the ledger could not be written can be lost. Hours around that fault may then be judged against a ledger that lacks some of the calls, and can raise an alert for use that did go through this Lockpin.
It cannot see use that is not billed to a key the provider reports, and it cannot tell you who used one.
Keep the admin key safe#
An admin key can list, and at some providers manage, every key of the organisation. Treat it as more sensitive than an ordinary provider key.
Lockpin reads it from the environment only:
ANTHROPIC_ADMIN_KEYandOPENAI_ADMIN_KEY, the nameslockpin importreads. It never writes it to a file, the ledger, the log or an alert, and the config file refuses a value that looks like a key.When the check is on, Lockpin takes the variables out of its own process environment at start-up, so no program Lockpin starts afterwards inherits them.
Keep it on the node only: in the environment of the Lockpin service, or of the node. Do not put it in a shell profile, a
.envfile, an agent’s settings file or the repository.lockpin doctorfails when it finds one in such a file (see Exposure checks).Lockpin only reads with it. It sends
GETrequests to the provider’s admin API for the key list and the usage report (see What leaves your machine). It never creates, changes or deletes a key.If you think it was exposed, turn it off at the provider’s console and make a new one.
What stays on your machine#
Nothing from the check is uploaded to the hosted dashboard. These stay on the machine:
The
outside_spendandoutside_check_downalerts in the ledger, with the key hint and the hour. The charge’s key hint (provider_key_hint) and send time (started_at) in the ledger. They are not on the reporter’s allowlist, and a test says so.The check’s state file,
lockpin-outside.json, beside the ledger: the last hour judged for each key (by the provider’s key id), any hours not judged because the ledger could not be written, when the check first started for each provider, and the keys found behind this Lockpin, each with the provider’s key id, Lockpin’s hint of it and the hours of its first and last call here. If it cannot be read, Lockpin moves it aside tolockpin-outside.json.unreadable, says so once, and starts over from that moment. An alert already raised is not raised again.A key appears only as a hint: its first 8 and last 4 characters. Never the whole key, in any file, log or alert.
An alert goes to the destinations you configured, like any other alert, so its text (the key’s name and hint, the hour and the dollars) reaches them. It does not go to the hosted dashboard.
The only network traffic the check adds is its read-only requests to the providers’ admin APIs with your admin key, once per interval.
For the other half, a Lockpin key copied off its machine, see Keys that are worthless if copied. To see where provider keys lie unprotected on this machine, run lockpin doctor -exposure.