Xerobit

API Key Generator with Prefix, Length, and Entropy

Use this api key generator to create cryptographically secure API keys and API tokens with a custom prefix like sk_live_, adjustable length, and several character sets. It calculates the exact entropy in bits so you know how strong each one is. Everything runs in your browser; nothing is uploaded or stored.

Result

  • Entropy
    190.53 bits

    random part only: length x log2(62)

  • Characters per key
    40

    8 prefix + 32 random

  • Alphabet size
    62

    Base62 (0-9, A-Z, a-z)

  • Bits per character
    5.95
  • Keys generated
    1
  1. sk_live_G80mbWI421iBH3KOvdNk9taetcGrzADP

How to use the api key generator

  1. Enter a prefix such as sk_live_ or leave it blank for no prefix.
  2. Set the random length to determine how many characters follow the prefix.
  3. Choose a character set: base62, lowercase alphanumeric, hexadecimal or base64url.
  4. Set the quantity if you need to generate multiple keys in bulk.
  5. Click Generate to create your keys and view the calculated entropy.

How Entropy Is Calculated

Entropy measures the unpredictability of a generated key, expressed in bits. The formula is straightforward: multiply the number of random characters by the base-2 logarithm of the character set size.

For example, a 32-character key using the 62-character alphanumeric set (a-z, A-Z, 0-9) has an entropy of 32 * log2(62) = 190.53 bits. A 64-character hexadecimal key uses a 16-character set, yielding 64 * log2(16) = 256 bits of entropy. This api key generator displays the exact entropy below every batch so you can verify that your keys meet your security requirements.

Using it as an API token generator

An API key and an API token are both random secrets, so the same generator makes either. For a token, pick the hex or base64url character set, choose a length that gives at least 128 bits of entropy (the tool shows the figure), and add a prefix such as tok_ if you want tokens to be recognizable in logs and secret scanners. Use the count field to produce a batch.

This page does not offer base58 output or a checksum suffix. If you need a signed or expiring token for sessions, a JWT is a better fit than a random string.

Rejection Sampling Explained

To guarantee that every character in your key is equally likely, this tool uses rejection sampling rather than a simple modulo operation. Cryptographic random number generators produce uniformly distributed bytes from 0 to 255. If you map these directly to a 62-character alphabet using modulo 62, the first few characters will appear slightly more often because 256 does not divide evenly by 62.

Rejection sampling fixes this bias. The algorithm calculates the largest multiple of the alphabet size that fits within 256. For a 62-character set, that threshold is Math.floor(256 / 62) * 62 = 248. Any random byte greater than or equal to 248 is discarded, and a new byte is drawn. The accepted byte is then safely reduced modulo 62, ensuring a perfectly uniform distribution across all characters.

Common API Key Formats

Different services use different conventions for their keys. Here is a reference table of common formats:

FormatPrefixCharsetTypical Length
Stripe secret keysk_live_Alphanumeric24 to 32
Stripe publishable keypk_live_Alphanumeric24 to 32
GitHub personal access tokenghp_Alphanumeric36
AWS access key IDAKIAAlphanumeric20
Generic hex token(none)Hexadecimal32 to 64

You can replicate any of these patterns by adjusting the prefix, character set, and length fields in this api key generator.

Choosing the Right Character Set

The character set determines both readability and entropy per character. Base62 (0-9, A-Z, a-z) gives about 5.95 bits per character and is safe to paste almost anywhere. Lowercase alphanumeric (a-z, 0-9) gives about 5.17 bits and avoids case confusion. Hexadecimal gives exactly 4 bits per character: easy to read, but you need more characters for the same strength. Base64url (letters, digits, hyphen and underscore) gives exactly 6 bits per character and is safe in URLs and HTTP headers.

Security Best Practices for API Keys

Generating a strong key is only the first step. Store your keys securely using environment variables or a dedicated secrets manager rather than hardcoding them into source files. Never commit keys to version control systems. If you suspect a key has been exposed, revoke it immediately and generate a replacement.

For production environments, aim for at least 128 bits of entropy. A 22-character base62 key or a 32-character hexadecimal key meets this threshold comfortably. If you need a broader authentication solution, consider pairing your keys with a bearer token generator for structured tokens, or use a password generator when human-memorizable secrets are required. You can also evaluate the randomness of existing strings using a Shannon entropy calculator.

Worked examples

ExampleInputResult
Stripe-style live keyPrefix: sk_live_; Random length: 32; Character set: base62; Quantity: 1Entropy: 190.53 bits; Characters per key: 40; Alphabet size: 62; Bits per character: 5.95; Keys generated: 1
Hex key, no prefixRandom length: 64; Character set: hex; Quantity: 1Entropy: 256 bits; Characters per key: 64; Alphabet size: 16; Bits per character: 4; Keys generated: 1
Ten test keysPrefix: sk_test_; Random length: 24; Character set: alnum; Quantity: 10Entropy: 124.08 bits; Characters per key: 32; Alphabet size: 36; Bits per character: 5.17; Keys generated: 10
URL-safe keyPrefix: key_; Random length: 43; Character set: base64url; Quantity: 1Entropy: 258 bits; Characters per key: 47; Alphabet size: 64; Bits per character: 6; Keys generated: 1

FAQ

What is an api key generator?

An api key generator is a tool that creates cryptographically secure random strings used to authenticate requests between software applications. It allows developers to specify prefixes, lengths, and character sets to match their system's requirements.

Why use rejection sampling instead of modulo?

Using a simple modulo operation on random bytes introduces a slight statistical bias because 256 does not divide evenly by most alphabet sizes. Rejection sampling discards out-of-range bytes to guarantee that every character in the output has an exactly equal probability of being selected.

How much entropy does my API key need?

For server-to-server API endpoints, at least 128 bits of entropy is a common recommendation. That is 22 base62 characters or 32 hexadecimal characters. Higher-value targets may warrant 256 bits.

Are the generated keys sent to a server?

No. This api key generator runs entirely in your browser using the Web Crypto API. The keys are generated locally on your device and are never transmitted over the network.

Can I generate multiple keys at once?

Yes. Use the quantity field to generate up to 100 keys in a single batch. Each key is independently generated with full cryptographic randomness.

What does the prefix do?

A prefix like sk_live_ or pk_test_ helps identify the purpose, environment, or type of a key at a glance without needing to query a database. It is prepended directly to the random string.

Can I use this as an API token generator?

Yes. Choose hex or base64url, set the length so the entropy figure is at least 128 bits, and add a prefix if you want one. Base58 output and checksum suffixes are not offered.

What is the difference between an API key and an API token?

Both are random secrets. An API key usually identifies and authorizes an application and lasts until rotated, while a token often belongs to a user or session and may expire. The generation method is the same.