API Key Generator Random Keys and Secrets

Generate random API keys, secrets and tokens: alphanumeric, hex, Base64, Base64URL, UUID v4 or numeric, from 8 to 256 characters, with your own prefix and optional key ID + secret pairs. The keys are made in your browser with its cryptographically secure random number generator and are not sent anywhere.

Updated

Format
How many keys
Strong191 bits of entropy per key (32 × 5.95 bits, 62 symbols)
Generating a key in your browser…
Download:

How the API Key Generator Works

Random Bytes From Your Browser

Every key starts as bytes from crypto.getRandomValues(), the cryptographically secure generator of the Web Crypto API. The page is static, so there is no server that could see or keep a key.

Every Symbol Equally Likely

Bytes are turned into characters by rejection sampling: a byte that would make some symbols more frequent than others is discarded and drawn again. The entropy shown under the options is therefore exact.

Ready to Paste

Copy one key or all of them, or download the batch as TXT, CSV, JSON or a .env file with API_KEY lines. Up to 100 keys per batch, each generated independently of the others.

API key formats

All six formats take their randomness from the same source and differ only in the set of symbols a key is written with. A larger set packs more bits into each character, so the key can be shorter for the same strength.

FormatSymbolsBits per characterExample
Alphanumeric A–Z a–z 0–9 5.95 vCtvCRyFJI0GCVz7fhcMs3ipPlgIpumI
Hex 0–9 a–f 4 532950a7e379539f74aeb393f6eaaa78
Base64 A–Z a–z 0–9 + / 6 tdzGlS4vqNvwvP0dzYU08ajxeKKp9+4l
Base64URL A–Z a–z 0–9 - _ 6 a1OaW2iw2gQm6QA0-uwzJ4r4WLsRBS_v
UUID v4 8-4-4-4-12 hex digits — 02234c07-dfd4-41fc-894e-adc627c212d1
Numeric 0–9 3.32 09152076898454811930955550599287
  • Alphanumeric. The usual choice for an API key: no symbol needs escaping in a URL, an HTTP header, a shell command or JSON.
  • Hex. Maps straight to bytes: 64 characters are exactly 32 bytes. Common for HMAC and webhook signing secrets.
  • Base64. The densest text form, 6 bits per character, but + and / have to be percent-encoded inside a URL.
  • Base64URL. Base64 with - and _ in place of + and /, safe in URLs and file names. JSON Web Tokens use this alphabet.
  • UUID v4. Client IDs and key IDs in systems that already store UUIDs. 122 of its 128 bits are random.
  • Numeric. Codes typed by hand or read aloud. A digit carries little, so 128 bits take 39 digits.

Base64 and Base64URL are both defined in RFC 4648; the URL-safe variant in its section 5 changes only the last two symbols of the alphabet. At a length that is a multiple of four, a key from this generator is also a valid Base64 encoding of random bytes without padding: 32 characters decode to 24 bytes, 64 characters to 48.

Key length and entropy

The strength of a random key is its entropy: the length multiplied by the bits each character carries. Every extra bit doubles the number of keys an attacker would have to try.

LengthNumericHexAlphanumericBase64 / Base64URL
16 characters 53 bits64 bits95 bits96 bits
24 characters 80 bits96 bits143 bits144 bits
32 characters 106 bits128 bits191 bits192 bits
48 characters 159 bits192 bits286 bits288 bits
64 characters 213 bits256 bits381 bits384 bits

OWASP's Session Management Cheat Sheet requires at least 64 bits of entropy in a session identifier and, for identifiers you generate yourself, a cryptographically secure generator with a size of at least 128 bits. An API key lives far longer than a session, so 128 bits is a sensible floor: 22 alphanumeric or Base64 characters, or 32 hex characters. The generator marks a key below 64 bits as weak and one of 128 bits or more as strong. Its default, 32 alphanumeric characters, carries about 191 bits.

