the IT Hustle
ツール実践マニュアル概要
FundamentalsAI活用2026-04-03•10 min で読める

API Keys Explained: What They Are and How to Keep Them Safe

著者: Salty Deprecated Software Engineer

✨ AI アシスト コンテンツ

この記事はAIの支援を受けて作成され、正確性と品質についてチームが審査しました。すべての技術情報と例は検証済みです。

In 2024, a developer accidentally pushed an AWS API key to a public GitHub repo. Within 4 minutes — not hours, minutes — bots had found it and spun up $50,000 worth of cryptocurrency mining instances on his account.

API keys are the passwords of the internet. And unlike passwords, people accidentally publish them in code, screenshots, and Slack messages every single day.

Here's what they are, why they exist, and how to not be the person who costs their company $50K on a Tuesday.

What Is an API Key?

An API key is a unique string of characters that identifies your application to a service. When you use Google Maps in your app, Stripe for payments, or OpenAI for AI — each one gives you an API key so they know who's making the request and how much to charge you.

Example API keys (fake, obviously):

sk_test_4eC39HqLyjWDarjtT1zdp7dc

AKIAIOSFODNN7EXAMPLE

AIzaSyD-9tSrke72PouQMnMX-a7rWEbA8o_KQXk

sk_ = Stripe, AKIA = AWS, AIza = Google. Prefixes tell you what service.

API Key vs. Password vs. Token

TypeIdentifiesExpires?Used By
API KeyYour applicationUsually noServer-to-server
PasswordA human userUsually noHuman login
OAuth TokenA user's sessionYes (hours/days)Delegated access
JWTA verified identityYes (minutes/hours)Stateless auth

The 5 Rules of API Key Safety

1. Never Hardcode API Keys in Your Code

Bad:

const stripe = new Stripe("sk_live_abc123");

Good:

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

2. Use .env Files and .gitignore

Store keys in .env.local and make sure .env*.local is in your .gitignore. Read our full guide: Environment Variables Explained Like You're 5.

3. Use Different Keys for Development and Production

Most services give you separate test and live keys (Stripe: sk_test_ vs sk_live_). Use test keys locally. If your test key leaks, no real money is at risk.

4. Restrict Key Permissions

Most services let you limit what an API key can do. If your app only reads data, create a read-only key. If it only needs one endpoint, restrict to that endpoint. The principle: minimum privilege, maximum safety.

5. Rotate Keys If Compromised

If a key is exposed — even briefly — assume it's compromised. Go to the service dashboard, generate a new key, update your environment variables, and revoke the old key. Do this immediately, not "after the sprint."

Where API Keys Go Wrong

  • Committed to Git. Even if you delete the commit later, the key exists in git history. Bots scrape GitHub continuously.
  • Shared in Slack/email. These channels aren't encrypted end-to-end. Use a password manager or secrets vault.
  • Visible in screenshots. Developers share terminal screenshots with API keys visible. Crop or blur.
  • Embedded in frontend code. Any key in client-side JavaScript is visible to anyone who opens DevTools. Only put publishable keys (like Stripe's pk_) in the frontend.

The Bottom Line

API keys are simple: they identify your app to a service. The hard part is keeping them secret. Use environment variables, never commit them to git, restrict permissions, and rotate immediately if exposed. The 4-minute horror story doesn't have to be yours.

Need to generate strong API keys or secrets? Use our free Password Generator. Setting up environment variables? Read Environment Variables Explained Like You're 5.

IT
Salty Deprecated Software Engineer

The IT Hustleの編集用ペンネームで書いています——ノートPC修理技術者、システム管理者、ストレージエンジニア、ソフトウェアエンジニアとしての25年以上の経験を、今はAIエージェントの運用に注いでいます。すべての記事は公開前に人間が確認します。詳しくは編集方針をご覧ください。

ツール一覧全記事私たちについて

最新情報を受け取る

新しいツール、ブログ記事、アップデートをいち早くお届けします。スパムなし。

独自の反ハルシネーション プロンプトを生成する

AIプロンプトエンジンは独自技術を使い、内蔵の検証・矛盾テスト付きプロンプトを生成します。

無料で3回試す →

会社情報

  • 概要
  • 実践マニュアル
  • AI用語集
  • 筆者について
  • お問い合わせ

プロダクト

  • ツール
  • 料金ウォッチ
  • エージェントオプス
  • コード
  • デザイン
  • システム管理
  • 生産性
  • マーケティング
  • ビジネス

法的情報

  • プライバシーポリシー
  • 利用規約
  • 免責事項
  • 編集方針
  • 訂正について

© 2026 Salty Rantz LLC. 無断複製・転載を禁じます。

テクノロジーの変革を乗り越える人々のために。