Explore Grablex
JOURNAL / DEVELOPER SECURITY / API CREDENTIALS

An API key is
authority in a string.

A key can let software act, use paid services, or reach data. Keep each one narrow, private, attributable, and easy to revoke.

A small hardware security key rests beside a charcoal notebook and a laptop on a softly lit desk.SYMPLOKA / JOURNAL / SYMPLOKA
DEVELOPER SECURITY / API CREDENTIALS

API keys are credentials. Give them a lifecycle.

A key can let software act, use paid services, or reach data. Keep each one narrow, private, attributable, and easy to revoke.

01 / KNOW WHAT THE KEY CAN DO

Treat a credential as the authority it carries.

An API key is more than a project label. Depending on the provider and its permissions, a person who obtains it may be able to make requests as your application, consume paid quota, or reach connected resources. The exact scope differs by product, so check the key’s permissions and the account behind it before sharing it with a tool.

Some public client identifiers are designed to appear in a browser and rely on strict domain or API restrictions. That does not make every string called an API key safe to expose. Follow the provider’s documentation for that exact key type; keep secret bearer credentials on a server you control.

If a key can authorize a request, assume that anyone who can read it can try to use it.

SOURCESOpenAI Help Center: best practices for API key safety ↗Google Cloud: best practices for managing API keys ↗
02 / CREATE A SMALL BLAST RADIUS

One workload, one purpose, one owner.

Avoid a shared, all-powerful key for an entire team. Use a separate credential for each application, environment, or workload when the provider supports it. That makes it easier to see where a request came from and to disable one integration without breaking unrelated work.

Grant only the APIs, operations, projects, and data the workload needs. Add an expiration when the provider offers one. Prefer a short-lived workload identity or delegated token over a long-lived static key where the service supports it. Usage limits and alerts can help you spot unusual activity, but they do not revoke a stolen credential.

  • Name a human owner and the application that consumes the key.
  • Separate development, test, and production credentials.
  • Restrict permissions and destinations; remove unused keys.
  • Record how the key expires, rotates, and gets revoked.
SOURCESClaude Platform Docs: create and manage API keys ↗Google Cloud: restrict API keys ↗
03 / KEEP SECRETS OUT OF THE CLIENT

A browser is a public place for credentials.

Anything bundled into a web page or mobile app can be inspected by its users. A frontend should send a request to an authenticated service you control; that service can attach its private credential and enforce the user’s access. Never hide a key by renaming a variable or obfuscating the bundle.

For local development, environment variables can keep a key out of source code. A local environment file still needs to be excluded from Git and protected on the machine. In CI, use the platform’s encrypted secret store with narrowly scoped access. For production services, use a secrets manager or workload identity suited to the runtime. Environment variables reduce accidental commits; they are not a complete secrets-management system.

Do not place credentials in URLs, prompts, screenshots, issue trackers, source files, example configuration, or logs. A connected coding agent or third-party tool that can read a key can potentially use it too. Give an agent access only through the smallest scoped mechanism the task requires.

SOURCESOpenAI Help Center: API key safety for applications and repositories ↗OWASP Secrets Management Cheat Sheet ↗
04 / ROTATE WITH A PLAN

A safe rotation has an owner and a tested replacement.

Rotation is a controlled handover, not simply making a new key and hoping nothing breaks. Create the replacement with the same or narrower scope, install it in the intended consumer, verify that requests work, then revoke the old key. Track which environments and jobs use it so a forgotten copy does not become a permanent exception.

Follow the provider’s expiration and rotation controls for that credential. If there is evidence a key was exposed, do not wait for the routine rotation date: revoke it as soon as the service allows, then replace it and inspect how it was used. Removing a value from the current source file does not invalidate the credential.

Revocation stops future use of that credential. It does not undo actions or charges that already occurred.

SOURCESOpenAI Help Center: expire and rotate project API keys ↗OWASP Secrets Management Cheat Sheet: lifecycle and revocation ↗
05 / IF A KEY LEAKS

Contain access first. Clean up every copy second.

Treat a disclosed key as compromised even if the repository is private or the commit is later removed. Revoke it in the provider’s console, issue a least-privilege replacement, update the affected service, and verify that the old credential no longer works. Then review usage, access logs, and billing for activity you do not recognize.

Search the current files, build artifacts, CI output, logs, and places where people shared the value. Secret scanning and push protection can catch supported patterns before or after a push, but coverage varies by provider and credential type. They are a backstop, not permission to store keys in source code. Rewriting Git history can remove a visible copy, but it does not replace revocation.

  • Revoke the exposed credential immediately.
  • Create and test a narrowly scoped replacement; update each consumer.
  • Check provider activity, quotas, and charges for unexpected use.
  • Remove exposed copies from code and logs, then add scanning to catch recurrence.
SOURCESGitHub Docs: remediate a leaked secret ↗GitHub Docs: push protection and its coverage ↗