For scale: 128 bits is the entropy of a 12-word BIP39 seed phrase, and 256 bits, which is 64 hex characters, is the entropy of a 24-word phrase and the size of a Bitcoin or Ethereum private key. The BIP39 visualizer shows how such bits become words, and the private key generator makes keys with a public key and an address for 18 networks.

Key prefixes

A prefix is a fixed, readable start of the key, such as sk_ or api_. It adds no security; it tells people and programs what they are looking at. A developer sees at once whether a key is secret or publishable, test or live, and secret scanners find leaked keys in repositories by these patterns. An underscore keeps the whole key one word, so a double-click selects all of it. Large APIs follow the same idea:

ServicePrefixMeaning
Stripesk_live_, sk_test_Secret keys for live and test mode
Stripepk_live_, pk_test_Publishable keys that may appear in client code
GitHubghp_, github_pat_Personal access tokens, classic and fine-grained
Slackxoxb-, xoxp-Bot tokens and user tokens
AWSAKIALong-term access key ID, paired with a 40-character secret access key

The prefix you type is put in front of every key and is not counted in the length or in the entropy. It may hold letters, digits, underscores, hyphens and dots, up to 24 characters.

Key ID and secret pairs

A single API key is both the name and the password of a client: whoever sees it in transit or in a log can use it. A pair splits the two roles. The key ID identifies the client and travels with every request. The secret stays with the client and the server; the client uses it to sign each request, usually with HMAC-SHA256 over the body and a timestamp, and the server recomputes the signature. AWS works this way with its access key ID and secret access key. The same split between a public identifier and a secret stands behind the OAuth client ID and client secret.

With the pair option on, the generator makes an independent secret for every key ID, 32 to 128 characters long, in the format of the key and with its own prefix if you need one. For a UUID key ID the secret is alphanumeric: RFC 9562, the UUID standard, says UUIDs must not be used as identifiers whose mere possession grants access.

Generate an API key in code

When keys are issued by your own backend, generate them there. Each line below takes 32 bytes, that is 256 bits, from a cryptographically secure generator seeded by the operating system:

WhereCodeResult
Linux, macOS shellopenssl rand -hex 3264 hex characters
Linux, macOS shellopenssl rand -base64 3244 Base64 characters, the last one is = padding
Node.jsrequire('node:crypto').randomBytes(32).toString('base64url')43 Base64URL characters
Browser JavaScriptArray.from(crypto.getRandomValues(new Uint8Array(32)), (b) => b.toString(16).padStart(2, '0')).join('')64 hex characters
Pythonsecrets.token_urlsafe(32)43 Base64URL characters; secrets.token_hex(32) gives 64 hex
PHPbin2hex(random_bytes(32))64 hex characters
Gob := make([]byte, 32); rand.Read(b); key := base64.RawURLEncoding.EncodeToString(b)43 Base64URL characters, with crypto/rand
Javabyte[] b = new byte[32]; new SecureRandom().nextBytes(b); String key = Base64.getUrlEncoder().withoutPadding().encodeToString(b);43 Base64URL characters
C# (.NET 6+)Convert.ToHexString(RandomNumberGenerator.GetBytes(32))64 hex characters, upper case
RubySecureRandom.urlsafe_base64(32)43 Base64URL characters

General-purpose generators such as Math.random() in JavaScript or rand() in PHP and C are built for speed, and their output can be predicted from the values they have already produced. They are not a source for keys.

How to Store and Use API Keys

✓

Store a hash, show the key once

Save the SHA-256 hash of the key in the database and show the key itself a single time, when it is created. A random key of 128 bits or more cannot be guessed back from its hash, so a fast hash is enough here; slow password hashes exist for short, human-chosen passwords.

✓

Compare in constant time

Check a presented key with a constant-time function: crypto.timingSafeEqual in Node.js, hmac.compare_digest in Python, hash_equals in PHP. An ordinary string comparison stops at the first wrong character, and the time it takes leaks how much of the key was right.

✓

Send it in a header over HTTPS

