Skip to content
AI · Secret guide

Leaked Ollama API Key: what to do in the first hour

High severityDetected onlyLast verified · 5 min read

An Ollama API key lets whoever holds it call Ollama’s hosted models from your account, for the cloud models that run on Ollama’s servers rather than on your own machine. Requests made with a leaked key are billed or limited against your account, and they can be used to run models at your expense or to send prompts that you did not write. Keys of this kind do not expose a model you ran locally, since a local Ollama server does not need one. Revoke the key first, then check what the account was used for.

Check your GitHub account for leaked secrets — free

Provider
Ollama
Severity
High
Impact
SaaS account access and billing
Checked live by LeakWatch
No

What an Ollama API Key looks like

Ollama’s cloud keys do not carry a readable prefix. The rule in LeakWatch expects a 32-character hexadecimal part, a dot, and then a 24-character part of letters, digits, underscores and hyphens. The masked form below shows the general layout only:

XXXX…XXXX.XXXX…XXXX   layout of an Ollama cloud key (masked)

Because there is no prefix, the rule only reports a value of that layout when the word ollama appears just before it, usually as a variable name such as OLLAMA_API_KEY. The local server address used by the desktop app is not a secret, and it does not need a key, so an address on its own is not a leak. If you find a value with the dotted layout in a file, check your account’s key list before deciding whether it is yours.

How Ollama API Keys get leaked

  • Scripts that call the hosted API. A script that carries the key so that a model can run from a server or a scheduled job, pushed to a repository.
  • Browser code. A call to the hosted API from front-end JavaScript, which places the key in a bundle that anyone can download. Ollama’s own guidance is to keep keys out of browser code.
  • Container images. A key copied into a Docker build context or an image layer, which stays in the image even after the file is removed from the source.
  • CI variables printed in logs. A pipeline step that echoes the environment when a model call fails.
  • Shared notebooks and examples. A key pasted into a notebook cell or a tutorial to show how to list models.

What to do in the first hour

  1. Revoke the key. Open the account settings on Ollama, go to the keys page and revoke the key that leaked. Revoking takes effect for new requests, so do it before you clean the code.
  2. Create a replacement for each service that needs one, and store it in a secret manager or in the environment of the process that uses it.
  3. Check usage. Review the usage figures on your account for the period since the exposure. Look for models you do not use, for a jump in requests, and for activity at unusual hours.
  4. Check the bill and limits. If your plan has a spending or usage limit, confirm it is set. Contact Ollama support if the usage shows calls you cannot explain.
  5. Check the rest of the file. A script that holds an Ollama key often holds other AI provider keys or database passwords. Revoke those too.
  6. Clean the repository. Remove the value from current files and from any container image that was built with it. Rebuild the image without the key, then rewrite history if the repository was public. See I accidentally pushed an API key to GitHub for the full order.
  7. Move the calls to the server. If a browser calls the hosted API, route the request through your own server, so the key never reaches the client.

Not sure what else leaked from the same repository? Run a free scan.

Not sure what else leaked? Run a free scan.

Revoke it at Ollama

Ollama’s documentation points to a keys page in the account settings, where you can see the keys and revoke any of them at any time. The docs say that cloud API keys do not currently expire, which means a key that leaked stays valid until someone revokes it. Revocation is the step to take, not waiting for an expiry. After you revoke a key, create a replacement, set it in the environment of the service that needs it and test one call. If you use the desktop app or the command-line tool with ollama signin, the sign-in is handled separately from the key, so check those sessions as well. The menu labels may change, so confirm them in your own account before you rely on them.

How LeakWatch detects it

The rule is called “Ollama API Key”. It looks for the word ollama, followed by a short run of characters and an assignment sign or similar separator, then a value made of 32 lowercase hexadecimal characters, a dot, and 24 letters, digits, underscores or hyphens. The word requirement is what keeps the rule from matching the shape alone. The severity is high, with the SaaS impact class, because the key can run hosted models on your account. This type is not checked live: LeakWatch does not send the value to Ollama, so a finding means a matching value sat next to the name, not that the key still works.

LeakWatch detects this format but does not check it live: it can tell you the key is exposed, not whether it still works. Assume it does until you have revoked it.

FAQ

Does a leaked key let someone read my local models?

No. A local Ollama server listens on your own machine and does not need a key. The cloud key only works against Ollama’s hosted service, so the risk is to your hosted usage and to any prompts sent through it.

Why does Ollama say the keys do not expire?

That is the vendor’s description at the time of writing. A key that does not expire is only safe while it stays secret, so you should revoke leaked keys yourself and rotate the ones in use on a schedule that fits your risk.

Should I keep the key in the environment variable?

Yes, that is the usual place for it, as long as the file that sets the variable is not committed and the process environment is not printed or logged.

Get alerted next time a secret leaks — create a free account

LeakWatch is not affiliated with Ollama.