October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Stop LLMs Leaking API Keys: Keep Credentials Out of Reach

Keep live API keys out of prompts and project files an assistant can read. Use runtime secret access, least privilege, code review, and scanning as layered defenses.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep real API keys out of source files and out of any context a coding assistant can read. Have generated code obtain credentials from a controlled runtime environment or secrets manager, limit access to what the task needs, and scan changes before they are committed or merged. Treat scanning and repository push protection as backstops—not guarantees. If a real key is exposed, revoke or rotate it and investigate its use.

Why “default to secret” is the safer rule

Assume a credential could be exposed if it enters a coding assistant’s readable files, prompt, terminal context, or workflow. The most reliable first step is to keep the credential out of those places, rather than asking a model to protect it after seeing it.

As an Amazon Associate I earn from qualifying purchases.

A prompt is not an authorization boundary or a secret store. OWASP’s guidance on system prompt leakage says, “The system prompt should not be considered a secret, nor should it be used as a security control.” Keep access controls outside the model and do not grant an agent credentials it does not need. OWASP, LLM07:2025 System Prompt Leakage

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep credentials out of the assistant’s context

Do not paste a live key into a prompt or leave it in a project file the assistant can read. OWASP recommends using vault services or encrypted stores for secrets and excluding sensitive files from coding-assistant context. OWASP Secrets Management Cheat Sheet and OWASP, LLM06:2025 Excessive Agency

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Use the coding tool’s context-exclusion mechanism for files such as .env, private keys, and credential files. Do not rely on .gitignore for this: it controls what Git tracks, not what a filesystem-reading assistant can open.

In prompts and examples, use a placeholder such as API_KEY or a configuration-variable name, not the actual credential. If an agent has tool, repository, or CI access, limit its permissions and require approval before it reaches sensitive resources or changes workflows.

Rank #2
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

Make generated code retrieve secrets at runtime

Ask the assistant to write code that reads a credential from a controlled runtime environment or retrieves it through a secrets manager integration. Provide only the access the workload needs, and avoid printing secret values or including them in exception messages. OWASP’s secrets-management guidance covers least-privilege access and runtime secret provisioning.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, a prompt can ask for code that reads API_KEY from the process environment, without supplying its value. The deployment environment—not the source file or prompt—must provide the real credential. Where a secrets manager is used, evaluate whether its access controls, rotation and revocation support, audit visibility, deployment integration, and operational requirements fit the workload.

Rank #3
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

Review changes and block accidental leaks

Use more than one check: inspect the change yourself, scan locally before committing, and run secret detection as a pull request gate configured to fail when it finds a credential. Review source code, tests, examples, notebooks, logs, and CI configuration for hard-coded values or accidental secret forwarding.

Enable repository push protection where available. GitHub says, “With push protection, secret scanning blocks contributors from pushing secrets to a repository and generates an alert whenever a contributor bypasses the block.” GitHub Docs: How-tos for leak prevention

Rank #4
Yubico - Security Key NFC - Basic Compatibility - Multi-Factor Authentication (MFA) Key, Connect via USB-A or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Push protection and scanners recognize supported secret patterns; they cannot establish that every possible credential or leak path is covered. When assessing checks, consider which secret types they detect, when they run, how findings and bypasses are handled, and whether the enforcement is available for the repository. Keep scanning in the development workflow even when push protection is enabled.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Respond promptly if a real key appears

  1. Revoke or rotate the exposed credential. Treat it as compromised; deleting the line from the current file does not make the key safe.
  2. Remove it from active code and configuration. Check the repository’s secret alerts and review available access logs for unexpected use.
  3. Check the surrounding workflow. Look for copies in tests, examples, notebooks, logs, CI configuration, prompts, or other files the assistant could read, then close the access path that allowed the exposure.

OWASP’s secrets-management guidance includes revocation, rotation, and monitoring as parts of the secret lifecycle. OWASP Secrets Management Cheat Sheet

Best Value
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified (Pack of 2)
  • The information below is per-pack only
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.

Choose controls for both storage and detection

Runtime secret storage and leak detection address different parts of the problem. Choose storage based on access control, least privilege, rotation and revocation, audit visibility, integration with deployment, and operational complexity. Choose scanning based on developer feedback, pull request enforcement, coverage of relevant secret types, bypass and audit handling, and repository availability. Neither choice removes every route by which a key can enter model context or generated output.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.