Pass the key as Authorization: Bearer <key> or in an X-API-Key header. A key placed in the query string ends up in server logs, browser history and Referer headers.

✓

Keep it out of the code

Read keys from environment variables or a secret manager, and keep .env files out of version control. Anything bundled into a web page or a mobile app can be read by its users, so a secret key belongs on the server only.

✓

One key per client and environment

Give every client, service and environment its own key with the narrowest permissions that work. A leaked test key then cannot touch production, and one client can be cut off without affecting the others.

✓

Rotate and revoke

Let two keys be valid at once so a client can switch without downtime, set an expiry date where you can, and revoke a key the moment it shows up in a log, a ticket or a repository. A prefix plus the last four characters is enough to tell keys apart in a dashboard.

API Key Generator: Frequently Asked Questions

What is an API key?

An API key is a long random string that a client sends with each request so the server can tell which application is calling. The server looks the key up, finds the account and permissions tied to it, and applies rate limits. The key works as a password for a program, which is why it has to be unpredictable and kept secret.

How long should an API key be?

Long enough to carry at least 128 bits of entropy: 22 alphanumeric or Base64 characters, or 32 hex characters. The default of this generator, 32 alphanumeric characters, carries about 191 bits. Going beyond 256 bits (43 alphanumeric or 64 hex characters) adds length without adding practical security.

Which format should I choose?

Alphanumeric suits most APIs: it is compact and needs no escaping anywhere. Choose hex when the value is used as raw bytes, for example an HMAC signing secret. Choose Base64URL for the shortest string that is still safe in a URL. Use a UUID v4 for identifiers such as a client ID, and numeric only where a person has to type the code.

Are the generated keys sent to a server?

No. The page is static: the keys are produced in your browser by crypto.getRandomValues(), the cryptographically secure generator of the Web Crypto API, and they are neither sent anywhere nor stored. Once the page has loaded, the generator also works with the network switched off.

Can this tool create a Stripe, OpenAI, Google or X (Twitter) API key?

No. A key for someone else's service is issued by that service in its developer console and is tied to your account there, so no outside tool can produce one. This generator makes keys for an API you run yourself. A prefix such as sk_ only gives your own keys the same recognizable look.

What is the difference between a key ID and a secret?

In a pair, the key ID is a public identifier that travels with every request and may appear in logs, and the secret never leaves the two parties: the client uses it to sign the request, usually with HMAC-SHA256, and the server recomputes the signature. Someone who intercepts a request sees the key ID and one signature, but cannot sign a different request.

How do I generate an API key in Node.js, Python or on Linux?

In Node.js: require('node:crypto').randomBytes(32).toString('base64url'). In Python: secrets.token_urlsafe(32). In a Linux or macOS terminal: openssl rand -hex 32. Each takes 32 bytes, that is 256 bits, from a cryptographically secure generator. Do not build keys from Math.random() or a timestamp: their output can be predicted.

How do I generate an API key for a React app?

Generate it on the server, not in React. A React app runs in the visitor's browser, so a key written into its code or into a build-time environment variable is delivered to every visitor. Create and check keys in your backend, and let the React app call that backend.

Is a UUID a good API key?

A version 4 UUID from a cryptographically secure generator has 122 random bits, which is enough to resist guessing. The UUID standard, RFC 9562, still says not to assume that UUIDs are hard to guess and not to use them as security capabilities: the format does not guarantee how a given UUID was generated. A UUID fits best as a key ID, with a separate random secret next to it; in pair mode this tool does exactly that.

What is the difference between an API key and a JWT?

An API key is an opaque random string: it means nothing by itself, and the server has to look it up. A JSON Web Token carries signed data, such as the user, the permissions and an expiry time, and the server verifies the signature instead of querying a database. API keys suit long-lived access between services; JWTs suit short-lived sessions.

The API key generator covers the keys of an API you run yourself. For cryptocurrency keys the site has separate tools: the private key generator, the BIP39 seed phrase generator and the mnemonic code converter.

Guides to API keys