API Key Generator

Create random API keys and tokens in base64url, hex, base64, alphanumeric, or UUID format. Made in your browser and never sent anywhere.

  • Free
  • No sign-up
  • Offline once loaded
  • Never sent or stored

Generated keys

    Key options

    Letters, digits, and underscores, up to 24 characters. Not counted as randomness.

    How to use the API key generator

    1. Choose a format. Base64url works almost everywhere.
    2. Keep 256 bits unless your system needs something else.
    3. Add a prefix if your keys follow a naming pattern such as sk_live_.
    4. Copy the key and store it straight into your environment variables or secrets manager.

    Formats explained

    Key formats and their length at 256 bits of randomness (calculated from each alphabet's size)
    FormatCharacters usedLength at 256 bitsSafe in URLs as-is
    Hex0 to 9, a to f64Yes
    Base64A to Z, a to z, 0 to 9, + and /44 (with padding)No
    Base64urlA to Z, a to z, 0 to 9, - and _43Yes
    Letters and digitsA to Z, a to z, 0 to 943Yes
    UUID v4Hex digits and hyphens36 (122 random bits)Yes

    Base64 and base64url are defined in RFC 4648; base64url swaps + and / for - and _ so the key can sit in a URL or file name without escaping. The base64url output here drops the trailing = padding. UUIDs are defined in RFC 9562, and a version 4 UUID has 122 random bits because 6 bits are fixed to mark the version and variant. UUIDs here come from the browser's crypto.randomUUID().

    Where API keys should live

    An API key is a password for a program, so the same rules apply. The OWASP Secrets Management Cheat Sheet recommends keeping secrets in a dedicated secrets manager or injected environment variables, out of source code and version control, with access limited and logged.

    • Never paste a key into client-side JavaScript or a mobile app bundle, where anyone can read it.
    • Add your .env file to .gitignore before the first commit.
    • Use separate keys for development and production so a leaked test key can't touch real data.
    • Rotate a key on a schedule your system can handle, and revoke it immediately if it might have been exposed.

    Worked example

    A developer needs a test key for a webhook. They choose base64url, 256 bits, and the prefix sk_test_. The result is sk_test_ followed by 43 random characters. The prefix makes the key easy to spot in logs and secret scanners, and only the 43 random characters count toward its 256 bits of randomness.

    Related tools

    Frequently asked questions

    Is a UUID secure enough as an API key?

    A version 4 UUID carries 122 random bits, which is enough to be unguessable, but it has a fixed, recognizable format. A 256-bit key in hex or base64url is longer and gives more margin, so it is the better default for secrets.

    Which format should I use?

    Use base64url when the key goes in a URL, header, or environment variable, since it has no characters that need escaping. Use hex when a system only accepts 0 to 9 and a to f. Use UUID only when a system specifically expects one.

    How long should an API key be?

    256 bits of randomness is the default here and is common practice for secret keys. That is 64 hex characters or 43 base64url characters.

    Is the key sent anywhere?

    No. The key is generated in your browser with the Web Crypto API and encoded on this page. The tool makes no network requests.

    Can I use these keys in production?

    Yes, the randomness comes from the browser's cryptographic generator. Treat the key like any other secret: store it in an environment variable or a secrets manager, never commit it to a repository, and rotate it if it might have been exposed.

    Sources

    1. Crypto: getRandomValues() method, MDN Web Docs
    2. Crypto: randomUUID() method, MDN Web Docs
    3. RFC 4648: The Base16, Base32, and Base64 Data Encodings, IETF
    4. RFC 9562: Universally Unique IDentifiers (UUIDs), IETF
    5. Secrets Management Cheat Sheet, OWASP