API Key Generator

Generate cryptographically secure API keys, tokens, and secrets. Choose from multiple formats including hex, base64, and UUID.

Use + D to bookmark this tool
pwgen — generate api-key
guest@pwgen:~$ generate api-key --format=hex --bytes=32
format
bytes
32
prefix
[init] crypto.getRandomValues() — ready
[info] all generation client-side · zero server requests

What Is an API Key?

An API key is a unique string of characters used to authenticate requests to an API (Application Programming Interface). It acts as a secret token that identifies your application and grants access to specific services — like OpenAI's GPT models, Stripe's payment processing, or AWS cloud resources.

Unlike passwords, API keys are typically generated once and embedded in server-side code or environment variables. They should never appear in client-side code, version control, or public repositories. A compromised API key can give attackers full access to your account and services, which is why cryptographic randomness and proper key management are critical.

Your Key's Security Level

256-bit entropyEquivalent to AES-256 encryption
military grade
Brute-force proofEven all world's computers combined can't crack it
2^256 combos
Production readySafe for production use indefinitely
no expiry needed
NIST & OWASP compliantMeets federal and industry standards
SP 800-133

API Key Formats Explained

Hexadecimal

Characters 0-9 and a-f. The most common format for API keys and tokens. A 32-byte hex key produces a 64-character string with 256 bits of entropy.

Base64

Characters A-Z, a-z, 0-9, +, /. More compact than hex — a 32-byte key produces a 44-character string. Common in authentication headers and JWT secrets.

Base64URL

Like Base64 but URL-safe — uses - and _ instead of + and /. No padding. Ideal for keys that appear in URLs or query parameters.

UUID v4

Standard 128-bit format: 8-4-4-4-12 hex digits. Widely used for resource identifiers and some API systems. Provides 122 bits of randomness.

API Key Format Comparison

FormatBytesCharactersEntropyUse Case
Hex3264256 bitsDatabase IDs, signing secrets
Base643244256 bitsAuth headers, JWT secrets
Base64URL3243256 bitsURLs, query params
UUID v41636122 bitsResource IDs
Alphanumeric3232190 bitsHuman-readable tokens

Best Practices for API Key Management

  1. Never commit keys to version control. Use environment variables or secret management tools like HashiCorp Vault, AWS Secrets Manager, or .env files (added to .gitignore).
  2. Use prefixes to identify key types. Prefixes like "sk_" (secret key), "pk_" (public key), or "test_" make it easy to identify key purposes and catch accidental exposure in logs.
  3. Rotate keys regularly. Set up a rotation schedule. If a key is compromised, you can revoke it immediately without disrupting the entire system.
  4. Use different keys for different environments. Never use production keys in development or testing. Generate separate keys for each environment.
  5. Apply the principle of least privilege. Each API key should only have the permissions it needs. Don't use admin keys where read-only keys would suffice.
  6. Monitor key usage. Log API key usage and set up alerts for unusual patterns. This helps detect compromised keys early.

Common API Key Prefixes

ServicePrefixExampleTypeNotes
Stripesk_sk_live_abc123...SecretLive vs test keys
OpenAIsk-sk-proj-xyz...SecretProject-scoped
AWSAKIAAKIAIOSFODNN7...Access KeyAlways 20 chars
GitHubghp_ghp_1234567890...PATFine-grained tokens
TwilioSKSK1234567890ab...API KeyAccount-level

Using recognizable prefixes helps secret scanners (like GitHub's) detect leaked keys automatically.

More Security Tools

Frequently Asked Questions

How many bytes should I use?

32 bytes (256 bits) is the standard recommendation for API keys and secrets. This provides security equivalent to AES-256 encryption. Use 16 bytes minimum for less critical applications.

Is this suitable for production use?

The cryptographic randomness is production-grade (Web Crypto API). However, for team/enterprise environments, consider using a dedicated secret management system that handles rotation and access control.

What's the difference between API keys and tokens?

API keys are typically long-lived credentials that identify an application. Tokens (like JWTs) are often short-lived, carry additional claims, and are tied to specific users or sessions.

Should I use UUID v4 as an API key?

UUIDs work as identifiers but only provide 122 bits of randomness. For security-sensitive keys (signing secrets, encryption keys), use 256-bit hex or base64 keys instead.

What format should I use for JWT secrets?

Base64 is the most common format for JWT signing secrets. Use at least 32 bytes (256 bits) for HS256 and 64 bytes (512 bits) for HS512. The key must be kept server-side only.

How often should I rotate API keys?

Rotate production keys every 90 days as a baseline. Rotate immediately if a key is exposed in logs, commits, or a breach. Use key management systems that support automatic rotation.

Copied to clipboard ✓