Provider API key committed in source
A provider key committed in source. The key is masked in every report.
Why it costs money
Automated scanners watch public repositories for key-shaped strings and test what they find within minutes. A working LLM key is valuable to them, because they can resell access or run their own workloads on it. The industry name for this is LLMjacking, and the usage is billed to you until the key is revoked.
Deleting the line does not fix it. The key stays in git history, in forks, in CI logs and on every clone. Private repositories are not safe either: they get shared with contractors, mirrored or made public later.
Example
Flagged
from openai import OpenAI
client = OpenAI(api_key="sk-proj-4fT9qL2mXv8RkP1sZ7wN3bYcH6dJ0")
def ask(question: str) -> str:
response = client.chat.completions.create(
model="gpt-4o-mini",
max_tokens=300,
messages=[{"role": "user", "content": question}],
)
return response.choices[0].message.contentFixed
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
def ask(question: str) -> str:
response = client.chat.completions.create(
model="gpt-4o-mini",
max_tokens=300,
messages=[{"role": "user", "content": question}],
)
return response.choices[0].message.contentHow to fix it
Rotate the key first: revoke it in the provider console and issue a new one. Removing it from the code comes second, because the old key is already in history and has to be treated as public.
Load the new key from an environment variable or a secret manager on the server, and add a secret scanner to your pre-commit hooks and CI so the next one is caught before it is pushed.
What the audit detects
- Quoted string literals shaped like provider keys: sk- (OpenAI, including sk-proj-), sk-ant- (Anthropic) or AIza (Google), with at least 18 characters after the prefix and a mix of letters and digits.
- Obvious placeholders are skipped: xxxx, your-api-key, example, dummy, redacted, ellipses, and test, fake, mock or demo keys such as sk-test-....
- The key is masked in every report, showing only the provider prefix and the key length, so the report itself never contains the secret.
Research
Sysdig: LLMjacking, stolen cloud credentials used in new AI attack. Exposed LLM credentials are found and abused quickly, and removing a key from code is not enough once it has been committed. It has to be rotated.